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 static const WCHAR strMRUList
[] = { 'M','R','U','L','i','s','t',0 };
93 /**************************************************************************
94 * DPA_LoadStream [COMCTL32.9]
96 * Loads a dynamic pointer array from a stream
99 * phDpa [O] pointer to a handle to a dynamic pointer array
100 * loadProc [I] pointer to a callback function
101 * pStream [I] pointer to a stream
102 * lParam [I] application specific value
109 * No more information available yet!
111 HRESULT WINAPI
DPA_LoadStream (HDPA
*phDpa
, DPALOADPROC loadProc
,
112 IStream
*pStream
, LPARAM lParam
)
115 LARGE_INTEGER position
;
116 ULARGE_INTEGER newPosition
;
117 STREAMDATA streamData
;
123 FIXME ("phDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
124 phDpa
, loadProc
, pStream
, lParam
);
126 if (!phDpa
|| !loadProc
|| !pStream
)
131 position
.QuadPart
= 0;
134 * Zero out our streamData
136 memset(&streamData
,0,sizeof(STREAMDATA
));
138 errCode
= IStream_Seek (pStream
, position
, STREAM_SEEK_CUR
, &newPosition
);
142 errCode
= IStream_Read (pStream
, &streamData
, sizeof(STREAMDATA
), &ulRead
);
146 FIXME ("dwSize=%lu dwData2=%lu dwItems=%lu\n",
147 streamData
.dwSize
, streamData
.dwData2
, streamData
.dwItems
);
149 if ( ulRead
< sizeof(STREAMDATA
) ||
150 lParam
< sizeof(STREAMDATA
) ||
151 streamData
.dwSize
< sizeof(STREAMDATA
) ||
152 streamData
.dwData2
< 1) {
156 if (streamData
.dwItems
> (UINT_MAX
/ 2 / sizeof(VOID
*))) /* 536870911 */
157 return E_OUTOFMEMORY
;
160 hDpa
= DPA_Create (streamData
.dwItems
);
162 return E_OUTOFMEMORY
;
164 if (!DPA_Grow (hDpa
, streamData
.dwItems
))
165 return E_OUTOFMEMORY
;
167 /* load data from the stream into the dpa */
169 for (loadData
.nCount
= 0; loadData
.nCount
< streamData
.dwItems
; loadData
.nCount
++) {
170 errCode
= (loadProc
)(&loadData
, pStream
, lParam
);
171 if (errCode
!= S_OK
) {
180 /* set the number of items */
181 hDpa
->nItemCount
= loadData
.nCount
;
183 /* store the handle to the dpa */
185 FIXME ("new hDpa=%p, errorcode=%lx\n", hDpa
, errCode
);
191 /**************************************************************************
192 * DPA_SaveStream [COMCTL32.10]
194 * Saves a dynamic pointer array to a stream
197 * hDpa [I] handle to a dynamic pointer array
198 * loadProc [I] pointer to a callback function
199 * pStream [I] pointer to a stream
200 * lParam [I] application specific value
207 * No more information available yet!
209 HRESULT WINAPI
DPA_SaveStream (const HDPA hDpa
, DPALOADPROC loadProc
,
210 IStream
*pStream
, LPARAM lParam
)
213 FIXME ("hDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
214 hDpa
, loadProc
, pStream
, lParam
);
220 /**************************************************************************
221 * DPA_Merge [COMCTL32.11]
223 * Merge two dynamic pointers arrays.
226 * hdpa1 [I] handle to a dynamic pointer array
227 * hdpa2 [I] handle to a dynamic pointer array
229 * pfnCompare [I] pointer to sort function
230 * pfnMerge [I] pointer to merge function
231 * lParam [I] application specific value
238 * No more information available yet!
240 BOOL WINAPI
DPA_Merge (const HDPA hdpa1
, const HDPA hdpa2
, DWORD dwFlags
,
241 PFNDPACOMPARE pfnCompare
, PFNDPAMERGE pfnMerge
,
245 LPVOID
*pWork1
, *pWork2
;
249 TRACE("%p %p %08lx %p %p %08lx)\n",
250 hdpa1
, hdpa2
, dwFlags
, pfnCompare
, pfnMerge
, lParam
);
252 if (IsBadWritePtr (hdpa1
, sizeof(*hdpa1
)))
255 if (IsBadWritePtr (hdpa2
, sizeof(*hdpa2
)))
258 if (IsBadCodePtr ((FARPROC
)pfnCompare
))
261 if (IsBadCodePtr ((FARPROC
)pfnMerge
))
264 if (!(dwFlags
& DPAM_NOSORT
)) {
265 TRACE("sorting dpa's!\n");
266 if (hdpa1
->nItemCount
> 0)
267 DPA_Sort (hdpa1
, pfnCompare
, lParam
);
268 TRACE ("dpa 1 sorted!\n");
269 if (hdpa2
->nItemCount
> 0)
270 DPA_Sort (hdpa2
, pfnCompare
, lParam
);
271 TRACE ("dpa 2 sorted!\n");
274 if (hdpa2
->nItemCount
< 1)
277 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
278 hdpa1
->nItemCount
, hdpa2
->nItemCount
);
281 /* working but untrusted implementation */
283 pWork1
= &(hdpa1
->ptrs
[hdpa1
->nItemCount
- 1]);
284 pWork2
= &(hdpa2
->ptrs
[hdpa2
->nItemCount
- 1]);
286 nIndex
= hdpa1
->nItemCount
- 1;
287 nCount
= hdpa2
->nItemCount
- 1;
292 if ((nCount
>= 0) && (dwFlags
& DPAM_INSERT
)) {
293 /* Now insert the remaining new items into DPA 1 */
294 TRACE("%d items to be inserted at start of DPA 1\n",
296 for (i
=nCount
; i
>=0; i
--) {
299 ptr
= (pfnMerge
)(3, *pWork2
, NULL
, lParam
);
302 DPA_InsertPtr (hdpa1
, 0, ptr
);
308 nResult
= (pfnCompare
)(*pWork1
, *pWork2
, lParam
);
309 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
310 nResult
, nIndex
, nCount
);
316 ptr
= (pfnMerge
)(1, *pWork1
, *pWork2
, lParam
);
326 else if (nResult
> 0)
328 /* item in DPA 1 missing from DPA 2 */
329 if (dwFlags
& DPAM_DELETE
)
331 /* Now delete the extra item in DPA1 */
334 ptr
= DPA_DeletePtr (hdpa1
, hdpa1
->nItemCount
- 1);
336 (pfnMerge
)(2, ptr
, NULL
, lParam
);
343 /* new item in DPA 2 */
344 if (dwFlags
& DPAM_INSERT
)
346 /* Now insert the new item in DPA 1 */
349 ptr
= (pfnMerge
)(3, *pWork2
, NULL
, lParam
);
352 DPA_InsertPtr (hdpa1
, nIndex
+1, ptr
);
365 /**************************************************************************
366 * Alloc [COMCTL32.71]
368 * Allocates memory block from the dll's private heap
371 * dwSize [I] size of the allocated memory block
374 * Success: pointer to allocated memory block
377 LPVOID WINAPI
Alloc (DWORD dwSize
)
379 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
383 /**************************************************************************
384 * ReAlloc [COMCTL32.72]
386 * Changes the size of an allocated memory block or allocates a memory
387 * block using the dll's private heap.
390 * lpSrc [I] pointer to memory block which will be resized
391 * dwSize [I] new size of the memory block.
394 * Success: pointer to the resized memory block
398 * If lpSrc is a NULL-pointer, then ReAlloc allocates a memory
401 LPVOID WINAPI
ReAlloc (LPVOID lpSrc
, DWORD dwSize
)
404 return LocalReAlloc( lpSrc
, dwSize
, LMEM_ZEROINIT
);
406 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
410 /**************************************************************************
413 * Frees an allocated memory block from the dll's private heap.
416 * 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
441 DWORD WINAPI
GetSize (LPVOID lpMem
)
443 return LocalSize( lpMem
);
447 /**************************************************************************
448 * MRU-Functions {COMCTL32}
451 * The MRU-Api is a set of functions to manipulate lists of M.R.U. (Most Recently
452 * Used) items. It is an undocumented Api that is used (at least) by the shell
453 * and explorer to implement their recent documents feature.
455 * Since these functions are undocumented, they are unsupported by MS and
456 * may change at any time.
458 * Internally, the list is implemented as a last in, last out list of items
459 * persisted into the system registry under a caller chosen key. Each list
460 * item is given a one character identifier in the Ascii range from 'a' to
461 * '}'. A list of the identifiers in order from newest to oldest is stored
462 * under the same key in a value named "MRUList".
464 * Items are re-ordered by changing the order of the values in the MRUList
465 * value. When a new item is added, it becomes the new value of the oldest
466 * identifier, and that identifier is moved to the front of the MRUList value.
468 * Wine stores MRU-lists in the same registry format as Windows, so when
469 * switching between the builtin and native comctl32.dll no problems or
470 * incompatibilities should occur.
472 * The following undocumented structure is used to create an MRU-list:
473 *|typedef INT (CALLBACK *MRUStringCmpFn)(LPCTSTR lhs, LPCTSTR rhs);
474 *|typedef INT (CALLBACK *MRUBinaryCmpFn)(LPCVOID lhs, LPCVOID rhs, DWORD length);
476 *|typedef struct tagCREATEMRULIST
482 *| LPCTSTR lpszSubKey;
484 *|} CREATEMRULIST, *LPCREATEMRULIST;
487 * cbSize [I] The size of the CREATEMRULIST structure. This must be set
488 * to sizeof(CREATEMRULIST) by the caller.
489 * nMaxItems [I] The maximum number of items allowed in the list. Because
490 * of the limited number of identifiers, this should be set to
491 * a value from 1 to 30 by the caller.
492 * dwFlags [I] If bit 0 is set, the list will be used to store binary
493 * data, otherwise it is assumed to store strings. If bit 1
494 * is set, every change made to the list will be reflected in
495 * the registry immediately, otherwise changes will only be
496 * written when the list is closed.
497 * hKey [I] The registry key that the list should be written under.
498 * This must be supplied by the caller.
499 * lpszSubKey [I] A caller supplied name of a subkey under hKey to write
500 * the list to. This may not be blank.
501 * lpfnCompare [I] A caller supplied comparison function, which may be either
502 * an MRUStringCmpFn if dwFlags does not have bit 0 set, or a
503 * MRUBinaryCmpFn otherwise.
506 * - Create an MRU-list with CreateMRUList() or CreateMRUListLazy().
507 * - Add items to an MRU-list with AddMRUString() or AddMRUData().
508 * - Remove items from an MRU-list with DelMRUString().
509 * - Find data in an MRU-list with FindMRUString() or FindMRUData().
510 * - Iterate through an MRU-list with EnumMRUList().
511 * - Free an MRU-list with FreeMRUList().
514 typedef struct tagCREATEMRULISTA
522 } CREATEMRULISTA
, *LPCREATEMRULISTA
;
524 typedef struct tagCREATEMRULISTW
532 } CREATEMRULISTW
, *LPCREATEMRULISTW
;
535 #define MRUF_STRING_LIST 0 /* list will contain strings */
536 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
537 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
539 /* If list is a string list lpfnCompare has the following prototype
540 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
541 * for binary lists the prototype is
542 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
543 * where cbData is the no. of bytes to compare.
544 * Need to check what return value means identical - 0?
547 typedef struct tagWINEMRUITEM
549 DWORD size
; /* size of data stored */
550 DWORD itemFlag
; /* flags */
552 } WINEMRUITEM
, *LPWINEMRUITEM
;
555 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
557 typedef struct tagWINEMRULIST
559 CREATEMRULISTW extview
; /* original create information */
560 BOOL isUnicode
; /* is compare fn Unicode */
561 DWORD wineFlags
; /* internal flags */
562 DWORD cursize
; /* current size of realMRU */
563 LPWSTR realMRU
; /* pointer to string of index names */
564 LPWINEMRUITEM
*array
; /* array of pointers to data */
565 /* in 'a' to 'z' order */
566 } WINEMRULIST
, *LPWINEMRULIST
;
569 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
571 /**************************************************************************
572 * MRU_SaveChanged (internal)
574 * Local MRU saving code
576 static void MRU_SaveChanged ( LPWINEMRULIST mp
)
582 static const WCHAR emptyW
[] = {'\0'};
584 /* or should we do the following instead of RegOpenKeyEx:
587 /* open the sub key */
588 if ((err
= RegOpenKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
589 0, KEY_WRITE
, &newkey
))) {
590 /* not present - what to do ??? */
591 ERR("Could not open key, error=%d, attempting to create\n",
593 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
596 REG_OPTION_NON_VOLATILE
,
597 KEY_READ
| KEY_WRITE
,
601 ERR("failed to create key /%s/, err=%d\n",
602 debugstr_w(mp
->extview
.lpszSubKey
), err
);
606 if (mp
->wineFlags
& WMRUF_CHANGED
) {
607 mp
->wineFlags
&= ~WMRUF_CHANGED
;
608 err
= RegSetValueExW(newkey
, strMRUList
, 0, REG_SZ
, (LPBYTE
)mp
->realMRU
,
609 (strlenW(mp
->realMRU
) + 1)*sizeof(WCHAR
));
611 ERR("error saving MRUList, err=%d\n", err
);
613 TRACE("saving MRUList=/%s/\n", debugstr_w(mp
->realMRU
));
616 for(i
=0; i
<mp
->cursize
; i
++) {
617 witem
= mp
->array
[i
];
618 if (witem
->itemFlag
& WMRUIF_CHANGED
) {
619 witem
->itemFlag
&= ~WMRUIF_CHANGED
;
620 realname
[0] = 'a' + i
;
621 err
= RegSetValueExW(newkey
, realname
, 0,
622 (mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) ?
624 &witem
->datastart
, witem
->size
);
626 ERR("error saving /%s/, err=%d\n", debugstr_w(realname
), err
);
628 TRACE("saving value for name /%s/ size=%ld\n",
629 debugstr_w(realname
), witem
->size
);
632 RegCloseKey( newkey
);
635 /**************************************************************************
636 * FreeMRUList [COMCTL32.152]
638 * Frees a most-recently-used items list.
641 * hMRUList [I] Handle to list.
646 void WINAPI
FreeMRUList (HANDLE hMRUList
)
648 LPWINEMRULIST mp
= (LPWINEMRULIST
)hMRUList
;
651 TRACE("(%p)\n", hMRUList
);
655 if (mp
->wineFlags
& WMRUF_CHANGED
) {
656 /* need to open key and then save the info */
657 MRU_SaveChanged( mp
);
660 for(i
=0; i
<mp
->extview
.nMaxItems
; i
++) {
666 Free((LPWSTR
)mp
->extview
.lpszSubKey
);
671 /**************************************************************************
672 * FindMRUData [COMCTL32.169]
674 * Searches binary list for item that matches lpData of length cbData.
675 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
676 * corresponding to item's reg. name will be stored in it ('a' -> 0).
679 * hList [I] list handle
680 * lpData [I] data to find
681 * cbData [I] length of data
682 * lpRegNum [O] position in registry (maybe NULL)
685 * Position in list 0 -> MRU. -1 if item not found.
687 INT WINAPI
FindMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
,
690 LPWINEMRULIST mp
= (LPWINEMRULIST
)hList
;
695 if (!mp
->extview
.lpfnCompare
) {
696 ERR("MRU list not properly created. No compare procedure.\n");
700 if(!(mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) && !mp
->isUnicode
) {
701 DWORD len
= WideCharToMultiByte(CP_ACP
, 0, lpData
, -1,
702 NULL
, 0, NULL
, NULL
);
704 WideCharToMultiByte(CP_ACP
, 0, lpData
, -1, dataA
, len
, NULL
, NULL
);
707 for(i
=0; i
<mp
->cursize
; i
++) {
708 if (mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) {
709 if (!mp
->extview
.lpfnCompare(lpData
, &mp
->array
[i
]->datastart
,
715 if (!mp
->extview
.lpfnCompare(lpData
, &mp
->array
[i
]->datastart
))
718 DWORD len
= WideCharToMultiByte(CP_ACP
, 0,
719 (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
720 NULL
, 0, NULL
, NULL
);
721 LPSTR itemA
= Alloc(len
);
723 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
724 itemA
, len
, NULL
, NULL
);
726 cmp
= mp
->extview
.lpfnCompare(dataA
, itemA
);
739 if (lpRegNum
&& (ret
!= -1))
742 TRACE("(%p, %p, %ld, %p) returning %d\n",
743 hList
, lpData
, cbData
, lpRegNum
, ret
);
749 /**************************************************************************
750 * AddMRUData [COMCTL32.167]
752 * Add item to MRU binary list. If item already exists in list then it is
753 * simply moved up to the top of the list and not added again. If list is
754 * full then the least recently used item is removed to make room.
757 * hList [I] Handle to list.
758 * lpData [I] ptr to data to add.
759 * cbData [I] no. of bytes of data.
762 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
765 INT WINAPI
AddMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
)
767 LPWINEMRULIST mp
= (LPWINEMRULIST
)hList
;
771 if ((replace
= FindMRUData (hList
, lpData
, cbData
, NULL
)) >= 0) {
772 /* Item exists, just move it to the front */
773 LPWSTR pos
= strchrW(mp
->realMRU
, replace
+ 'a');
774 while (pos
> mp
->realMRU
)
781 /* either add a new entry or replace oldest */
782 if (mp
->cursize
< mp
->extview
.nMaxItems
) {
783 /* Add in a new item */
784 replace
= mp
->cursize
;
788 /* get the oldest entry and replace data */
789 replace
= mp
->realMRU
[mp
->cursize
- 1] - 'a';
790 Free(mp
->array
[replace
]);
793 /* Allocate space for new item and move in the data */
794 mp
->array
[replace
] = witem
= Alloc(cbData
+ sizeof(WINEMRUITEM
));
795 witem
->itemFlag
|= WMRUIF_CHANGED
;
796 witem
->size
= cbData
;
797 memcpy( &witem
->datastart
, lpData
, cbData
);
799 /* now rotate MRU list */
800 for(i
=mp
->cursize
-1; i
>=1; i
--)
801 mp
->realMRU
[i
] = mp
->realMRU
[i
-1];
804 /* The new item gets the front spot */
805 mp
->wineFlags
|= WMRUF_CHANGED
;
806 mp
->realMRU
[0] = replace
+ 'a';
808 TRACE("(%p, %p, %ld) adding data, /%c/ now most current\n",
809 hList
, lpData
, cbData
, replace
+'a');
811 if (!(mp
->extview
.dwFlags
& MRUF_DELAYED_SAVE
)) {
812 /* save changed stuff right now */
813 MRU_SaveChanged( mp
);
819 /**************************************************************************
820 * AddMRUStringW [COMCTL32.401]
822 * Add an item to an MRU string list.
825 * hList [I] Handle to list.
826 * lpszString [I] The string to add.
829 * Success: The number corresponding to the registry name where the string
830 * has been stored (0 maps to 'a', 1 to 'b' and so on).
831 * Failure: -1, if hList is NULL or memory allocation fails. If lpszString
832 * is invalid, the function returns 0, and GetLastError() returns
833 * ERROR_INVALID_PARAMETER. The last error value is set only in
837 * -If lpszString exists in the list already, it is moved to the top of the
838 * MRU list (it is not duplicated).
839 * -If the list is full the least recently used list entry is replaced with
841 * -If this function returns 0 you should check the last error value to
842 * ensure the call really succeeded.
844 INT WINAPI
AddMRUStringW(HANDLE hList
, LPCWSTR lpszString
)
846 TRACE("(%p,%s)\n", hList
, debugstr_w(lpszString
));
851 if (!lpszString
|| IsBadStringPtrW(lpszString
, -1))
853 SetLastError(ERROR_INVALID_PARAMETER
);
857 return AddMRUData(hList
, lpszString
,
858 (strlenW(lpszString
) + 1) * sizeof(WCHAR
));
861 /**************************************************************************
862 * AddMRUStringA [COMCTL32.153]
866 INT WINAPI
AddMRUStringA(HANDLE hList
, LPCSTR lpszString
)
872 TRACE("(%p,%s)\n", hList
, debugstr_a(lpszString
));
877 if (IsBadStringPtrA(lpszString
, -1))
879 SetLastError(ERROR_INVALID_PARAMETER
);
883 len
= MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, NULL
, 0) * sizeof(WCHAR
);
884 stringW
= Alloc(len
);
888 MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, stringW
, len
);
889 ret
= AddMRUData(hList
, stringW
, len
);
894 /**************************************************************************
895 * DelMRUString [COMCTL32.156]
897 * Removes item from either string or binary list (despite its name)
900 * hList [I] list handle
901 * nItemPos [I] item position to remove 0 -> MRU
904 * TRUE if successful, FALSE if nItemPos is out of range.
906 BOOL WINAPI
DelMRUString(HANDLE hList
, INT nItemPos
)
908 FIXME("(%p, %d): stub\n", hList
, nItemPos
);
912 /**************************************************************************
913 * FindMRUStringW [COMCTL32.402]
915 * See FindMRUStringA.
917 INT WINAPI
FindMRUStringW (HANDLE hList
, LPCWSTR lpszString
, LPINT lpRegNum
)
919 return FindMRUData(hList
, lpszString
,
920 (lstrlenW(lpszString
) + 1) * sizeof(WCHAR
), lpRegNum
);
923 /**************************************************************************
924 * FindMRUStringA [COMCTL32.155]
926 * Searches string list for item that matches lpszString.
927 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
928 * corresponding to item's reg. name will be stored in it ('a' -> 0).
931 * hList [I] list handle
932 * lpszString [I] string to find
933 * lpRegNum [O] position in registry (maybe NULL)
936 * Position in list 0 -> MRU. -1 if item not found.
938 INT WINAPI
FindMRUStringA (HANDLE hList
, LPCSTR lpszString
, LPINT lpRegNum
)
940 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, NULL
, 0);
941 LPWSTR stringW
= Alloc(len
* sizeof(WCHAR
));
944 MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, stringW
, len
);
945 ret
= FindMRUData(hList
, stringW
, len
* sizeof(WCHAR
), lpRegNum
);
950 /*************************************************************************
951 * CreateMRUListLazy_common (internal)
953 static HANDLE
CreateMRUListLazy_common(LPWINEMRULIST mp
)
957 DWORD datasize
, dwdisp
;
961 static const WCHAR emptyW
[] = {'\0'};
963 /* get space to save indices that will turn into names
964 * but in order of most to least recently used
966 mp
->realMRU
= Alloc((mp
->extview
.nMaxItems
+ 2) * sizeof(WCHAR
));
968 /* get space to save pointers to actual data in order of
969 * 'a' to 'z' (0 to n).
971 mp
->array
= Alloc(mp
->extview
.nMaxItems
* sizeof(LPVOID
));
973 /* open the sub key */
974 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
977 REG_OPTION_NON_VOLATILE
,
978 KEY_READ
| KEY_WRITE
,
982 /* error - what to do ??? */
983 ERR("(%lu %lu %lx %lx \"%s\" %p): Could not open key, error=%d\n",
984 mp
->extview
.cbSize
, mp
->extview
.nMaxItems
, mp
->extview
.dwFlags
,
985 (DWORD
)mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
986 mp
->extview
.lpfnCompare
, err
);
990 /* get values from key 'MRUList' */
992 datasize
= mp
->extview
.nMaxItems
+ 1;
993 if((err
=RegQueryValueExW( newkey
, strMRUList
, 0, &type
,
994 (LPBYTE
)mp
->realMRU
, &datasize
))) {
995 /* not present - set size to 1 (will become 0 later) */
1000 TRACE("MRU list = %s, datasize = %ld\n", debugstr_w(mp
->realMRU
), datasize
);
1002 mp
->cursize
= datasize
- 1;
1003 /* datasize now has number of items in the MRUList */
1005 /* get actual values for each entry */
1007 for(i
=0; i
<mp
->cursize
; i
++) {
1008 realname
[0] = 'a' + i
;
1009 if(RegQueryValueExW( newkey
, realname
, 0, &type
, 0, &datasize
)) {
1010 /* not present - what to do ??? */
1011 ERR("Key %s not found 1\n", debugstr_w(realname
));
1013 mp
->array
[i
] = witem
= Alloc(datasize
+ sizeof(WINEMRUITEM
));
1014 witem
->size
= datasize
;
1015 if(RegQueryValueExW( newkey
, realname
, 0, &type
,
1016 &witem
->datastart
, &datasize
)) {
1017 /* not present - what to do ??? */
1018 ERR("Key %s not found 2\n", debugstr_w(realname
));
1021 RegCloseKey( newkey
);
1026 TRACE("(%lu %lu %lx %lx \"%s\" %p): Current Size = %ld\n",
1027 mp
->extview
.cbSize
, mp
->extview
.nMaxItems
, mp
->extview
.dwFlags
,
1028 (DWORD
)mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
1029 mp
->extview
.lpfnCompare
, mp
->cursize
);
1033 /**************************************************************************
1034 * CreateMRUListLazyW [COMCTL32.404]
1036 * See CreateMRUListLazyA.
1038 HANDLE WINAPI
CreateMRUListLazyW (LPCREATEMRULISTW lpcml
, DWORD dwParam2
,
1039 DWORD dwParam3
, DWORD dwParam4
)
1043 /* Native does not check for a NULL lpcml */
1045 if (lpcml
->cbSize
!= sizeof(CREATEMRULISTW
) || !lpcml
->hKey
||
1046 IsBadStringPtrW(lpcml
->lpszSubKey
, -1))
1049 mp
= Alloc(sizeof(WINEMRULIST
));
1050 memcpy(&mp
->extview
, lpcml
, sizeof(CREATEMRULISTW
));
1051 mp
->extview
.lpszSubKey
= Alloc((strlenW(lpcml
->lpszSubKey
) + 1) * sizeof(WCHAR
));
1052 strcpyW((LPWSTR
)mp
->extview
.lpszSubKey
, lpcml
->lpszSubKey
);
1053 mp
->isUnicode
= TRUE
;
1055 return CreateMRUListLazy_common(mp
);
1058 /**************************************************************************
1059 * CreateMRUListLazyA [COMCTL32.157]
1061 * Creates a most-recently-used list.
1064 * lpcml [I] ptr to CREATEMRULIST structure.
1065 * dwParam2 [I] Unknown
1066 * dwParam3 [I] Unknown
1067 * dwParam4 [I] Unknown
1070 * Handle to MRU list.
1072 HANDLE WINAPI
CreateMRUListLazyA (LPCREATEMRULISTA lpcml
, DWORD dwParam2
,
1073 DWORD dwParam3
, DWORD dwParam4
)
1078 /* Native does not check for a NULL lpcml */
1080 if (lpcml
->cbSize
!= sizeof(CREATEMRULISTA
) || !lpcml
->hKey
||
1081 IsBadStringPtrA(lpcml
->lpszSubKey
, -1))
1084 mp
= Alloc(sizeof(WINEMRULIST
));
1085 memcpy(&mp
->extview
, lpcml
, sizeof(CREATEMRULISTW
));
1086 len
= MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1, NULL
, 0);
1087 mp
->extview
.lpszSubKey
= Alloc(len
* sizeof(WCHAR
));
1088 MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1,
1089 (LPWSTR
)mp
->extview
.lpszSubKey
, len
);
1090 mp
->isUnicode
= FALSE
;
1091 return CreateMRUListLazy_common(mp
);
1094 /**************************************************************************
1095 * CreateMRUListW [COMCTL32.400]
1097 * See CreateMRUListA.
1099 HANDLE WINAPI
CreateMRUListW (LPCREATEMRULISTW lpcml
)
1101 return CreateMRUListLazyW(lpcml
, 0, 0, 0);
1104 /**************************************************************************
1105 * CreateMRUListA [COMCTL32.151]
1107 * Creates a most-recently-used list.
1110 * lpcml [I] ptr to CREATEMRULIST structure.
1113 * Handle to MRU list.
1115 HANDLE WINAPI
CreateMRUListA (LPCREATEMRULISTA lpcml
)
1117 return CreateMRUListLazyA (lpcml
, 0, 0, 0);
1121 /**************************************************************************
1122 * EnumMRUListW [COMCTL32.403]
1124 * Enumerate item in a most-recenty-used list
1127 * hList [I] list handle
1128 * nItemPos [I] item position to enumerate
1129 * lpBuffer [O] buffer to receive item
1130 * nBufferSize [I] size of buffer
1133 * For binary lists specifies how many bytes were copied to buffer, for
1134 * string lists specifies full length of string. Enumerating past the end
1135 * of list returns -1.
1136 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
1139 INT WINAPI
EnumMRUListW (HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
1142 LPWINEMRULIST mp
= (LPWINEMRULIST
) hList
;
1143 LPWINEMRUITEM witem
;
1144 INT desired
, datasize
;
1146 if (nItemPos
>= mp
->cursize
) return -1;
1147 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
1148 desired
= mp
->realMRU
[nItemPos
];
1150 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
1151 witem
= mp
->array
[desired
];
1152 datasize
= min( witem
->size
, nBufferSize
);
1153 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
1154 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1155 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
1159 /**************************************************************************
1160 * EnumMRUListA [COMCTL32.154]
1164 INT WINAPI
EnumMRUListA (HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
1167 LPWINEMRULIST mp
= (LPWINEMRULIST
) hList
;
1168 LPWINEMRUITEM witem
;
1169 INT desired
, datasize
;
1172 if (nItemPos
>= mp
->cursize
) return -1;
1173 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
1174 desired
= mp
->realMRU
[nItemPos
];
1176 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
1177 witem
= mp
->array
[desired
];
1178 if(mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) {
1179 datasize
= min( witem
->size
, nBufferSize
);
1180 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
1182 lenA
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
1183 NULL
, 0, NULL
, NULL
);
1184 datasize
= min( witem
->size
, nBufferSize
);
1185 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
1186 lpBuffer
, datasize
, NULL
, NULL
);
1188 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1189 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
1194 /**************************************************************************
1195 * Str_GetPtrA [COMCTL32.233]
1197 * Copies a string into a destination buffer.
1200 * lpSrc [I] Source string
1201 * lpDest [O] Destination buffer
1202 * nMaxLen [I] Size of buffer in characters
1205 * The number of characters copied.
1207 INT WINAPI
Str_GetPtrA (LPCSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
1211 TRACE("(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
1213 if (!lpDest
&& lpSrc
)
1214 return strlen (lpSrc
);
1219 if (lpSrc
== NULL
) {
1224 len
= strlen (lpSrc
);
1228 RtlMoveMemory (lpDest
, lpSrc
, len
);
1235 /**************************************************************************
1236 * Str_SetPtrA [COMCTL32.234]
1238 * Makes a copy of a string, allocating memory if necessary.
1241 * lppDest [O] Pointer to destination string
1242 * lpSrc [I] Source string
1249 * Set lpSrc to NULL to free the memory allocated by a previous call
1252 BOOL WINAPI
Str_SetPtrA (LPSTR
*lppDest
, LPCSTR lpSrc
)
1254 TRACE("(%p %p)\n", lppDest
, lpSrc
);
1257 LPSTR ptr
= ReAlloc (*lppDest
, strlen (lpSrc
) + 1);
1260 strcpy (ptr
, lpSrc
);
1274 /**************************************************************************
1275 * Str_GetPtrW [COMCTL32.235]
1279 INT WINAPI
Str_GetPtrW (LPCWSTR lpSrc
, LPWSTR lpDest
, INT nMaxLen
)
1283 TRACE("(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
1285 if (!lpDest
&& lpSrc
)
1286 return strlenW (lpSrc
);
1291 if (lpSrc
== NULL
) {
1296 len
= strlenW (lpSrc
);
1300 RtlMoveMemory (lpDest
, lpSrc
, len
*sizeof(WCHAR
));
1301 lpDest
[len
] = L
'\0';
1307 /**************************************************************************
1308 * Str_SetPtrW [COMCTL32.236]
1312 BOOL WINAPI
Str_SetPtrW (LPWSTR
*lppDest
, LPCWSTR lpSrc
)
1314 TRACE("(%p %p)\n", lppDest
, lpSrc
);
1317 INT len
= strlenW (lpSrc
) + 1;
1318 LPWSTR ptr
= ReAlloc (*lppDest
, len
* sizeof(WCHAR
));
1321 strcpyW (ptr
, lpSrc
);
1335 /**************************************************************************
1336 * Str_GetPtrWtoA [internal]
1338 * Converts a unicode string into a multi byte string
1341 * lpSrc [I] Pointer to the unicode source string
1342 * lpDest [O] Pointer to caller supplied storage for the multi byte string
1343 * nMaxLen [I] Size, in bytes, of the destination buffer
1346 * Length, in bytes, of the converted string.
1349 INT
Str_GetPtrWtoA (LPCWSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
1353 TRACE("(%s %p %d)\n", debugstr_w(lpSrc
), lpDest
, nMaxLen
);
1355 if (!lpDest
&& lpSrc
)
1356 return WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
1361 if (lpSrc
== NULL
) {
1366 len
= WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
1370 WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, lpDest
, len
, NULL
, NULL
);
1377 /**************************************************************************
1378 * Str_SetPtrAtoW [internal]
1380 * Converts a multi byte string to a unicode string.
1381 * If the pointer to the destination buffer is NULL a buffer is allocated.
1382 * If the destination buffer is too small to keep the converted multi byte
1383 * string the destination buffer is reallocated. If the source pointer is
1384 * NULL, the destination buffer is freed.
1387 * lppDest [I/O] pointer to a pointer to the destination buffer
1388 * lpSrc [I] pointer to a multi byte string
1391 * TRUE: conversion successful
1394 BOOL
Str_SetPtrAtoW (LPWSTR
*lppDest
, LPCSTR lpSrc
)
1396 TRACE("(%p %s)\n", lppDest
, lpSrc
);
1399 INT len
= MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,NULL
,0);
1400 LPWSTR ptr
= ReAlloc (*lppDest
, len
*sizeof(WCHAR
));
1404 MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,ptr
,len
);
1418 /**************************************************************************
1419 * DSA_Create [COMCTL32.320]
1421 * Creates a dynamic storage array
1424 * nSize [I] size of the array elements
1425 * nGrow [I] number of elements by which the array grows when it is filled
1428 * Success: pointer to an array control structure. Use this like a handle.
1432 * The DSA_ functions can be used to create and manipulate arrays of
1433 * fixed-size memory blocks. These arrays can store any kind of data
1434 * (e.g. strings and icons).
1436 HDSA WINAPI
DSA_Create (INT nSize
, INT nGrow
)
1440 TRACE("(size=%d grow=%d)\n", nSize
, nGrow
);
1442 hdsa
= Alloc (sizeof(*hdsa
));
1445 hdsa
->nItemCount
= 0;
1447 hdsa
->nMaxCount
= 0;
1448 hdsa
->nItemSize
= nSize
;
1449 hdsa
->nGrow
= max(1, nGrow
);
1456 /**************************************************************************
1457 * DSA_Destroy [COMCTL32.321]
1459 * Destroys a dynamic storage array
1462 * hdsa [I] pointer to the array control structure
1468 BOOL WINAPI
DSA_Destroy (const HDSA hdsa
)
1470 TRACE("(%p)\n", hdsa
);
1475 if (hdsa
->pData
&& (!Free (hdsa
->pData
)))
1482 /**************************************************************************
1483 * DSA_GetItem [COMCTL32.322]
1485 * Copies the specified item into a caller-supplied buffer.
1488 * hdsa [I] pointer to the array control structure
1489 * nIndex [I] number of the Item to get
1490 * pDest [O] destination buffer. Has to be >= dwElementSize.
1496 BOOL WINAPI
DSA_GetItem (const HDSA hdsa
, INT nIndex
, LPVOID pDest
)
1500 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pDest
);
1504 if ((nIndex
< 0) || (nIndex
>= hdsa
->nItemCount
))
1507 pSrc
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1508 memmove (pDest
, pSrc
, hdsa
->nItemSize
);
1514 /**************************************************************************
1515 * DSA_GetItemPtr [COMCTL32.323]
1517 * Retrieves a pointer to the specified item.
1520 * hdsa [I] pointer to the array control structure
1521 * nIndex [I] index of the desired item
1524 * Success: pointer to an item
1527 LPVOID WINAPI
DSA_GetItemPtr (const HDSA hdsa
, INT nIndex
)
1531 TRACE("(%p %d)\n", hdsa
, nIndex
);
1535 if ((nIndex
< 0) || (nIndex
>= hdsa
->nItemCount
))
1538 pSrc
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1540 TRACE("-- ret=%p\n", pSrc
);
1546 /**************************************************************************
1547 * DSA_SetItem [COMCTL32.325]
1549 * Sets the contents of an item in the array.
1552 * hdsa [I] pointer to the array control structure
1553 * nIndex [I] index for the item
1554 * pSrc [I] pointer to the new item data
1560 BOOL WINAPI
DSA_SetItem (const HDSA hdsa
, INT nIndex
, LPVOID pSrc
)
1562 INT nSize
, nNewItems
;
1563 LPVOID pDest
, lpTemp
;
1565 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pSrc
);
1567 if ((!hdsa
) || nIndex
< 0)
1570 if (hdsa
->nItemCount
<= nIndex
) {
1571 /* within the old array */
1572 if (hdsa
->nMaxCount
> nIndex
) {
1573 /* within the allocated space, set a new boundary */
1574 hdsa
->nItemCount
= nIndex
+ 1;
1577 /* resize the block of memory */
1579 hdsa
->nGrow
* ((INT
)(((nIndex
+ 1) - 1) / hdsa
->nGrow
) + 1);
1580 nSize
= hdsa
->nItemSize
* nNewItems
;
1582 lpTemp
= ReAlloc (hdsa
->pData
, nSize
);
1586 hdsa
->nMaxCount
= nNewItems
;
1587 hdsa
->nItemCount
= nIndex
+ 1;
1588 hdsa
->pData
= lpTemp
;
1592 /* put the new entry in */
1593 pDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1594 TRACE("-- move dest=%p src=%p size=%d\n",
1595 pDest
, pSrc
, hdsa
->nItemSize
);
1596 memmove (pDest
, pSrc
, hdsa
->nItemSize
);
1602 /**************************************************************************
1603 * DSA_InsertItem [COMCTL32.324]
1605 * Inserts an item into the array at the specified index.
1608 * hdsa [I] pointer to the array control structure
1609 * nIndex [I] index for the new item
1610 * pSrc [I] pointer to the element
1613 * Success: position of the new item
1616 INT WINAPI
DSA_InsertItem (const HDSA hdsa
, INT nIndex
, LPVOID pSrc
)
1618 INT nNewItems
, nSize
;
1619 LPVOID lpTemp
, lpDest
;
1621 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pSrc
);
1623 if ((!hdsa
) || nIndex
< 0)
1626 /* when nIndex >= nItemCount then append */
1627 if (nIndex
>= hdsa
->nItemCount
)
1628 nIndex
= hdsa
->nItemCount
;
1630 /* do we need to resize ? */
1631 if (hdsa
->nItemCount
>= hdsa
->nMaxCount
) {
1632 nNewItems
= hdsa
->nMaxCount
+ hdsa
->nGrow
;
1633 nSize
= hdsa
->nItemSize
* nNewItems
;
1635 lpTemp
= ReAlloc (hdsa
->pData
, nSize
);
1639 hdsa
->nMaxCount
= nNewItems
;
1640 hdsa
->pData
= lpTemp
;
1643 /* do we need to move elements ? */
1644 if (nIndex
< hdsa
->nItemCount
) {
1645 lpTemp
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1646 lpDest
= (char *) lpTemp
+ hdsa
->nItemSize
;
1647 nSize
= (hdsa
->nItemCount
- nIndex
) * hdsa
->nItemSize
;
1648 TRACE("-- move dest=%p src=%p size=%d\n",
1649 lpDest
, lpTemp
, nSize
);
1650 memmove (lpDest
, lpTemp
, nSize
);
1653 /* ok, we can put the new Item in */
1655 lpDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1656 TRACE("-- move dest=%p src=%p size=%d\n",
1657 lpDest
, pSrc
, hdsa
->nItemSize
);
1658 memmove (lpDest
, pSrc
, hdsa
->nItemSize
);
1664 /**************************************************************************
1665 * DSA_DeleteItem [COMCTL32.326]
1667 * Deletes the specified item from the array.
1670 * hdsa [I] pointer to the array control structure
1671 * nIndex [I] index for the element to delete
1674 * Success: number of the deleted element
1677 INT WINAPI
DSA_DeleteItem (const HDSA hdsa
, INT nIndex
)
1679 LPVOID lpDest
,lpSrc
;
1682 TRACE("(%p %d)\n", hdsa
, nIndex
);
1686 if (nIndex
< 0 || nIndex
>= hdsa
->nItemCount
)
1689 /* do we need to move ? */
1690 if (nIndex
< hdsa
->nItemCount
- 1) {
1691 lpDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1692 lpSrc
= (char *) lpDest
+ hdsa
->nItemSize
;
1693 nSize
= hdsa
->nItemSize
* (hdsa
->nItemCount
- nIndex
- 1);
1694 TRACE("-- move dest=%p src=%p size=%d\n",
1695 lpDest
, lpSrc
, nSize
);
1696 memmove (lpDest
, lpSrc
, nSize
);
1702 if ((hdsa
->nMaxCount
- hdsa
->nItemCount
) >= hdsa
->nGrow
) {
1703 nSize
= hdsa
->nItemSize
* hdsa
->nItemCount
;
1705 lpDest
= ReAlloc (hdsa
->pData
, nSize
);
1709 hdsa
->nMaxCount
= hdsa
->nItemCount
;
1710 hdsa
->pData
= lpDest
;
1717 /**************************************************************************
1718 * DSA_DeleteAllItems [COMCTL32.327]
1720 * Removes all items and reinitializes the array.
1723 * hdsa [I] pointer to the array control structure
1729 BOOL WINAPI
DSA_DeleteAllItems (const HDSA hdsa
)
1731 TRACE("(%p)\n", hdsa
);
1735 if (hdsa
->pData
&& (!Free (hdsa
->pData
)))
1738 hdsa
->nItemCount
= 0;
1740 hdsa
->nMaxCount
= 0;
1746 /**************************************************************************
1747 * DPA_Destroy [COMCTL32.329]
1749 * Destroys a dynamic pointer array
1752 * hdpa [I] handle (pointer) to the pointer array
1758 BOOL WINAPI
DPA_Destroy (const HDPA hdpa
)
1760 TRACE("(%p)\n", hdpa
);
1765 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
1768 return HeapFree (hdpa
->hHeap
, 0, hdpa
);
1772 /**************************************************************************
1773 * DPA_Grow [COMCTL32.330]
1775 * Sets the growth amount.
1778 * hdpa [I] handle (pointer) to the existing (source) pointer array
1779 * nGrow [I] number of items by which the array grows when it's too small
1785 BOOL WINAPI
DPA_Grow (const HDPA hdpa
, INT nGrow
)
1787 TRACE("(%p %d)\n", hdpa
, nGrow
);
1792 hdpa
->nGrow
= max(8, nGrow
);
1798 /**************************************************************************
1799 * DPA_Clone [COMCTL32.331]
1801 * Copies a pointer array to an other one or creates a copy
1804 * hdpa [I] handle (pointer) to the existing (source) pointer array
1805 * hdpaNew [O] handle (pointer) to the destination pointer array
1808 * Success: pointer to the destination pointer array.
1812 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
1813 * array will be created and it's handle (pointer) is returned.
1814 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
1815 * this implementation just returns NULL.
1817 HDPA WINAPI
DPA_Clone (const HDPA hdpa
, const HDPA hdpaNew
)
1819 INT nNewItems
, nSize
;
1825 TRACE("(%p %p)\n", hdpa
, hdpaNew
);
1828 /* create a new DPA */
1829 hdpaTemp
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
1831 hdpaTemp
->hHeap
= hdpa
->hHeap
;
1832 hdpaTemp
->nGrow
= hdpa
->nGrow
;
1837 if (hdpaTemp
->ptrs
) {
1838 /* remove old pointer array */
1839 HeapFree (hdpaTemp
->hHeap
, 0, hdpaTemp
->ptrs
);
1840 hdpaTemp
->ptrs
= NULL
;
1841 hdpaTemp
->nItemCount
= 0;
1842 hdpaTemp
->nMaxCount
= 0;
1845 /* create a new pointer array */
1846 nNewItems
= hdpaTemp
->nGrow
*
1847 ((INT
)((hdpa
->nItemCount
- 1) / hdpaTemp
->nGrow
) + 1);
1848 nSize
= nNewItems
* sizeof(LPVOID
);
1849 hdpaTemp
->ptrs
= HeapAlloc (hdpaTemp
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
1850 hdpaTemp
->nMaxCount
= nNewItems
;
1852 /* clone the pointer array */
1853 hdpaTemp
->nItemCount
= hdpa
->nItemCount
;
1854 memmove (hdpaTemp
->ptrs
, hdpa
->ptrs
,
1855 hdpaTemp
->nItemCount
* sizeof(LPVOID
));
1861 /**************************************************************************
1862 * DPA_GetPtr [COMCTL32.332]
1864 * Retrieves a pointer from a dynamic pointer array
1867 * hdpa [I] handle (pointer) to the pointer array
1868 * nIndex [I] array index of the desired pointer
1874 LPVOID WINAPI
DPA_GetPtr (const HDPA hdpa
, INT nIndex
)
1876 TRACE("(%p %d)\n", hdpa
, nIndex
);
1881 WARN("no pointer array.\n");
1884 if ((nIndex
< 0) || (nIndex
>= hdpa
->nItemCount
)) {
1885 WARN("not enough pointers in array (%d vs %d).\n",nIndex
,hdpa
->nItemCount
);
1889 TRACE("-- %p\n", hdpa
->ptrs
[nIndex
]);
1891 return hdpa
->ptrs
[nIndex
];
1895 /**************************************************************************
1896 * DPA_GetPtrIndex [COMCTL32.333]
1898 * Retrieves the index of the specified pointer
1901 * hdpa [I] handle (pointer) to the pointer array
1905 * Success: index of the specified pointer
1908 INT WINAPI
DPA_GetPtrIndex (const HDPA hdpa
, LPVOID p
)
1912 if (!hdpa
|| !hdpa
->ptrs
)
1915 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
1916 if (hdpa
->ptrs
[i
] == p
)
1924 /**************************************************************************
1925 * DPA_InsertPtr [COMCTL32.334]
1927 * Inserts a pointer into a dynamic pointer array
1930 * hdpa [I] handle (pointer) to the array
1932 * p [I] pointer to insert
1935 * Success: index of the inserted pointer
1938 INT WINAPI
DPA_InsertPtr (const HDPA hdpa
, INT i
, LPVOID p
)
1940 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
1942 if (!hdpa
|| i
< 0) return -1;
1945 i
= hdpa
->nItemCount
;
1947 if (i
>= hdpa
->nItemCount
)
1948 return DPA_SetPtr(hdpa
, i
, p
) ? i
: -1;
1950 /* create empty spot at the end */
1951 if (!DPA_SetPtr(hdpa
, hdpa
->nItemCount
, 0)) return -1;
1952 memmove (hdpa
->ptrs
+ i
+ 1, hdpa
->ptrs
+ i
, (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
));
1957 /**************************************************************************
1958 * DPA_SetPtr [COMCTL32.335]
1960 * Sets a pointer in the pointer array
1963 * hdpa [I] handle (pointer) to the pointer array
1964 * i [I] index of the pointer that will be set
1965 * p [I] pointer to be set
1971 BOOL WINAPI
DPA_SetPtr (const HDPA hdpa
, INT i
, LPVOID p
)
1975 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
1977 if (!hdpa
|| i
< 0 || i
> 0x7fff)
1980 if (hdpa
->nItemCount
<= i
) {
1981 /* within the old array */
1982 if (hdpa
->nMaxCount
<= i
) {
1983 /* resize the block of memory */
1985 hdpa
->nGrow
* ((INT
)(((i
+1) - 1) / hdpa
->nGrow
) + 1);
1986 INT nSize
= nNewItems
* sizeof(LPVOID
);
1989 lpTemp
= HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, hdpa
->ptrs
, nSize
);
1991 lpTemp
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
1996 hdpa
->nMaxCount
= nNewItems
;
1997 hdpa
->ptrs
= lpTemp
;
1999 hdpa
->nItemCount
= i
+1;
2002 /* put the new entry in */
2009 /**************************************************************************
2010 * DPA_DeletePtr [COMCTL32.336]
2012 * Removes a pointer from the pointer array.
2015 * hdpa [I] handle (pointer) to the pointer array
2016 * i [I] index of the pointer that will be deleted
2019 * Success: deleted pointer
2022 LPVOID WINAPI
DPA_DeletePtr (const HDPA hdpa
, INT i
)
2024 LPVOID
*lpDest
, *lpSrc
, lpTemp
= NULL
;
2027 TRACE("(%p %d)\n", hdpa
, i
);
2029 if ((!hdpa
) || i
< 0 || i
>= hdpa
->nItemCount
)
2032 lpTemp
= hdpa
->ptrs
[i
];
2034 /* do we need to move ?*/
2035 if (i
< hdpa
->nItemCount
- 1) {
2036 lpDest
= hdpa
->ptrs
+ i
;
2038 nSize
= (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
);
2039 TRACE("-- move dest=%p src=%p size=%x\n",
2040 lpDest
, lpSrc
, nSize
);
2041 memmove (lpDest
, lpSrc
, nSize
);
2044 hdpa
->nItemCount
--;
2047 if ((hdpa
->nMaxCount
- hdpa
->nItemCount
) >= hdpa
->nGrow
) {
2048 INT nNewItems
= max(hdpa
->nGrow
* 2, hdpa
->nItemCount
);
2049 nSize
= nNewItems
* sizeof(LPVOID
);
2050 lpDest
= HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
2055 hdpa
->nMaxCount
= nNewItems
;
2056 hdpa
->ptrs
= (LPVOID
*)lpDest
;
2063 /**************************************************************************
2064 * DPA_DeleteAllPtrs [COMCTL32.337]
2066 * Removes all pointers and reinitializes the array.
2069 * hdpa [I] handle (pointer) to the pointer array
2075 BOOL WINAPI
DPA_DeleteAllPtrs (const HDPA hdpa
)
2077 TRACE("(%p)\n", hdpa
);
2082 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
2085 hdpa
->nItemCount
= 0;
2086 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
2087 hdpa
->ptrs
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
2088 hdpa
->nMaxCount
* sizeof(LPVOID
));
2094 /**************************************************************************
2095 * DPA_QuickSort [Internal]
2097 * Ordinary quicksort (used by DPA_Sort).
2100 * lpPtrs [I] pointer to the pointer array
2101 * l [I] index of the "left border" of the partition
2102 * r [I] index of the "right border" of the partition
2103 * pfnCompare [I] pointer to the compare function
2104 * lParam [I] user defined value (3rd parameter in compare function)
2109 static VOID
DPA_QuickSort (LPVOID
*lpPtrs
, INT l
, INT r
,
2110 PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
2115 TRACE("l=%i r=%i\n", l
, r
);
2117 if (l
==r
) /* one element is always sorted */
2119 if (r
<l
) /* oops, got it in the wrong order */
2121 DPA_QuickSort(lpPtrs
, r
, l
, pfnCompare
, lParam
);
2124 m
= (l
+r
)/2; /* divide by two */
2125 DPA_QuickSort(lpPtrs
, l
, m
, pfnCompare
, lParam
);
2126 DPA_QuickSort(lpPtrs
, m
+1, r
, pfnCompare
, lParam
);
2128 /* join the two sides */
2129 while( (l
<=m
) && (m
<r
) )
2131 if(pfnCompare(lpPtrs
[l
],lpPtrs
[m
+1],lParam
)>0)
2134 memmove(&lpPtrs
[l
+1],&lpPtrs
[l
],(m
-l
+1)*sizeof(lpPtrs
[l
]));
2144 /**************************************************************************
2145 * DPA_Sort [COMCTL32.338]
2147 * Sorts a pointer array using a user defined compare function
2150 * hdpa [I] handle (pointer) to the pointer array
2151 * pfnCompare [I] pointer to the compare function
2152 * lParam [I] user defined value (3rd parameter of compare function)
2158 BOOL WINAPI
DPA_Sort (const HDPA hdpa
, PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
2160 if (!hdpa
|| !pfnCompare
)
2163 TRACE("(%p %p 0x%lx)\n", hdpa
, pfnCompare
, lParam
);
2165 if ((hdpa
->nItemCount
> 1) && (hdpa
->ptrs
))
2166 DPA_QuickSort (hdpa
->ptrs
, 0, hdpa
->nItemCount
- 1,
2167 pfnCompare
, lParam
);
2173 /**************************************************************************
2174 * DPA_Search [COMCTL32.339]
2176 * Searches a pointer array for a specified pointer
2179 * hdpa [I] handle (pointer) to the pointer array
2180 * pFind [I] pointer to search for
2181 * nStart [I] start index
2182 * pfnCompare [I] pointer to the compare function
2183 * lParam [I] user defined value (3rd parameter of compare function)
2184 * uOptions [I] search options
2187 * Success: index of the pointer in the array.
2191 * Binary search taken from R.Sedgewick "Algorithms in C"!
2192 * Function is NOT tested!
2193 * If something goes wrong, blame HIM not ME! (Eric Kohl)
2195 INT WINAPI
DPA_Search (const HDPA hdpa
, LPVOID pFind
, INT nStart
,
2196 PFNDPACOMPARE pfnCompare
, LPARAM lParam
, UINT uOptions
)
2198 if (!hdpa
|| !pfnCompare
|| !pFind
)
2201 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
2202 hdpa
, pFind
, nStart
, pfnCompare
, lParam
, uOptions
);
2204 if (uOptions
& DPAS_SORTED
) {
2205 /* array is sorted --> use binary search */
2209 TRACE("binary search\n");
2211 l
= (nStart
== -1) ? 0 : nStart
;
2212 r
= hdpa
->nItemCount
- 1;
2216 n
= (pfnCompare
)(pFind
, lpPtr
[x
], lParam
);
2222 TRACE("-- ret=%d\n", n
);
2227 if (uOptions
& DPAS_INSERTBEFORE
) {
2229 TRACE("-- ret=%d\n", r
);
2233 if (uOptions
& DPAS_INSERTAFTER
) {
2234 TRACE("-- ret=%d\n", l
);
2239 /* array is not sorted --> use linear search */
2243 TRACE("linear search\n");
2245 nIndex
= (nStart
== -1)? 0 : nStart
;
2247 for (; nIndex
< hdpa
->nItemCount
; nIndex
++) {
2248 if ((pfnCompare
)(pFind
, lpPtr
[nIndex
], lParam
) == 0) {
2249 TRACE("-- ret=%d\n", nIndex
);
2255 TRACE("-- not found: ret=-1\n");
2260 /**************************************************************************
2261 * DPA_CreateEx [COMCTL32.340]
2263 * Creates a dynamic pointer array using the specified size and heap.
2266 * nGrow [I] number of items by which the array grows when it is filled
2267 * hHeap [I] handle to the heap where the array is stored
2270 * Success: handle (pointer) to the pointer array.
2274 * The DPA_ functions can be used to create and manipulate arrays of
2277 HDPA WINAPI
DPA_CreateEx (INT nGrow
, HANDLE hHeap
)
2281 TRACE("(%d %p)\n", nGrow
, hHeap
);
2284 hdpa
= HeapAlloc (hHeap
, HEAP_ZERO_MEMORY
, sizeof(*hdpa
));
2286 hdpa
= Alloc (sizeof(*hdpa
));
2289 hdpa
->nGrow
= max(8, nGrow
);
2290 hdpa
->hHeap
= hHeap
? hHeap
: GetProcessHeap();
2291 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
2292 hdpa
->ptrs
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
2293 hdpa
->nMaxCount
* sizeof(LPVOID
));
2296 TRACE("-- %p\n", hdpa
);
2302 /**************************************************************************
2303 * DPA_Create [COMCTL32.328]
2305 * Creates a dynamic pointer array.
2308 * nGrow [I] number of items by which the array grows when it is filled
2311 * Success: handle (pointer) to the pointer array.
2315 * The DPA_ functions can be used to create and manipulate arrays of
2318 HDPA WINAPI
DPA_Create (INT nGrow
)
2320 return DPA_CreateEx( nGrow
, 0 );
2324 /**************************************************************************
2325 * Notification functions
2328 typedef struct tagNOTIFYDATA
2336 } NOTIFYDATA
, *LPNOTIFYDATA
;
2339 /**************************************************************************
2340 * DoNotify [Internal]
2343 static LRESULT
DoNotify (LPNOTIFYDATA lpNotify
, UINT uCode
, LPNMHDR lpHdr
)
2346 LPNMHDR lpNmh
= NULL
;
2349 TRACE("(%p %p %d %p 0x%08lx)\n",
2350 lpNotify
->hwndFrom
, lpNotify
->hwndTo
, uCode
, lpHdr
,
2351 lpNotify
->dwParam5
);
2353 if (!lpNotify
->hwndTo
)
2356 if (lpNotify
->hwndFrom
== (HWND
)-1) {
2358 idFrom
= lpHdr
->idFrom
;
2361 if (lpNotify
->hwndFrom
)
2362 idFrom
= GetDlgCtrlID (lpNotify
->hwndFrom
);
2364 lpNmh
= (lpHdr
) ? lpHdr
: &nmhdr
;
2366 lpNmh
->hwndFrom
= lpNotify
->hwndFrom
;
2367 lpNmh
->idFrom
= idFrom
;
2368 lpNmh
->code
= uCode
;
2371 return SendMessageW (lpNotify
->hwndTo
, WM_NOTIFY
, idFrom
, (LPARAM
)lpNmh
);
2375 /**************************************************************************
2376 * SendNotify [COMCTL32.341]
2378 * Sends a WM_NOTIFY message to the specified window.
2381 * hwndTo [I] Window to receive the message
2382 * hwndFrom [I] Window that the message is from (see notes)
2383 * uCode [I] Notification code
2384 * lpHdr [I] The NMHDR and any additional information to send or NULL
2387 * Success: return value from notification
2391 * If hwndFrom is -1 then the identifier of the control sending the
2392 * message is taken from the NMHDR structure.
2393 * If hwndFrom is not -1 then lpHdr can be NULL.
2395 LRESULT WINAPI
SendNotify (HWND hwndTo
, HWND hwndFrom
, UINT uCode
, LPNMHDR lpHdr
)
2399 TRACE("(%p %p %d %p)\n",
2400 hwndTo
, hwndFrom
, uCode
, lpHdr
);
2402 notify
.hwndFrom
= hwndFrom
;
2403 notify
.hwndTo
= hwndTo
;
2404 notify
.dwParam5
= 0;
2405 notify
.dwParam6
= 0;
2407 return DoNotify (¬ify
, uCode
, lpHdr
);
2411 /**************************************************************************
2412 * SendNotifyEx [COMCTL32.342]
2414 * Sends a WM_NOTIFY message to the specified window.
2417 * hwndFrom [I] Window to receive the message
2418 * hwndTo [I] Window that the message is from
2419 * uCode [I] Notification code
2420 * lpHdr [I] The NMHDR and any additional information to send or NULL
2421 * dwParam5 [I] Unknown
2424 * Success: return value from notification
2428 * If hwndFrom is -1 then the identifier of the control sending the
2429 * message is taken from the NMHDR structure.
2430 * If hwndFrom is not -1 then lpHdr can be NULL.
2432 LRESULT WINAPI
SendNotifyEx (HWND hwndTo
, HWND hwndFrom
, UINT uCode
,
2433 LPNMHDR lpHdr
, DWORD dwParam5
)
2438 TRACE("(%p %p %d %p 0x%08lx)\n",
2439 hwndFrom
, hwndTo
, uCode
, lpHdr
, dwParam5
);
2441 hwndNotify
= hwndTo
;
2443 if (IsWindow (hwndFrom
)) {
2444 hwndNotify
= GetParent (hwndFrom
);
2450 notify
.hwndFrom
= hwndFrom
;
2451 notify
.hwndTo
= hwndNotify
;
2452 notify
.dwParam5
= dwParam5
;
2453 notify
.dwParam6
= 0;
2455 return DoNotify (¬ify
, uCode
, lpHdr
);
2461 /**************************************************************************
2462 * DPA_EnumCallback [COMCTL32.385]
2464 * Enumerates all items in a dynamic pointer array.
2467 * hdpa [I] handle to the dynamic pointer array
2474 VOID WINAPI
DPA_EnumCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
,
2479 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
2483 if (hdpa
->nItemCount
<= 0)
2486 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
2487 if ((enumProc
)(hdpa
->ptrs
[i
], lParam
) == 0)
2495 /**************************************************************************
2496 * DPA_DestroyCallback [COMCTL32.386]
2498 * Enumerates all items in a dynamic pointer array and destroys it.
2501 * hdpa [I] handle to the dynamic pointer array
2508 void WINAPI
DPA_DestroyCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
,
2511 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
2513 DPA_EnumCallback (hdpa
, enumProc
, lParam
);
2518 /**************************************************************************
2519 * DSA_EnumCallback [COMCTL32.387]
2521 * Enumerates all items in a dynamic storage array.
2524 * hdsa [I] handle to the dynamic storage array
2531 VOID WINAPI
DSA_EnumCallback (HDSA hdsa
, PFNDSAENUMCALLBACK enumProc
,
2536 TRACE("(%p %p %p)\n", hdsa
, enumProc
, lParam
);
2540 if (hdsa
->nItemCount
<= 0)
2543 for (i
= 0; i
< hdsa
->nItemCount
; i
++) {
2544 LPVOID lpItem
= DSA_GetItemPtr (hdsa
, i
);
2545 if ((enumProc
)(lpItem
, lParam
) == 0)
2553 /**************************************************************************
2554 * DSA_DestroyCallback [COMCTL32.388]
2556 * Enumerates all items in a dynamic storage array and destroys it.
2559 * hdsa [I] handle to the dynamic storage array
2566 void WINAPI
DSA_DestroyCallback (HDSA hdsa
, PFNDSAENUMCALLBACK enumProc
,
2569 TRACE("(%p %p %p)\n", hdsa
, enumProc
, lParam
);
2571 DSA_EnumCallback (hdsa
, enumProc
, lParam
);