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!
109 HRESULT WINAPI
DPA_LoadStream (HDPA
*phDpa
, DPALOADPROC loadProc
,
110 IStream
*pStream
, LPARAM lParam
)
113 LARGE_INTEGER position
;
114 ULARGE_INTEGER newPosition
;
115 STREAMDATA streamData
;
121 FIXME ("phDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
122 phDpa
, loadProc
, pStream
, lParam
);
124 if (!phDpa
|| !loadProc
|| !pStream
)
129 position
.QuadPart
= 0;
132 * Zero out our streamData
134 memset(&streamData
,0,sizeof(STREAMDATA
));
136 errCode
= IStream_Seek (pStream
, position
, STREAM_SEEK_CUR
, &newPosition
);
140 errCode
= IStream_Read (pStream
, &streamData
, sizeof(STREAMDATA
), &ulRead
);
144 FIXME ("dwSize=%lu dwData2=%lu dwItems=%lu\n",
145 streamData
.dwSize
, streamData
.dwData2
, streamData
.dwItems
);
147 if ( ulRead
< sizeof(STREAMDATA
) ||
148 lParam
< sizeof(STREAMDATA
) ||
149 streamData
.dwSize
< sizeof(STREAMDATA
) ||
150 streamData
.dwData2
< 1) {
154 if (streamData
.dwItems
> (UINT_MAX
/ 2 / sizeof(VOID
*))) /* 536870911 */
155 return E_OUTOFMEMORY
;
158 hDpa
= DPA_Create (streamData
.dwItems
);
160 return E_OUTOFMEMORY
;
162 if (!DPA_Grow (hDpa
, streamData
.dwItems
))
163 return E_OUTOFMEMORY
;
165 /* load data from the stream into the dpa */
167 for (loadData
.nCount
= 0; loadData
.nCount
< streamData
.dwItems
; loadData
.nCount
++) {
168 errCode
= (loadProc
)(&loadData
, pStream
, lParam
);
169 if (errCode
!= S_OK
) {
178 /* set the number of items */
179 hDpa
->nItemCount
= loadData
.nCount
;
181 /* store the handle to the dpa */
183 FIXME ("new hDpa=%p, errorcode=%lx\n", hDpa
, errCode
);
189 /**************************************************************************
190 * DPA_SaveStream [COMCTL32.10]
192 * Saves a dynamic pointer array to a stream
195 * hDpa [I] handle to a dynamic pointer array
196 * loadProc [I] pointer to a callback function
197 * pStream [I] pointer to a stream
198 * lParam [I] application specific value
205 * No more information available yet!
207 HRESULT WINAPI
DPA_SaveStream (const HDPA hDpa
, DPALOADPROC loadProc
,
208 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]
221 * Merge two dynamic pointers arrays.
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!
238 BOOL WINAPI
DPA_Merge (const HDPA hdpa1
, const HDPA hdpa2
, DWORD dwFlags
,
239 PFNDPACOMPARE pfnCompare
, PFNDPAMERGE pfnMerge
,
243 LPVOID
*pWork1
, *pWork2
;
247 TRACE("%p %p %08lx %p %p %08lx)\n",
248 hdpa1
, hdpa2
, dwFlags
, pfnCompare
, pfnMerge
, lParam
);
250 if (IsBadWritePtr (hdpa1
, sizeof(*hdpa1
)))
253 if (IsBadWritePtr (hdpa2
, sizeof(*hdpa2
)))
256 if (IsBadCodePtr ((FARPROC
)pfnCompare
))
259 if (IsBadCodePtr ((FARPROC
)pfnMerge
))
262 if (!(dwFlags
& DPAM_NOSORT
)) {
263 TRACE("sorting dpa's!\n");
264 if (hdpa1
->nItemCount
> 0)
265 DPA_Sort (hdpa1
, pfnCompare
, lParam
);
266 TRACE ("dpa 1 sorted!\n");
267 if (hdpa2
->nItemCount
> 0)
268 DPA_Sort (hdpa2
, pfnCompare
, lParam
);
269 TRACE ("dpa 2 sorted!\n");
272 if (hdpa2
->nItemCount
< 1)
275 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
276 hdpa1
->nItemCount
, hdpa2
->nItemCount
);
279 /* working but untrusted implementation */
281 pWork1
= &(hdpa1
->ptrs
[hdpa1
->nItemCount
- 1]);
282 pWork2
= &(hdpa2
->ptrs
[hdpa2
->nItemCount
- 1]);
284 nIndex
= hdpa1
->nItemCount
- 1;
285 nCount
= hdpa2
->nItemCount
- 1;
290 if ((nCount
>= 0) && (dwFlags
& DPAM_INSERT
)) {
291 /* Now insert the remaining new items into DPA 1 */
292 TRACE("%d items to be inserted at start of DPA 1\n",
294 for (i
=nCount
; i
>=0; i
--) {
297 ptr
= (pfnMerge
)(3, *pWork2
, NULL
, lParam
);
300 DPA_InsertPtr (hdpa1
, 0, ptr
);
306 nResult
= (pfnCompare
)(*pWork1
, *pWork2
, lParam
);
307 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
308 nResult
, nIndex
, nCount
);
314 ptr
= (pfnMerge
)(1, *pWork1
, *pWork2
, lParam
);
324 else if (nResult
> 0)
326 /* item in DPA 1 missing from DPA 2 */
327 if (dwFlags
& DPAM_DELETE
)
329 /* Now delete the extra item in DPA1 */
332 ptr
= DPA_DeletePtr (hdpa1
, hdpa1
->nItemCount
- 1);
334 (pfnMerge
)(2, ptr
, NULL
, lParam
);
341 /* new item in DPA 2 */
342 if (dwFlags
& DPAM_INSERT
)
344 /* Now insert the new item in DPA 1 */
347 ptr
= (pfnMerge
)(3, *pWork2
, NULL
, lParam
);
350 DPA_InsertPtr (hdpa1
, nIndex
+1, ptr
);
363 /**************************************************************************
364 * Alloc [COMCTL32.71]
366 * Allocates memory block from the dll's private heap
369 * dwSize [I] size of the allocated memory block
372 * 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
399 LPVOID WINAPI
ReAlloc (LPVOID lpSrc
, DWORD dwSize
)
402 return LocalReAlloc( lpSrc
, dwSize
, LMEM_ZEROINIT
);
404 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
408 /**************************************************************************
411 * Frees an allocated memory block from the dll's private heap.
414 * lpMem [I] pointer to memory block which will be freed
420 BOOL WINAPI
Free (LPVOID lpMem
)
422 return !LocalFree( lpMem
);
426 /**************************************************************************
427 * GetSize [COMCTL32.74]
429 * Retrieves the size of the specified memory block from the dll's
433 * lpMem [I] pointer to an allocated memory block
436 * Success: size of the specified memory block
439 DWORD WINAPI
GetSize (LPVOID lpMem
)
441 return LocalSize( lpMem
);
445 /**************************************************************************
446 * MRU-Functions {COMCTL32}
449 * The MRU-Api is a set of functions to manipulate lists of M.R.U. (Most Recently
450 * Used) items. It is an undocumented Api that is used (at least) by the shell
451 * and explorer to implement their recent documents feature.
453 * Since these functions are undocumented, they are unsupported by MS and
454 * may change at any time.
456 * Internally, the list is implemented as a last in, last out list of items
457 * persisted into the system registry under a caller chosen key. Each list
458 * item is given a one character identifier in the Ascii range from 'a' to
459 * '}'. A list of the identifiers in order from newest to oldest is stored
460 * under the same key in a value named "MRUList".
462 * Items are re-ordered by changing the order of the values in the MRUList
463 * value. When a new item is added, it becomes the new value of the oldest
464 * identifier, and that identifier is moved to the front of the MRUList value.
466 * Wine stores MRU-lists in the same registry format as Windows, so when
467 * switching between the builtin and native comctl32.dll no problems or
468 * incompatibilities should occur.
470 * The following undocumented structure is used to create an MRU-list:
471 *|typedef INT (CALLBACK *MRUStringCmpFn)(LPCTSTR lhs, LPCTSTR rhs);
472 *|typedef INT (CALLBACK *MRUBinaryCmpFn)(LPCVOID lhs, LPCVOID rhs, DWORD length);
474 *|typedef struct tagCREATEMRULIST
480 *| LPCTSTR lpszSubKey;
482 *|} CREATEMRULIST, *LPCREATEMRULIST;
485 * cbSize [I] The size of the CREATEMRULIST structure. This must be set
486 * to sizeof(CREATEMRULIST) by the caller.
487 * nMaxItems [I] The maximum number of items allowed in the list. Because
488 * of the limited number of identifiers, this should be set to
489 * a value from 1 to 30 by the caller.
490 * dwFlags [I] If bit 0 is set, the list will be used to store binary
491 * data, otherwise it is assumed to store strings. If bit 1
492 * is set, every change made to the list will be reflected in
493 * the registry immediately, otherwise changes will only be
494 * written when the list is closed.
495 * hKey [I] The registry key that the list should be written under.
496 * This must be supplied by the caller.
497 * lpszSubKey [I] A caller supplied name of a subkey under hKey to write
498 * the list to. This may not be blank.
499 * lpfnCompare [I] A caller supplied comparison function, which may be either
500 * an MRUStringCmpFn if dwFlags does not have bit 0 set, or a
501 * MRUBinaryCmpFn otherwise.
504 * - Create an MRU-list with CreateMRUList() or CreateMRUListLazy().
505 * - Add items to an MRU-list with AddMRUString() or AddMRUData().
506 * - Remove items from an MRU-list with DelMRUString().
507 * - Find data in an MRU-list with FindMRUString() or FindMRUData().
508 * - Iterate through an MRU-list with EnumMRUList().
509 * - Free an MRU-list with FreeMRUList().
512 typedef struct tagCREATEMRULISTA
520 } CREATEMRULISTA
, *LPCREATEMRULISTA
;
522 typedef struct tagCREATEMRULISTW
530 } CREATEMRULISTW
, *LPCREATEMRULISTW
;
533 #define MRUF_STRING_LIST 0 /* list will contain strings */
534 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
535 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
537 /* If list is a string list lpfnCompare has the following prototype
538 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
539 * for binary lists the prototype is
540 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
541 * where cbData is the no. of bytes to compare.
542 * Need to check what return value means identical - 0?
545 typedef struct tagWINEMRUITEM
547 DWORD size
; /* size of data stored */
548 DWORD itemFlag
; /* flags */
550 } WINEMRUITEM
, *LPWINEMRUITEM
;
553 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
555 typedef struct tagWINEMRULIST
557 CREATEMRULISTW extview
; /* original create information */
558 BOOL isUnicode
; /* is compare fn Unicode */
559 DWORD wineFlags
; /* internal flags */
560 DWORD cursize
; /* current size of realMRU */
561 LPSTR realMRU
; /* pointer to string of index names */
562 LPWINEMRUITEM
*array
; /* array of pointers to data */
563 /* in 'a' to 'z' order */
564 } WINEMRULIST
, *LPWINEMRULIST
;
567 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
569 /**************************************************************************
570 * MRU_SaveChanged (internal)
572 * Local MRU saving code
574 static void MRU_SaveChanged ( LPWINEMRULIST mp
)
580 static const WCHAR emptyW
[] = {'\0'};
582 /* or should we do the following instead of RegOpenKeyEx:
585 /* open the sub key */
586 if ((err
= RegOpenKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
587 0, KEY_WRITE
, &newkey
))) {
588 /* not present - what to do ??? */
589 ERR("Can not open key, error=%d, attempting to create\n",
591 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
594 REG_OPTION_NON_VOLATILE
,
595 KEY_READ
| KEY_WRITE
,
599 ERR("failed to create key /%s/, err=%d\n",
600 debugstr_w(mp
->extview
.lpszSubKey
), err
);
604 if (mp
->wineFlags
& WMRUF_CHANGED
) {
605 mp
->wineFlags
&= ~WMRUF_CHANGED
;
606 err
= RegSetValueExA(newkey
, "MRUList", 0, REG_SZ
,
607 mp
->realMRU
, strlen(mp
->realMRU
) + 1);
609 ERR("error saving MRUList, err=%d\n", err
);
611 TRACE("saving MRUList=/%s/\n", mp
->realMRU
);
614 for(i
=0; i
<mp
->cursize
; i
++) {
615 witem
= mp
->array
[i
];
616 if (witem
->itemFlag
& WMRUIF_CHANGED
) {
617 witem
->itemFlag
&= ~WMRUIF_CHANGED
;
618 realname
[0] = 'a' + i
;
619 err
= RegSetValueExW(newkey
, realname
, 0,
620 (mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) ?
622 &witem
->datastart
, witem
->size
);
624 ERR("error saving /%s/, err=%d\n", debugstr_w(realname
), err
);
626 TRACE("saving value for name /%s/ size=%ld\n",
627 debugstr_w(realname
), witem
->size
);
630 RegCloseKey( newkey
);
633 /**************************************************************************
634 * FreeMRUList [COMCTL32.152]
636 * Frees a most-recently-used items list.
639 * hMRUList [I] Handle to list.
644 void WINAPI
FreeMRUList (HANDLE hMRUList
)
646 LPWINEMRULIST mp
= (LPWINEMRULIST
)hMRUList
;
649 TRACE("(%p)\n", hMRUList
);
653 if (mp
->wineFlags
& WMRUF_CHANGED
) {
654 /* need to open key and then save the info */
655 MRU_SaveChanged( mp
);
658 for(i
=0; i
<mp
->extview
.nMaxItems
; i
++) {
664 Free((LPWSTR
)mp
->extview
.lpszSubKey
);
669 /**************************************************************************
670 * FindMRUData [COMCTL32.169]
672 * Searches binary list for item that matches lpData of length cbData.
673 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
674 * corresponding to item's reg. name will be stored in it ('a' -> 0).
677 * hList [I] list handle
678 * lpData [I] data to find
679 * cbData [I] length of data
680 * lpRegNum [O] position in registry (maybe NULL)
683 * Position in list 0 -> MRU. -1 if item not found.
685 INT WINAPI
FindMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
,
688 LPWINEMRULIST mp
= (LPWINEMRULIST
)hList
;
693 if (!mp
->extview
.lpfnCompare
) {
694 ERR("MRU list not properly created. No compare procedure.\n");
698 if(!(mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) && !mp
->isUnicode
) {
699 DWORD len
= WideCharToMultiByte(CP_ACP
, 0, lpData
, -1,
700 NULL
, 0, NULL
, NULL
);
702 WideCharToMultiByte(CP_ACP
, 0, lpData
, -1, dataA
, len
, NULL
, NULL
);
705 for(i
=0; i
<mp
->cursize
; i
++) {
706 if (mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) {
707 if (!mp
->extview
.lpfnCompare(lpData
, &mp
->array
[i
]->datastart
,
713 if (!mp
->extview
.lpfnCompare(lpData
, &mp
->array
[i
]->datastart
))
716 DWORD len
= WideCharToMultiByte(CP_ACP
, 0,
717 (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
718 NULL
, 0, NULL
, NULL
);
719 LPSTR itemA
= Alloc(len
);
721 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
722 itemA
, len
, NULL
, NULL
);
724 cmp
= mp
->extview
.lpfnCompare(dataA
, itemA
);
737 if (lpRegNum
&& (ret
!= -1))
740 TRACE("(%p, %p, %ld, %p) returning %d\n",
741 hList
, lpData
, cbData
, lpRegNum
, ret
);
747 /**************************************************************************
748 * AddMRUData [COMCTL32.167]
750 * Add item to MRU binary list. If item already exists in list then it is
751 * simply moved up to the top of the list and not added again. If list is
752 * full then the least recently used item is removed to make room.
755 * hList [I] Handle to list.
756 * lpData [I] ptr to data to add.
757 * cbData [I] no. of bytes of data.
760 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
763 INT WINAPI
AddMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
)
765 LPWINEMRULIST mp
= (LPWINEMRULIST
)hList
;
769 if ((replace
= FindMRUData (hList
, lpData
, cbData
, NULL
)) >= 0) {
770 /* Item exists, just move it to the front */
771 LPSTR pos
= strchr(mp
->realMRU
, replace
+ 'a');
772 while (pos
> mp
->realMRU
)
779 /* either add a new entry or replace oldest */
780 if (mp
->cursize
< mp
->extview
.nMaxItems
) {
781 /* Add in a new item */
782 replace
= mp
->cursize
;
786 /* get the oldest entry and replace data */
787 replace
= mp
->realMRU
[mp
->cursize
- 1] - 'a';
788 Free(mp
->array
[replace
]);
791 /* Allocate space for new item and move in the data */
792 mp
->array
[replace
] = witem
= Alloc(cbData
+ sizeof(WINEMRUITEM
));
793 witem
->itemFlag
|= WMRUIF_CHANGED
;
794 witem
->size
= cbData
;
795 memcpy( &witem
->datastart
, lpData
, cbData
);
797 /* now rotate MRU list */
798 for(i
=mp
->cursize
-1; i
>=1; i
--)
799 mp
->realMRU
[i
] = mp
->realMRU
[i
-1];
802 /* The new item gets the front spot */
803 mp
->wineFlags
|= WMRUF_CHANGED
;
804 mp
->realMRU
[0] = replace
+ 'a';
806 TRACE("(%p, %p, %ld) adding data, /%c/ now most current\n",
807 hList
, lpData
, cbData
, replace
+'a');
809 if (!(mp
->extview
.dwFlags
& MRUF_DELAYED_SAVE
)) {
810 /* save changed stuff right now */
811 MRU_SaveChanged( mp
);
817 /**************************************************************************
818 * AddMRUStringW [COMCTL32.401]
820 * Add an item to an MRU string list.
823 * hList [I] Handle to list.
824 * lpszString [I] The string to add.
827 * Success: The number corresponding to the registry name where the string
828 * has been stored (0 maps to 'a', 1 to 'b' and so on).
829 * Failure: -1, if hList is NULL or memory allocation fails. If lpszString
830 * is invalid, the function returns 0, and GetLastError() returns
831 * ERROR_INVALID_PARAMETER. The last error value is set only in
835 * -If lpszString exists in the list already, it is moved to the top of the
836 * MRU list (it is not duplicated).
837 * -If the list is full the least recently used list entry is replaced with
839 * -If this function returns 0 you should check the last error value to
840 * ensure the call really succeeded.
842 INT WINAPI
AddMRUStringW(HANDLE hList
, LPCWSTR lpszString
)
844 TRACE("(%p,%s)\n", hList
, debugstr_w(lpszString
));
849 if (!lpszString
|| IsBadStringPtrW(lpszString
, -1))
851 SetLastError(ERROR_INVALID_PARAMETER
);
855 return AddMRUData(hList
, lpszString
,
856 (strlenW(lpszString
) + 1) * sizeof(WCHAR
));
859 /**************************************************************************
860 * AddMRUStringA [COMCTL32.153]
864 INT WINAPI
AddMRUStringA(HANDLE hList
, LPCSTR lpszString
)
870 TRACE("(%p,%s)\n", hList
, debugstr_a(lpszString
));
875 if (IsBadStringPtrA(lpszString
, -1))
877 SetLastError(ERROR_INVALID_PARAMETER
);
881 len
= MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, NULL
, 0) * sizeof(WCHAR
);
882 stringW
= Alloc(len
);
886 MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, stringW
, len
);
887 ret
= AddMRUData(hList
, stringW
, len
);
892 /**************************************************************************
893 * DelMRUString [COMCTL32.156]
895 * Removes item from either string or binary list (despite its name)
898 * hList [I] list handle
899 * nItemPos [I] item position to remove 0 -> MRU
902 * TRUE if successful, FALSE if nItemPos is out of range.
904 BOOL WINAPI
DelMRUString(HANDLE hList
, INT nItemPos
)
906 FIXME("(%p, %d): stub\n", hList
, nItemPos
);
910 /**************************************************************************
911 * FindMRUStringW [COMCTL32.402]
913 * See FindMRUStringA.
915 INT WINAPI
FindMRUStringW (HANDLE hList
, LPCWSTR lpszString
, LPINT lpRegNum
)
917 return FindMRUData(hList
, lpszString
,
918 (lstrlenW(lpszString
) + 1) * sizeof(WCHAR
), lpRegNum
);
921 /**************************************************************************
922 * FindMRUStringA [COMCTL32.155]
924 * Searches string list for item that matches lpszString.
925 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
926 * corresponding to item's reg. name will be stored in it ('a' -> 0).
929 * hList [I] list handle
930 * lpszString [I] string to find
931 * lpRegNum [O] position in registry (maybe NULL)
934 * Position in list 0 -> MRU. -1 if item not found.
936 INT WINAPI
FindMRUStringA (HANDLE hList
, LPCSTR lpszString
, LPINT lpRegNum
)
938 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, NULL
, 0);
939 LPWSTR stringW
= Alloc(len
* sizeof(WCHAR
));
942 MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, stringW
, len
);
943 ret
= FindMRUData(hList
, stringW
, len
* sizeof(WCHAR
), lpRegNum
);
948 /*************************************************************************
949 * CreateMRUListLazy_common (internal)
951 static HANDLE
CreateMRUListLazy_common(LPWINEMRULIST mp
)
955 DWORD datasize
, dwdisp
;
959 static const WCHAR emptyW
[] = {'\0'};
961 /* get space to save indices that will turn into names
962 * but in order of most to least recently used
964 mp
->realMRU
= Alloc(mp
->extview
.nMaxItems
+ 2);
966 /* get space to save pointers to actual data in order of
967 * 'a' to 'z' (0 to n).
969 mp
->array
= Alloc(mp
->extview
.nMaxItems
* sizeof(LPVOID
));
971 /* open the sub key */
972 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
975 REG_OPTION_NON_VOLATILE
,
976 KEY_READ
| KEY_WRITE
,
980 /* error - what to do ??? */
981 ERR("(%lu %lu %lx %lx \"%s\" %p): Can not open key, error=%d\n",
982 mp
->extview
.cbSize
, mp
->extview
.nMaxItems
, mp
->extview
.dwFlags
,
983 (DWORD
)mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
984 mp
->extview
.lpfnCompare
, err
);
988 /* get values from key 'MRUList' */
990 datasize
= mp
->extview
.nMaxItems
+ 1;
991 if((err
=RegQueryValueExA( newkey
, "MRUList", 0, &type
, mp
->realMRU
,
993 /* not present - set size to 1 (will become 0 later) */
998 TRACE("MRU list = %s, datasize = %ld\n", mp
->realMRU
, datasize
);
1000 mp
->cursize
= datasize
- 1;
1001 /* datasize now has number of items in the MRUList */
1003 /* get actual values for each entry */
1005 for(i
=0; i
<mp
->cursize
; i
++) {
1006 realname
[0] = 'a' + i
;
1007 if(RegQueryValueExW( newkey
, realname
, 0, &type
, 0, &datasize
)) {
1008 /* not present - what to do ??? */
1009 ERR("Key %s not found 1\n", debugstr_w(realname
));
1011 mp
->array
[i
] = witem
= Alloc(datasize
+ sizeof(WINEMRUITEM
));
1012 witem
->size
= datasize
;
1013 if(RegQueryValueExW( newkey
, realname
, 0, &type
,
1014 &witem
->datastart
, &datasize
)) {
1015 /* not present - what to do ??? */
1016 ERR("Key %s not found 2\n", debugstr_w(realname
));
1019 RegCloseKey( newkey
);
1024 TRACE("(%lu %lu %lx %lx \"%s\" %p): Current Size = %ld\n",
1025 mp
->extview
.cbSize
, mp
->extview
.nMaxItems
, mp
->extview
.dwFlags
,
1026 (DWORD
)mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
1027 mp
->extview
.lpfnCompare
, mp
->cursize
);
1031 /**************************************************************************
1032 * CreateMRUListLazyW [COMCTL32.404]
1034 * See CreateMRUListLazyA.
1036 HANDLE WINAPI
CreateMRUListLazyW (LPCREATEMRULISTW lpcml
, DWORD dwParam2
,
1037 DWORD dwParam3
, DWORD dwParam4
)
1041 /* Native does not check for a NULL lpcml */
1043 if (lpcml
->cbSize
!= sizeof(CREATEMRULISTW
) || !lpcml
->hKey
||
1044 IsBadStringPtrW(lpcml
->lpszSubKey
, -1))
1047 mp
= Alloc(sizeof(WINEMRULIST
));
1048 memcpy(&mp
->extview
, lpcml
, sizeof(CREATEMRULISTW
));
1049 mp
->extview
.lpszSubKey
= Alloc((strlenW(lpcml
->lpszSubKey
) + 1) * sizeof(WCHAR
));
1050 strcpyW((LPWSTR
)mp
->extview
.lpszSubKey
, lpcml
->lpszSubKey
);
1051 mp
->isUnicode
= TRUE
;
1053 return CreateMRUListLazy_common(mp
);
1056 /**************************************************************************
1057 * CreateMRUListLazyA [COMCTL32.157]
1059 * Creates a most-recently-used list.
1062 * lpcml [I] ptr to CREATEMRULIST structure.
1063 * dwParam2 [I] Unknown
1064 * dwParam3 [I] Unknown
1065 * dwParam4 [I] Unknown
1068 * Handle to MRU list.
1070 HANDLE WINAPI
CreateMRUListLazyA (LPCREATEMRULISTA lpcml
, DWORD dwParam2
,
1071 DWORD dwParam3
, DWORD dwParam4
)
1076 /* Native does not check for a NULL lpcml */
1078 if (lpcml
->cbSize
!= sizeof(CREATEMRULISTA
) || !lpcml
->hKey
||
1079 IsBadStringPtrA(lpcml
->lpszSubKey
, -1))
1082 mp
= Alloc(sizeof(WINEMRULIST
));
1083 memcpy(&mp
->extview
, lpcml
, sizeof(CREATEMRULISTW
));
1084 len
= MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1, NULL
, 0);
1085 mp
->extview
.lpszSubKey
= Alloc(len
* sizeof(WCHAR
));
1086 MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1,
1087 (LPWSTR
)mp
->extview
.lpszSubKey
, len
);
1088 mp
->isUnicode
= FALSE
;
1089 return CreateMRUListLazy_common(mp
);
1092 /**************************************************************************
1093 * CreateMRUListW [COMCTL32.400]
1095 * See CreateMRUListA.
1097 HANDLE WINAPI
CreateMRUListW (LPCREATEMRULISTW lpcml
)
1099 return CreateMRUListLazyW(lpcml
, 0, 0, 0);
1102 /**************************************************************************
1103 * CreateMRUListA [COMCTL32.151]
1105 * Creates a most-recently-used list.
1108 * lpcml [I] ptr to CREATEMRULIST structure.
1111 * Handle to MRU list.
1113 HANDLE WINAPI
CreateMRUListA (LPCREATEMRULISTA lpcml
)
1115 return CreateMRUListLazyA (lpcml
, 0, 0, 0);
1119 /**************************************************************************
1120 * EnumMRUListW [COMCTL32.403]
1122 * Enumerate item in a most-recenty-used list
1125 * hList [I] list handle
1126 * nItemPos [I] item position to enumerate
1127 * lpBuffer [O] buffer to receive item
1128 * nBufferSize [I] size of buffer
1131 * For binary lists specifies how many bytes were copied to buffer, for
1132 * string lists specifies full length of string. Enumerating past the end
1133 * of list returns -1.
1134 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
1137 INT WINAPI
EnumMRUListW (HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
1140 LPWINEMRULIST mp
= (LPWINEMRULIST
) hList
;
1141 LPWINEMRUITEM witem
;
1142 INT desired
, datasize
;
1144 if (nItemPos
>= mp
->cursize
) return -1;
1145 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
1146 desired
= mp
->realMRU
[nItemPos
];
1148 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
1149 witem
= mp
->array
[desired
];
1150 datasize
= min( witem
->size
, nBufferSize
);
1151 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
1152 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1153 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
1157 /**************************************************************************
1158 * EnumMRUListA [COMCTL32.154]
1162 INT WINAPI
EnumMRUListA (HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
1165 LPWINEMRULIST mp
= (LPWINEMRULIST
) hList
;
1166 LPWINEMRUITEM witem
;
1167 INT desired
, datasize
;
1170 if (nItemPos
>= mp
->cursize
) return -1;
1171 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
1172 desired
= mp
->realMRU
[nItemPos
];
1174 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
1175 witem
= mp
->array
[desired
];
1176 if(mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) {
1177 datasize
= min( witem
->size
, nBufferSize
);
1178 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
1180 lenA
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
1181 NULL
, 0, NULL
, NULL
);
1182 datasize
= min( witem
->size
, nBufferSize
);
1183 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
1184 lpBuffer
, datasize
, NULL
, NULL
);
1186 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1187 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
1192 /**************************************************************************
1193 * Str_GetPtrA [COMCTL32.233]
1195 * Copies a string into a destination buffer.
1198 * lpSrc [I] Source string
1199 * lpDest [O] Destination buffer
1200 * nMaxLen [I] Size of buffer in characters
1203 * The number of characters copied.
1205 INT WINAPI
Str_GetPtrA (LPCSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
1209 TRACE("(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
1211 if (!lpDest
&& lpSrc
)
1212 return strlen (lpSrc
);
1217 if (lpSrc
== NULL
) {
1222 len
= strlen (lpSrc
);
1226 RtlMoveMemory (lpDest
, lpSrc
, len
);
1233 /**************************************************************************
1234 * Str_SetPtrA [COMCTL32.234]
1236 * Makes a copy of a string, allocating memory if necessary.
1239 * lppDest [O] Pointer to destination string
1240 * lpSrc [I] Source string
1247 * Set lpSrc to NULL to free the memory allocated by a previous call
1250 BOOL WINAPI
Str_SetPtrA (LPSTR
*lppDest
, LPCSTR lpSrc
)
1252 TRACE("(%p %p)\n", lppDest
, lpSrc
);
1255 LPSTR ptr
= ReAlloc (*lppDest
, strlen (lpSrc
) + 1);
1258 strcpy (ptr
, lpSrc
);
1272 /**************************************************************************
1273 * Str_GetPtrW [COMCTL32.235]
1277 INT WINAPI
Str_GetPtrW (LPCWSTR lpSrc
, LPWSTR lpDest
, INT nMaxLen
)
1281 TRACE("(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
1283 if (!lpDest
&& lpSrc
)
1284 return strlenW (lpSrc
);
1289 if (lpSrc
== NULL
) {
1294 len
= strlenW (lpSrc
);
1298 RtlMoveMemory (lpDest
, lpSrc
, len
*sizeof(WCHAR
));
1299 lpDest
[len
] = L
'\0';
1305 /**************************************************************************
1306 * Str_SetPtrW [COMCTL32.236]
1310 BOOL WINAPI
Str_SetPtrW (LPWSTR
*lppDest
, LPCWSTR lpSrc
)
1312 TRACE("(%p %p)\n", lppDest
, lpSrc
);
1315 INT len
= strlenW (lpSrc
) + 1;
1316 LPWSTR ptr
= ReAlloc (*lppDest
, len
* sizeof(WCHAR
));
1319 strcpyW (ptr
, lpSrc
);
1333 /**************************************************************************
1334 * Str_GetPtrWtoA [internal]
1336 * Converts a unicode string into a multi byte string
1339 * lpSrc [I] Pointer to the unicode source string
1340 * lpDest [O] Pointer to caller supplied storage for the multi byte string
1341 * nMaxLen [I] Size, in bytes, of the destination buffer
1344 * Length, in bytes, of the converted string.
1347 INT
Str_GetPtrWtoA (LPCWSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
1351 TRACE("(%s %p %d)\n", debugstr_w(lpSrc
), lpDest
, nMaxLen
);
1353 if (!lpDest
&& lpSrc
)
1354 return WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
1359 if (lpSrc
== NULL
) {
1364 len
= WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
1368 WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, lpDest
, len
, NULL
, NULL
);
1375 /**************************************************************************
1376 * Str_SetPtrAtoW [internal]
1378 * Converts a multi byte string to a unicode string.
1379 * If the pointer to the destination buffer is NULL a buffer is allocated.
1380 * If the destination buffer is too small to keep the converted multi byte
1381 * string the destination buffer is reallocated. If the source pointer is
1382 * NULL, the destination buffer is freed.
1385 * lppDest [I/O] pointer to a pointer to the destination buffer
1386 * lpSrc [I] pointer to a multi byte string
1389 * TRUE: conversion successful
1392 BOOL
Str_SetPtrAtoW (LPWSTR
*lppDest
, LPCSTR lpSrc
)
1394 TRACE("(%p %s)\n", lppDest
, lpSrc
);
1397 INT len
= MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,NULL
,0);
1398 LPWSTR ptr
= ReAlloc (*lppDest
, len
*sizeof(WCHAR
));
1402 MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,ptr
,len
);
1416 /**************************************************************************
1417 * DSA_Create [COMCTL32.320]
1419 * Creates a dynamic storage array
1422 * nSize [I] size of the array elements
1423 * nGrow [I] number of elements by which the array grows when it is filled
1426 * Success: pointer to an array control structure. Use this like a handle.
1430 * The DSA_ functions can be used to create and manipulate arrays of
1431 * fixed-size memory blocks. These arrays can store any kind of data
1432 * (e.g. strings and icons).
1434 HDSA WINAPI
DSA_Create (INT nSize
, INT nGrow
)
1438 TRACE("(size=%d grow=%d)\n", nSize
, nGrow
);
1440 hdsa
= Alloc (sizeof(*hdsa
));
1443 hdsa
->nItemCount
= 0;
1445 hdsa
->nMaxCount
= 0;
1446 hdsa
->nItemSize
= nSize
;
1447 hdsa
->nGrow
= max(1, nGrow
);
1454 /**************************************************************************
1455 * DSA_Destroy [COMCTL32.321]
1457 * Destroys a dynamic storage array
1460 * hdsa [I] pointer to the array control structure
1466 BOOL WINAPI
DSA_Destroy (const HDSA hdsa
)
1468 TRACE("(%p)\n", hdsa
);
1473 if (hdsa
->pData
&& (!Free (hdsa
->pData
)))
1480 /**************************************************************************
1481 * DSA_GetItem [COMCTL32.322]
1483 * Copies the specified item into a caller-supplied buffer.
1486 * hdsa [I] pointer to the array control structure
1487 * nIndex [I] number of the Item to get
1488 * pDest [O] destination buffer. Has to be >= dwElementSize.
1494 BOOL WINAPI
DSA_GetItem (const HDSA hdsa
, INT nIndex
, LPVOID pDest
)
1498 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pDest
);
1502 if ((nIndex
< 0) || (nIndex
>= hdsa
->nItemCount
))
1505 pSrc
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1506 memmove (pDest
, pSrc
, hdsa
->nItemSize
);
1512 /**************************************************************************
1513 * DSA_GetItemPtr [COMCTL32.323]
1515 * Retrieves a pointer to the specified item.
1518 * hdsa [I] pointer to the array control structure
1519 * nIndex [I] index of the desired item
1522 * Success: pointer to an item
1525 LPVOID WINAPI
DSA_GetItemPtr (const HDSA hdsa
, INT nIndex
)
1529 TRACE("(%p %d)\n", hdsa
, nIndex
);
1533 if ((nIndex
< 0) || (nIndex
>= hdsa
->nItemCount
))
1536 pSrc
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1538 TRACE("-- ret=%p\n", pSrc
);
1544 /**************************************************************************
1545 * DSA_SetItem [COMCTL32.325]
1547 * Sets the contents of an item in the array.
1550 * hdsa [I] pointer to the array control structure
1551 * nIndex [I] index for the item
1552 * pSrc [I] pointer to the new item data
1558 BOOL WINAPI
DSA_SetItem (const HDSA hdsa
, INT nIndex
, LPVOID pSrc
)
1560 INT nSize
, nNewItems
;
1561 LPVOID pDest
, lpTemp
;
1563 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pSrc
);
1565 if ((!hdsa
) || nIndex
< 0)
1568 if (hdsa
->nItemCount
<= nIndex
) {
1569 /* within the old array */
1570 if (hdsa
->nMaxCount
> nIndex
) {
1571 /* within the allocated space, set a new boundary */
1572 hdsa
->nItemCount
= nIndex
+ 1;
1575 /* resize the block of memory */
1577 hdsa
->nGrow
* ((INT
)(((nIndex
+ 1) - 1) / hdsa
->nGrow
) + 1);
1578 nSize
= hdsa
->nItemSize
* nNewItems
;
1580 lpTemp
= ReAlloc (hdsa
->pData
, nSize
);
1584 hdsa
->nMaxCount
= nNewItems
;
1585 hdsa
->nItemCount
= nIndex
+ 1;
1586 hdsa
->pData
= lpTemp
;
1590 /* put the new entry in */
1591 pDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1592 TRACE("-- move dest=%p src=%p size=%d\n",
1593 pDest
, pSrc
, hdsa
->nItemSize
);
1594 memmove (pDest
, pSrc
, hdsa
->nItemSize
);
1600 /**************************************************************************
1601 * DSA_InsertItem [COMCTL32.324]
1603 * Inserts an item into the array at the specified index.
1606 * hdsa [I] pointer to the array control structure
1607 * nIndex [I] index for the new item
1608 * pSrc [I] pointer to the element
1611 * Success: position of the new item
1614 INT WINAPI
DSA_InsertItem (const HDSA hdsa
, INT nIndex
, LPVOID pSrc
)
1616 INT nNewItems
, nSize
;
1617 LPVOID lpTemp
, lpDest
;
1619 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pSrc
);
1621 if ((!hdsa
) || nIndex
< 0)
1624 /* when nIndex >= nItemCount then append */
1625 if (nIndex
>= hdsa
->nItemCount
)
1626 nIndex
= hdsa
->nItemCount
;
1628 /* do we need to resize ? */
1629 if (hdsa
->nItemCount
>= hdsa
->nMaxCount
) {
1630 nNewItems
= hdsa
->nMaxCount
+ hdsa
->nGrow
;
1631 nSize
= hdsa
->nItemSize
* nNewItems
;
1633 lpTemp
= ReAlloc (hdsa
->pData
, nSize
);
1637 hdsa
->nMaxCount
= nNewItems
;
1638 hdsa
->pData
= lpTemp
;
1641 /* do we need to move elements ? */
1642 if (nIndex
< hdsa
->nItemCount
) {
1643 lpTemp
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1644 lpDest
= (char *) lpTemp
+ hdsa
->nItemSize
;
1645 nSize
= (hdsa
->nItemCount
- nIndex
) * hdsa
->nItemSize
;
1646 TRACE("-- move dest=%p src=%p size=%d\n",
1647 lpDest
, lpTemp
, nSize
);
1648 memmove (lpDest
, lpTemp
, nSize
);
1651 /* ok, we can put the new Item in */
1653 lpDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1654 TRACE("-- move dest=%p src=%p size=%d\n",
1655 lpDest
, pSrc
, hdsa
->nItemSize
);
1656 memmove (lpDest
, pSrc
, hdsa
->nItemSize
);
1662 /**************************************************************************
1663 * DSA_DeleteItem [COMCTL32.326]
1665 * Deletes the specified item from the array.
1668 * hdsa [I] pointer to the array control structure
1669 * nIndex [I] index for the element to delete
1672 * Success: number of the deleted element
1675 INT WINAPI
DSA_DeleteItem (const HDSA hdsa
, INT nIndex
)
1677 LPVOID lpDest
,lpSrc
;
1680 TRACE("(%p %d)\n", hdsa
, nIndex
);
1684 if (nIndex
< 0 || nIndex
>= hdsa
->nItemCount
)
1687 /* do we need to move ? */
1688 if (nIndex
< hdsa
->nItemCount
- 1) {
1689 lpDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1690 lpSrc
= (char *) lpDest
+ hdsa
->nItemSize
;
1691 nSize
= hdsa
->nItemSize
* (hdsa
->nItemCount
- nIndex
- 1);
1692 TRACE("-- move dest=%p src=%p size=%d\n",
1693 lpDest
, lpSrc
, nSize
);
1694 memmove (lpDest
, lpSrc
, nSize
);
1700 if ((hdsa
->nMaxCount
- hdsa
->nItemCount
) >= hdsa
->nGrow
) {
1701 nSize
= hdsa
->nItemSize
* hdsa
->nItemCount
;
1703 lpDest
= ReAlloc (hdsa
->pData
, nSize
);
1707 hdsa
->nMaxCount
= hdsa
->nItemCount
;
1708 hdsa
->pData
= lpDest
;
1715 /**************************************************************************
1716 * DSA_DeleteAllItems [COMCTL32.327]
1718 * Removes all items and reinitializes the array.
1721 * hdsa [I] pointer to the array control structure
1727 BOOL WINAPI
DSA_DeleteAllItems (const HDSA hdsa
)
1729 TRACE("(%p)\n", hdsa
);
1733 if (hdsa
->pData
&& (!Free (hdsa
->pData
)))
1736 hdsa
->nItemCount
= 0;
1738 hdsa
->nMaxCount
= 0;
1744 /**************************************************************************
1745 * DPA_Destroy [COMCTL32.329]
1747 * Destroys a dynamic pointer array
1750 * hdpa [I] handle (pointer) to the pointer array
1756 BOOL WINAPI
DPA_Destroy (const HDPA hdpa
)
1758 TRACE("(%p)\n", hdpa
);
1763 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
1766 return HeapFree (hdpa
->hHeap
, 0, hdpa
);
1770 /**************************************************************************
1771 * DPA_Grow [COMCTL32.330]
1773 * Sets the growth amount.
1776 * hdpa [I] handle (pointer) to the existing (source) pointer array
1777 * nGrow [I] number of items by which the array grows when it's too small
1783 BOOL WINAPI
DPA_Grow (const HDPA hdpa
, INT nGrow
)
1785 TRACE("(%p %d)\n", hdpa
, nGrow
);
1790 hdpa
->nGrow
= max(8, nGrow
);
1796 /**************************************************************************
1797 * DPA_Clone [COMCTL32.331]
1799 * Copies a pointer array to an other one or creates a copy
1802 * hdpa [I] handle (pointer) to the existing (source) pointer array
1803 * hdpaNew [O] handle (pointer) to the destination pointer array
1806 * Success: pointer to the destination pointer array.
1810 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
1811 * array will be created and it's handle (pointer) is returned.
1812 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
1813 * this implementation just returns NULL.
1815 HDPA WINAPI
DPA_Clone (const HDPA hdpa
, const HDPA hdpaNew
)
1817 INT nNewItems
, nSize
;
1823 TRACE("(%p %p)\n", hdpa
, hdpaNew
);
1826 /* create a new DPA */
1827 hdpaTemp
= (HDPA
)HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
1829 hdpaTemp
->hHeap
= hdpa
->hHeap
;
1830 hdpaTemp
->nGrow
= hdpa
->nGrow
;
1835 if (hdpaTemp
->ptrs
) {
1836 /* remove old pointer array */
1837 HeapFree (hdpaTemp
->hHeap
, 0, hdpaTemp
->ptrs
);
1838 hdpaTemp
->ptrs
= NULL
;
1839 hdpaTemp
->nItemCount
= 0;
1840 hdpaTemp
->nMaxCount
= 0;
1843 /* create a new pointer array */
1844 nNewItems
= hdpaTemp
->nGrow
*
1845 ((INT
)((hdpa
->nItemCount
- 1) / hdpaTemp
->nGrow
) + 1);
1846 nSize
= nNewItems
* sizeof(LPVOID
);
1848 (LPVOID
*)HeapAlloc (hdpaTemp
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
1849 hdpaTemp
->nMaxCount
= nNewItems
;
1851 /* clone the pointer array */
1852 hdpaTemp
->nItemCount
= hdpa
->nItemCount
;
1853 memmove (hdpaTemp
->ptrs
, hdpa
->ptrs
,
1854 hdpaTemp
->nItemCount
* sizeof(LPVOID
));
1860 /**************************************************************************
1861 * DPA_GetPtr [COMCTL32.332]
1863 * Retrieves a pointer from a dynamic pointer array
1866 * hdpa [I] handle (pointer) to the pointer array
1867 * nIndex [I] array index of the desired pointer
1873 LPVOID WINAPI
DPA_GetPtr (const HDPA hdpa
, INT nIndex
)
1875 TRACE("(%p %d)\n", hdpa
, nIndex
);
1880 WARN("no pointer array.\n");
1883 if ((nIndex
< 0) || (nIndex
>= hdpa
->nItemCount
)) {
1884 WARN("not enough pointers in array (%d vs %d).\n",nIndex
,hdpa
->nItemCount
);
1888 TRACE("-- %p\n", hdpa
->ptrs
[nIndex
]);
1890 return hdpa
->ptrs
[nIndex
];
1894 /**************************************************************************
1895 * DPA_GetPtrIndex [COMCTL32.333]
1897 * Retrieves the index of the specified pointer
1900 * hdpa [I] handle (pointer) to the pointer array
1904 * Success: index of the specified pointer
1907 INT WINAPI
DPA_GetPtrIndex (const HDPA hdpa
, LPVOID p
)
1911 if (!hdpa
|| !hdpa
->ptrs
)
1914 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
1915 if (hdpa
->ptrs
[i
] == p
)
1923 /**************************************************************************
1924 * DPA_InsertPtr [COMCTL32.334]
1926 * Inserts a pointer into a dynamic pointer array
1929 * hdpa [I] handle (pointer) to the array
1931 * p [I] pointer to insert
1934 * Success: index of the inserted pointer
1937 INT WINAPI
DPA_InsertPtr (const HDPA hdpa
, INT i
, LPVOID p
)
1939 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
1941 if (!hdpa
|| i
< 0) return -1;
1944 i
= hdpa
->nItemCount
;
1946 if (i
>= hdpa
->nItemCount
)
1947 return DPA_SetPtr(hdpa
, i
, p
) ? i
: -1;
1949 /* create empty spot at the end */
1950 if (!DPA_SetPtr(hdpa
, hdpa
->nItemCount
, 0)) return -1;
1951 memmove (hdpa
->ptrs
+ i
+ 1, hdpa
->ptrs
+ i
, (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
));
1956 /**************************************************************************
1957 * DPA_SetPtr [COMCTL32.335]
1959 * Sets a pointer in the pointer array
1962 * hdpa [I] handle (pointer) to the pointer array
1963 * i [I] index of the pointer that will be set
1964 * p [I] pointer to be set
1970 BOOL WINAPI
DPA_SetPtr (const HDPA hdpa
, INT i
, LPVOID p
)
1974 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
1976 if (!hdpa
|| i
< 0 || i
> 0x7fff)
1979 if (hdpa
->nItemCount
<= i
) {
1980 /* within the old array */
1981 if (hdpa
->nMaxCount
<= i
) {
1982 /* resize the block of memory */
1984 hdpa
->nGrow
* ((INT
)(((i
+1) - 1) / hdpa
->nGrow
) + 1);
1985 INT nSize
= nNewItems
* sizeof(LPVOID
);
1988 lpTemp
= (LPVOID
*)HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, hdpa
->ptrs
, nSize
);
1990 lpTemp
= (LPVOID
*)HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
1995 hdpa
->nMaxCount
= nNewItems
;
1996 hdpa
->ptrs
= lpTemp
;
1998 hdpa
->nItemCount
= i
+1;
2001 /* put the new entry in */
2008 /**************************************************************************
2009 * DPA_DeletePtr [COMCTL32.336]
2011 * Removes a pointer from the pointer array.
2014 * hdpa [I] handle (pointer) to the pointer array
2015 * i [I] index of the pointer that will be deleted
2018 * Success: deleted pointer
2021 LPVOID WINAPI
DPA_DeletePtr (const HDPA hdpa
, INT i
)
2023 LPVOID
*lpDest
, *lpSrc
, lpTemp
= NULL
;
2026 TRACE("(%p %d)\n", hdpa
, i
);
2028 if ((!hdpa
) || i
< 0 || i
>= hdpa
->nItemCount
)
2031 lpTemp
= hdpa
->ptrs
[i
];
2033 /* do we need to move ?*/
2034 if (i
< hdpa
->nItemCount
- 1) {
2035 lpDest
= hdpa
->ptrs
+ i
;
2037 nSize
= (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
);
2038 TRACE("-- move dest=%p src=%p size=%x\n",
2039 lpDest
, lpSrc
, nSize
);
2040 memmove (lpDest
, lpSrc
, nSize
);
2043 hdpa
->nItemCount
--;
2046 if ((hdpa
->nMaxCount
- hdpa
->nItemCount
) >= hdpa
->nGrow
) {
2047 INT nNewItems
= max(hdpa
->nGrow
* 2, hdpa
->nItemCount
);
2048 nSize
= nNewItems
* sizeof(LPVOID
);
2049 lpDest
= (LPVOID
)HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
2054 hdpa
->nMaxCount
= nNewItems
;
2055 hdpa
->ptrs
= (LPVOID
*)lpDest
;
2062 /**************************************************************************
2063 * DPA_DeleteAllPtrs [COMCTL32.337]
2065 * Removes all pointers and reinitializes the array.
2068 * hdpa [I] handle (pointer) to the pointer array
2074 BOOL WINAPI
DPA_DeleteAllPtrs (const HDPA hdpa
)
2076 TRACE("(%p)\n", hdpa
);
2081 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
2084 hdpa
->nItemCount
= 0;
2085 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
2086 hdpa
->ptrs
= (LPVOID
*)HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
2087 hdpa
->nMaxCount
* sizeof(LPVOID
));
2093 /**************************************************************************
2094 * DPA_QuickSort [Internal]
2096 * Ordinary quicksort (used by DPA_Sort).
2099 * lpPtrs [I] pointer to the pointer array
2100 * l [I] index of the "left border" of the partition
2101 * r [I] index of the "right border" of the partition
2102 * pfnCompare [I] pointer to the compare function
2103 * lParam [I] user defined value (3rd parameter in compare function)
2108 static VOID
DPA_QuickSort (LPVOID
*lpPtrs
, INT l
, INT r
,
2109 PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
2114 TRACE("l=%i r=%i\n", l
, r
);
2116 if (l
==r
) /* one element is always sorted */
2118 if (r
<l
) /* oops, got it in the wrong order */
2120 DPA_QuickSort(lpPtrs
, r
, l
, pfnCompare
, lParam
);
2123 m
= (l
+r
)/2; /* divide by two */
2124 DPA_QuickSort(lpPtrs
, l
, m
, pfnCompare
, lParam
);
2125 DPA_QuickSort(lpPtrs
, m
+1, r
, pfnCompare
, lParam
);
2127 /* join the two sides */
2128 while( (l
<=m
) && (m
<r
) )
2130 if(pfnCompare(lpPtrs
[l
],lpPtrs
[m
+1],lParam
)>0)
2133 memmove(&lpPtrs
[l
+1],&lpPtrs
[l
],(m
-l
+1)*sizeof(lpPtrs
[l
]));
2143 /**************************************************************************
2144 * DPA_Sort [COMCTL32.338]
2146 * Sorts a pointer array using a user defined compare function
2149 * hdpa [I] handle (pointer) to the pointer array
2150 * pfnCompare [I] pointer to the compare function
2151 * lParam [I] user defined value (3rd parameter of compare function)
2157 BOOL WINAPI
DPA_Sort (const HDPA hdpa
, PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
2159 if (!hdpa
|| !pfnCompare
)
2162 TRACE("(%p %p 0x%lx)\n", hdpa
, pfnCompare
, lParam
);
2164 if ((hdpa
->nItemCount
> 1) && (hdpa
->ptrs
))
2165 DPA_QuickSort (hdpa
->ptrs
, 0, hdpa
->nItemCount
- 1,
2166 pfnCompare
, lParam
);
2172 /**************************************************************************
2173 * DPA_Search [COMCTL32.339]
2175 * Searches a pointer array for a specified pointer
2178 * hdpa [I] handle (pointer) to the pointer array
2179 * pFind [I] pointer to search for
2180 * nStart [I] start index
2181 * pfnCompare [I] pointer to the compare function
2182 * lParam [I] user defined value (3rd parameter of compare function)
2183 * uOptions [I] search options
2186 * Success: index of the pointer in the array.
2190 * Binary search taken from R.Sedgewick "Algorithms in C"!
2191 * Function is NOT tested!
2192 * If something goes wrong, blame HIM not ME! (Eric Kohl)
2194 INT WINAPI
DPA_Search (const HDPA hdpa
, LPVOID pFind
, INT nStart
,
2195 PFNDPACOMPARE pfnCompare
, LPARAM lParam
, UINT uOptions
)
2197 if (!hdpa
|| !pfnCompare
|| !pFind
)
2200 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
2201 hdpa
, pFind
, nStart
, pfnCompare
, lParam
, uOptions
);
2203 if (uOptions
& DPAS_SORTED
) {
2204 /* array is sorted --> use binary search */
2208 TRACE("binary search\n");
2210 l
= (nStart
== -1) ? 0 : nStart
;
2211 r
= hdpa
->nItemCount
- 1;
2215 n
= (pfnCompare
)(pFind
, lpPtr
[x
], lParam
);
2221 TRACE("-- ret=%d\n", n
);
2226 if (uOptions
& DPAS_INSERTBEFORE
) {
2228 TRACE("-- ret=%d\n", r
);
2232 if (uOptions
& DPAS_INSERTAFTER
) {
2233 TRACE("-- ret=%d\n", l
);
2238 /* array is not sorted --> use linear search */
2242 TRACE("linear search\n");
2244 nIndex
= (nStart
== -1)? 0 : nStart
;
2246 for (; nIndex
< hdpa
->nItemCount
; nIndex
++) {
2247 if ((pfnCompare
)(pFind
, lpPtr
[nIndex
], lParam
) == 0) {
2248 TRACE("-- ret=%d\n", nIndex
);
2254 TRACE("-- not found: ret=-1\n");
2259 /**************************************************************************
2260 * DPA_CreateEx [COMCTL32.340]
2262 * Creates a dynamic pointer array using the specified size and heap.
2265 * nGrow [I] number of items by which the array grows when it is filled
2266 * hHeap [I] handle to the heap where the array is stored
2269 * Success: handle (pointer) to the pointer array.
2273 * The DPA_ functions can be used to create and manipulate arrays of
2276 HDPA WINAPI
DPA_CreateEx (INT nGrow
, HANDLE hHeap
)
2280 TRACE("(%d %p)\n", nGrow
, hHeap
);
2283 hdpa
= (HDPA
)HeapAlloc (hHeap
, HEAP_ZERO_MEMORY
, sizeof(*hdpa
));
2285 hdpa
= Alloc (sizeof(*hdpa
));
2288 hdpa
->nGrow
= max(8, nGrow
);
2289 hdpa
->hHeap
= hHeap
? hHeap
: GetProcessHeap();
2290 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
2291 hdpa
->ptrs
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
2292 hdpa
->nMaxCount
* sizeof(LPVOID
));
2295 TRACE("-- %p\n", hdpa
);
2301 /**************************************************************************
2302 * DPA_Create [COMCTL32.328]
2304 * Creates a dynamic pointer array.
2307 * nGrow [I] number of items by which the array grows when it is filled
2310 * Success: handle (pointer) to the pointer array.
2314 * The DPA_ functions can be used to create and manipulate arrays of
2317 HDPA WINAPI
DPA_Create (INT nGrow
)
2319 return DPA_CreateEx( nGrow
, 0 );
2323 /**************************************************************************
2324 * Notification functions
2327 typedef struct tagNOTIFYDATA
2335 } NOTIFYDATA
, *LPNOTIFYDATA
;
2338 /**************************************************************************
2339 * DoNotify [Internal]
2342 static LRESULT
DoNotify (LPNOTIFYDATA lpNotify
, UINT uCode
, LPNMHDR lpHdr
)
2345 LPNMHDR lpNmh
= NULL
;
2348 TRACE("(%p %p %d %p 0x%08lx)\n",
2349 lpNotify
->hwndFrom
, lpNotify
->hwndTo
, uCode
, lpHdr
,
2350 lpNotify
->dwParam5
);
2352 if (!lpNotify
->hwndTo
)
2355 if (lpNotify
->hwndFrom
== (HWND
)-1) {
2357 idFrom
= lpHdr
->idFrom
;
2360 if (lpNotify
->hwndFrom
)
2361 idFrom
= GetDlgCtrlID (lpNotify
->hwndFrom
);
2363 lpNmh
= (lpHdr
) ? lpHdr
: &nmhdr
;
2365 lpNmh
->hwndFrom
= lpNotify
->hwndFrom
;
2366 lpNmh
->idFrom
= idFrom
;
2367 lpNmh
->code
= uCode
;
2370 return SendMessageA (lpNotify
->hwndTo
, WM_NOTIFY
, idFrom
, (LPARAM
)lpNmh
);
2374 /**************************************************************************
2375 * SendNotify [COMCTL32.341]
2377 * Sends a WM_NOTIFY message to the specified window.
2380 * hwndTo [I] Window to receive the message
2381 * hwndFrom [I] Window that the message is from (see notes)
2382 * uCode [I] Notification code
2383 * lpHdr [I] The NMHDR and any additional information to send or NULL
2386 * Success: return value from notification
2390 * If hwndFrom is -1 then the identifier of the control sending the
2391 * message is taken from the NMHDR structure.
2392 * If hwndFrom is not -1 then lpHdr can be NULL.
2394 LRESULT WINAPI
SendNotify (HWND hwndTo
, HWND hwndFrom
, UINT uCode
, LPNMHDR lpHdr
)
2398 TRACE("(%p %p %d %p)\n",
2399 hwndTo
, hwndFrom
, uCode
, lpHdr
);
2401 notify
.hwndFrom
= hwndFrom
;
2402 notify
.hwndTo
= hwndTo
;
2403 notify
.dwParam5
= 0;
2404 notify
.dwParam6
= 0;
2406 return DoNotify (¬ify
, uCode
, lpHdr
);
2410 /**************************************************************************
2411 * SendNotifyEx [COMCTL32.342]
2413 * Sends a WM_NOTIFY message to the specified window.
2416 * hwndFrom [I] Window to receive the message
2417 * hwndTo [I] Window that the message is from
2418 * uCode [I] Notification code
2419 * lpHdr [I] The NMHDR and any additional information to send or NULL
2420 * dwParam5 [I] Unknown
2423 * Success: return value from notification
2427 * If hwndFrom is -1 then the identifier of the control sending the
2428 * message is taken from the NMHDR structure.
2429 * If hwndFrom is not -1 then lpHdr can be NULL.
2431 LRESULT WINAPI
SendNotifyEx (HWND hwndTo
, HWND hwndFrom
, UINT uCode
,
2432 LPNMHDR lpHdr
, DWORD dwParam5
)
2437 TRACE("(%p %p %d %p 0x%08lx)\n",
2438 hwndFrom
, hwndTo
, uCode
, lpHdr
, dwParam5
);
2440 hwndNotify
= hwndTo
;
2442 if (IsWindow (hwndFrom
)) {
2443 hwndNotify
= GetParent (hwndFrom
);
2449 notify
.hwndFrom
= hwndFrom
;
2450 notify
.hwndTo
= hwndNotify
;
2451 notify
.dwParam5
= dwParam5
;
2452 notify
.dwParam6
= 0;
2454 return DoNotify (¬ify
, uCode
, lpHdr
);
2460 /**************************************************************************
2461 * DPA_EnumCallback [COMCTL32.385]
2463 * Enumerates all items in a dynamic pointer array.
2466 * hdpa [I] handle to the dynamic pointer array
2473 VOID WINAPI
DPA_EnumCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
,
2478 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
2482 if (hdpa
->nItemCount
<= 0)
2485 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
2486 if ((enumProc
)(hdpa
->ptrs
[i
], lParam
) == 0)
2494 /**************************************************************************
2495 * DPA_DestroyCallback [COMCTL32.386]
2497 * Enumerates all items in a dynamic pointer array and destroys it.
2500 * hdpa [I] handle to the dynamic pointer array
2507 void WINAPI
DPA_DestroyCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
,
2510 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
2512 DPA_EnumCallback (hdpa
, enumProc
, lParam
);
2517 /**************************************************************************
2518 * DSA_EnumCallback [COMCTL32.387]
2520 * Enumerates all items in a dynamic storage array.
2523 * hdsa [I] handle to the dynamic storage array
2530 VOID WINAPI
DSA_EnumCallback (HDSA hdsa
, PFNDSAENUMCALLBACK enumProc
,
2535 TRACE("(%p %p %p)\n", hdsa
, enumProc
, lParam
);
2539 if (hdsa
->nItemCount
<= 0)
2542 for (i
= 0; i
< hdsa
->nItemCount
; i
++) {
2543 LPVOID lpItem
= DSA_GetItemPtr (hdsa
, i
);
2544 if ((enumProc
)(lpItem
, lParam
) == 0)
2552 /**************************************************************************
2553 * DSA_DestroyCallback [COMCTL32.388]
2555 * Enumerates all items in a dynamic storage array and destroys it.
2558 * hdsa [I] handle to the dynamic storage array
2565 void WINAPI
DSA_DestroyCallback (HDSA hdsa
, PFNDSAENUMCALLBACK enumProc
,
2568 TRACE("(%p %p %p)\n", hdsa
, enumProc
, lParam
);
2570 DSA_EnumCallback (hdsa
, enumProc
, lParam
);