2 * Undocumented functions from COMCTL32.DLL
4 * Copyright 1998 Eric Kohl
5 * 1998 Juergen Schmied <j.schmied@metronet.de>
6 * 2000 Eric Kohl for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * All of these functions are UNDOCUMENTED!! And I mean UNDOCUMENTED!!!!
24 * Do NOT rely on names or contents of undocumented structures and types!!!
25 * These functions are used by EXPLORER.EXE, IEXPLORE.EXE and
26 * COMCTL32.DLL (internally).
30 #include "wine/port.h"
37 #define NONAMELESSUNION
38 #define NONAMELESSSTRUCT
49 #include "wine/unicode.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(commctrl
);
74 typedef struct _STREAMDATA
79 } STREAMDATA
, *PSTREAMDATA
;
81 typedef struct _LOADDATA
85 } LOADDATA
, *LPLOADDATA
;
87 typedef HRESULT (CALLBACK
*DPALOADPROC
)(LPLOADDATA
,IStream
*,LPARAM
);
89 /**************************************************************************
90 * DPA_LoadStream [COMCTL32.9]
92 * Loads a dynamic pointer array from a stream
95 * phDpa [O] pointer to a handle to a dynamic pointer array
96 * loadProc [I] pointer to a callback function
97 * pStream [I] pointer to a stream
98 * lParam [I] application specific value
105 * No more information available yet!
109 DPA_LoadStream (HDPA
*phDpa
, DPALOADPROC loadProc
, IStream
*pStream
, LPARAM lParam
)
112 LARGE_INTEGER position
;
113 ULARGE_INTEGER newPosition
;
114 STREAMDATA streamData
;
120 FIXME ("phDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
121 phDpa
, loadProc
, pStream
, lParam
);
123 if (!phDpa
|| !loadProc
|| !pStream
)
128 position
.QuadPart
= 0;
131 * Zero out our streamData
133 memset(&streamData
,0,sizeof(STREAMDATA
));
135 errCode
= IStream_Seek (pStream
, position
, STREAM_SEEK_CUR
, &newPosition
);
139 errCode
= IStream_Read (pStream
, &streamData
, sizeof(STREAMDATA
), &ulRead
);
143 FIXME ("dwSize=%lu dwData2=%lu dwItems=%lu\n",
144 streamData
.dwSize
, streamData
.dwData2
, streamData
.dwItems
);
146 if ( ulRead
< sizeof(STREAMDATA
) ||
147 lParam
< sizeof(STREAMDATA
) ||
148 streamData
.dwSize
< sizeof(STREAMDATA
) ||
149 streamData
.dwData2
< 1) {
153 if (streamData
.dwItems
> (UINT_MAX
/ 2 / sizeof(VOID
*))) /* 536870911 */
154 return E_OUTOFMEMORY
;
157 hDpa
= DPA_Create (streamData
.dwItems
);
159 return E_OUTOFMEMORY
;
161 if (!DPA_Grow (hDpa
, streamData
.dwItems
))
162 return E_OUTOFMEMORY
;
164 /* load data from the stream into the dpa */
166 for (loadData
.nCount
= 0; loadData
.nCount
< streamData
.dwItems
; loadData
.nCount
++) {
167 errCode
= (loadProc
)(&loadData
, pStream
, lParam
);
168 if (errCode
!= S_OK
) {
177 /* set the number of items */
178 hDpa
->nItemCount
= loadData
.nCount
;
180 /* store the handle to the dpa */
182 FIXME ("new hDpa=%p, errorcode=%lx\n", hDpa
, errCode
);
188 /**************************************************************************
189 * DPA_SaveStream [COMCTL32.10]
191 * Saves a dynamic pointer array to a stream
194 * hDpa [I] handle to a dynamic pointer array
195 * loadProc [I] pointer to a callback function
196 * pStream [I] pointer to a stream
197 * lParam [I] application specific value
204 * No more information available yet!
208 DPA_SaveStream (const HDPA hDpa
, DPALOADPROC loadProc
, IStream
*pStream
, LPARAM lParam
)
211 FIXME ("hDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
212 hDpa
, loadProc
, pStream
, lParam
);
218 /**************************************************************************
219 * DPA_Merge [COMCTL32.11]
222 * hdpa1 [I] handle to a dynamic pointer array
223 * hdpa2 [I] handle to a dynamic pointer array
225 * pfnCompare [I] pointer to sort function
226 * pfnMerge [I] pointer to merge function
227 * lParam [I] application specific value
234 * No more information available yet!
238 DPA_Merge (const HDPA hdpa1
, const HDPA hdpa2
, DWORD dwFlags
,
239 PFNDPACOMPARE pfnCompare
, PFNDPAMERGE pfnMerge
, LPARAM lParam
)
242 LPVOID
*pWork1
, *pWork2
;
246 TRACE("%p %p %08lx %p %p %08lx)\n",
247 hdpa1
, hdpa2
, dwFlags
, pfnCompare
, pfnMerge
, lParam
);
249 if (IsBadWritePtr (hdpa1
, sizeof(*hdpa1
)))
252 if (IsBadWritePtr (hdpa2
, sizeof(*hdpa2
)))
255 if (IsBadCodePtr ((FARPROC
)pfnCompare
))
258 if (IsBadCodePtr ((FARPROC
)pfnMerge
))
261 if (!(dwFlags
& DPAM_NOSORT
)) {
262 TRACE("sorting dpa's!\n");
263 if (hdpa1
->nItemCount
> 0)
264 DPA_Sort (hdpa1
, pfnCompare
, lParam
);
265 TRACE ("dpa 1 sorted!\n");
266 if (hdpa2
->nItemCount
> 0)
267 DPA_Sort (hdpa2
, pfnCompare
, lParam
);
268 TRACE ("dpa 2 sorted!\n");
271 if (hdpa2
->nItemCount
< 1)
274 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
275 hdpa1
->nItemCount
, hdpa2
->nItemCount
);
278 /* working but untrusted implementation */
280 pWork1
= &(hdpa1
->ptrs
[hdpa1
->nItemCount
- 1]);
281 pWork2
= &(hdpa2
->ptrs
[hdpa2
->nItemCount
- 1]);
283 nIndex
= hdpa1
->nItemCount
- 1;
284 nCount
= hdpa2
->nItemCount
- 1;
289 if ((nCount
>= 0) && (dwFlags
& DPAM_INSERT
)) {
290 /* Now insert the remaining new items into DPA 1 */
291 TRACE("%d items to be inserted at start of DPA 1\n",
293 for (i
=nCount
; i
>=0; i
--) {
296 ptr
= (pfnMerge
)(3, *pWork2
, NULL
, lParam
);
299 DPA_InsertPtr (hdpa1
, 0, ptr
);
305 nResult
= (pfnCompare
)(*pWork1
, *pWork2
, lParam
);
306 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
307 nResult
, nIndex
, nCount
);
313 ptr
= (pfnMerge
)(1, *pWork1
, *pWork2
, lParam
);
323 else if (nResult
> 0)
325 /* item in DPA 1 missing from DPA 2 */
326 if (dwFlags
& DPAM_DELETE
)
328 /* Now delete the extra item in DPA1 */
331 ptr
= DPA_DeletePtr (hdpa1
, hdpa1
->nItemCount
- 1);
333 (pfnMerge
)(2, ptr
, NULL
, lParam
);
340 /* new item in DPA 2 */
341 if (dwFlags
& DPAM_INSERT
)
343 /* Now insert the new item in DPA 1 */
346 ptr
= (pfnMerge
)(3, *pWork2
, NULL
, lParam
);
349 DPA_InsertPtr (hdpa1
, nIndex
+1, ptr
);
362 /**************************************************************************
363 * Alloc [COMCTL32.71]
365 * Allocates memory block from the dll's private heap
368 * dwSize [I] size of the allocated memory block
371 * Success: pointer to allocated memory block
375 LPVOID WINAPI
Alloc (DWORD dwSize
)
377 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
381 /**************************************************************************
382 * ReAlloc [COMCTL32.72]
384 * Changes the size of an allocated memory block or allocates a memory
385 * block using the dll's private heap.
388 * lpSrc [I] pointer to memory block which will be resized
389 * dwSize [I] new size of the memory block.
392 * Success: pointer to the resized memory block
396 * If lpSrc is a NULL-pointer, then ReAlloc allocates a memory
400 LPVOID WINAPI
ReAlloc (LPVOID lpSrc
, DWORD dwSize
)
403 return LocalReAlloc( lpSrc
, dwSize
, LMEM_ZEROINIT
);
405 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
409 /**************************************************************************
412 * Frees an allocated memory block from the dll's private heap.
415 * lpMem [I] pointer to memory block which will be freed
422 BOOL WINAPI
Free (LPVOID lpMem
)
424 return !LocalFree( lpMem
);
428 /**************************************************************************
429 * GetSize [COMCTL32.74]
431 * Retrieves the size of the specified memory block from the dll's
435 * lpMem [I] pointer to an allocated memory block
438 * Success: size of the specified memory block
442 DWORD WINAPI
GetSize (LPVOID lpMem
)
444 return LocalSize( lpMem
);
448 /**************************************************************************
449 * The MRU-API is a set of functions to manipulate MRU(Most Recently Used)
452 * Stored in the reg. as a set of values under a single key. Each item in the
453 * list has a value name that is a single char. 'a' - 'z', '{', '|' or '}'.
454 * The order of the list is stored with value name 'MRUList' which is a string
455 * containing the value names (i.e. 'a', 'b', etc.) in the relevant order.
458 typedef struct tagCREATEMRULISTA
460 DWORD cbSize
; /* size of struct */
461 DWORD nMaxItems
; /* max no. of items in list */
462 DWORD dwFlags
; /* see below */
463 HKEY hKey
; /* root reg. key under which list is saved */
464 LPCSTR lpszSubKey
; /* reg. subkey */
465 PROC lpfnCompare
; /* item compare proc */
466 } CREATEMRULISTA
, *LPCREATEMRULISTA
;
468 typedef struct tagCREATEMRULISTW
470 DWORD cbSize
; /* size of struct */
471 DWORD nMaxItems
; /* max no. of items in list */
472 DWORD dwFlags
; /* see below */
473 HKEY hKey
; /* root reg. key under which list is saved */
474 LPCWSTR lpszSubKey
; /* reg. subkey */
475 PROC lpfnCompare
; /* item compare proc */
476 } CREATEMRULISTW
, *LPCREATEMRULISTW
;
479 #define MRUF_STRING_LIST 0 /* list will contain strings */
480 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
481 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
483 /* If list is a string list lpfnCompare has the following prototype
484 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
485 * for binary lists the prototype is
486 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
487 * where cbData is the no. of bytes to compare.
488 * Need to check what return value means identical - 0?
491 typedef struct tagWINEMRUITEM
493 DWORD size
; /* size of data stored */
494 DWORD itemFlag
; /* flags */
496 } WINEMRUITEM
, *LPWINEMRUITEM
;
499 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
501 typedef struct tagWINEMRULIST
503 CREATEMRULISTW extview
; /* original create information */
504 BOOL isUnicode
; /* is compare fn Unicode */
505 DWORD wineFlags
; /* internal flags */
506 DWORD cursize
; /* current size of realMRU */
507 LPSTR realMRU
; /* pointer to string of index names */
508 LPWINEMRUITEM
*array
; /* array of pointers to data */
509 /* in 'a' to 'z' order */
510 } WINEMRULIST
, *LPWINEMRULIST
;
513 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
515 /**************************************************************************
516 * MRU_SaveChanged (internal)
518 * Localize MRU saving code
520 VOID
MRU_SaveChanged( LPWINEMRULIST mp
)
526 static const WCHAR emptyW
[] = {'\0'};
528 /* or should we do the following instead of RegOpenKeyEx:
531 /* open the sub key */
532 if ((err
= RegOpenKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
533 0, KEY_WRITE
, &newkey
))) {
534 /* not present - what to do ??? */
535 ERR("Can not open key, error=%d, attempting to create\n",
537 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
540 REG_OPTION_NON_VOLATILE
,
541 KEY_READ
| KEY_WRITE
,
545 ERR("failed to create key /%s/, err=%d\n",
546 debugstr_w(mp
->extview
.lpszSubKey
), err
);
550 if (mp
->wineFlags
& WMRUF_CHANGED
) {
551 mp
->wineFlags
&= ~WMRUF_CHANGED
;
552 err
= RegSetValueExA(newkey
, "MRUList", 0, REG_SZ
,
553 mp
->realMRU
, strlen(mp
->realMRU
) + 1);
555 ERR("error saving MRUList, err=%d\n", err
);
557 TRACE("saving MRUList=/%s/\n", mp
->realMRU
);
560 for(i
=0; i
<mp
->cursize
; i
++) {
561 witem
= mp
->array
[i
];
562 if (witem
->itemFlag
& WMRUIF_CHANGED
) {
563 witem
->itemFlag
&= ~WMRUIF_CHANGED
;
564 realname
[0] = 'a' + i
;
565 err
= RegSetValueExW(newkey
, realname
, 0,
566 (mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) ?
568 &witem
->datastart
, witem
->size
);
570 ERR("error saving /%s/, err=%d\n", debugstr_w(realname
), err
);
572 TRACE("saving value for name /%s/ size=%ld\n",
573 debugstr_w(realname
), witem
->size
);
576 RegCloseKey( newkey
);
579 /**************************************************************************
580 * FreeMRUList [COMCTL32.152]
582 * Frees a most-recently-used items list.
585 * hMRUList [I] Handle to list.
592 FreeMRUList (HANDLE hMRUList
)
594 LPWINEMRULIST mp
= (LPWINEMRULIST
)hMRUList
;
598 if (mp
->wineFlags
& WMRUF_CHANGED
) {
599 /* need to open key and then save the info */
600 MRU_SaveChanged( mp
);
603 for(i
=0; i
<mp
->extview
.nMaxItems
; i
++) {
609 Free((LPWSTR
)mp
->extview
.lpszSubKey
);
614 /**************************************************************************
615 * FindMRUData [COMCTL32.169]
617 * Searches binary list for item that matches lpData of length cbData.
618 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
619 * corresponding to item's reg. name will be stored in it ('a' -> 0).
622 * hList [I] list handle
623 * lpData [I] data to find
624 * cbData [I] length of data
625 * lpRegNum [O] position in registry (maybe NULL)
628 * Position in list 0 -> MRU. -1 if item not found.
631 FindMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
, LPINT lpRegNum
)
633 LPWINEMRULIST mp
= (LPWINEMRULIST
)hList
;
638 if (!mp
->extview
.lpfnCompare
) {
639 ERR("MRU list not properly created. No compare procedure.\n");
643 if(!(mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) && !mp
->isUnicode
) {
644 DWORD len
= WideCharToMultiByte(CP_ACP
, 0, lpData
, -1,
645 NULL
, 0, NULL
, NULL
);
647 WideCharToMultiByte(CP_ACP
, 0, lpData
, -1, dataA
, len
, NULL
, NULL
);
650 for(i
=0; i
<mp
->cursize
; i
++) {
651 if (mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) {
652 if (!mp
->extview
.lpfnCompare(lpData
, &mp
->array
[i
]->datastart
,
658 if (!mp
->extview
.lpfnCompare(lpData
, &mp
->array
[i
]->datastart
))
661 DWORD len
= WideCharToMultiByte(CP_ACP
, 0,
662 (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
663 NULL
, 0, NULL
, NULL
);
664 LPSTR itemA
= Alloc(len
);
666 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
667 itemA
, len
, NULL
, NULL
);
669 cmp
= mp
->extview
.lpfnCompare(dataA
, itemA
);
682 if (lpRegNum
&& (ret
!= -1))
685 TRACE("(%p, %p, %ld, %p) returning %d\n",
686 hList
, lpData
, cbData
, lpRegNum
, ret
);
692 /**************************************************************************
693 * AddMRUData [COMCTL32.167]
695 * Add item to MRU binary list. If item already exists in list then it is
696 * simply moved up to the top of the list and not added again. If list is
697 * full then the least recently used item is removed to make room.
700 * hList [I] Handle to list.
701 * lpData [I] ptr to data to add.
702 * cbData [I] no. of bytes of data.
705 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
709 AddMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
)
711 LPWINEMRULIST mp
= (LPWINEMRULIST
)hList
;
715 if ((replace
= FindMRUData (hList
, lpData
, cbData
, NULL
)) < 0) {
716 /* either add a new entry or replace oldest */
717 if (mp
->cursize
< mp
->extview
.nMaxItems
) {
718 /* Add in a new item */
719 replace
= mp
->cursize
;
723 /* get the oldest entry and replace data */
724 replace
= mp
->realMRU
[mp
->cursize
- 1] - 'a';
725 Free(mp
->array
[replace
]);
729 /* free up the old data */
730 Free(mp
->array
[replace
]);
733 /* Allocate space for new item and move in the data */
734 mp
->array
[replace
] = witem
= Alloc(cbData
+ sizeof(WINEMRUITEM
));
735 witem
->itemFlag
|= WMRUIF_CHANGED
;
736 witem
->size
= cbData
;
737 memcpy( &witem
->datastart
, lpData
, cbData
);
739 /* now rotate MRU list */
740 mp
->wineFlags
|= WMRUF_CHANGED
;
741 for(i
=mp
->cursize
-1; i
>=1; i
--) {
742 mp
->realMRU
[i
] = mp
->realMRU
[i
-1];
744 mp
->realMRU
[0] = replace
+ 'a';
745 TRACE("(%p, %p, %ld) adding data, /%c/ now most current\n",
746 hList
, lpData
, cbData
, replace
+'a');
749 if (!(mp
->extview
.dwFlags
& MRUF_DELAYED_SAVE
)) {
750 /* save changed stuff right now */
751 MRU_SaveChanged( mp
);
757 /**************************************************************************
758 * AddMRUStringW [COMCTL32.401]
760 * Add item to MRU string list. If item already exists in list them it is
761 * simply moved up to the top of the list and not added again. If list is
762 * full then the least recently used item is removed to make room.
765 * hList [I] Handle to list.
766 * lpszString [I] ptr to string to add.
769 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
773 AddMRUStringW(HANDLE hList
, LPCWSTR lpszString
)
775 FIXME("(%p, %s) empty stub!\n", hList
, debugstr_w(lpszString
));
780 /**************************************************************************
781 * AddMRUStringA [COMCTL32.153]
786 AddMRUStringA(HANDLE hList
, LPCSTR lpszString
)
788 FIXME("(%p, %s) empty stub!\n", hList
, debugstr_a(lpszString
));
793 /**************************************************************************
794 * DelMRUString [COMCTL32.156]
796 * Removes item from either string or binary list (despite its name)
799 * hList [I] list handle
800 * nItemPos [I] item position to remove 0 -> MRU
803 * TRUE if successful, FALSE if nItemPos is out of range.
806 DelMRUString(HANDLE hList
, INT nItemPos
)
808 FIXME("(%p, %d): stub\n", hList
, nItemPos
);
812 /**************************************************************************
813 * FindMRUStringW [COMCTL32.402]
815 * See FindMRUStringA.
818 FindMRUStringW (HANDLE hList
, LPCWSTR lpszString
, LPINT lpRegNum
)
824 /**************************************************************************
825 * FindMRUStringA [COMCTL32.155]
827 * Searches string list for item that matches lpszString.
828 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
829 * corresponding to item's reg. name will be stored in it ('a' -> 0).
832 * hList [I] list handle
833 * lpszString [I] string to find
834 * lpRegNum [O] position in registry (maybe NULL)
837 * Position in list 0 -> MRU. -1 if item not found.
840 FindMRUStringA (HANDLE hList
, LPCSTR lpszString
, LPINT lpRegNum
)
842 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, NULL
, 0);
843 LPWSTR stringW
= Alloc(len
* sizeof(WCHAR
));
846 MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, stringW
, len
);
847 ret
= FindMRUData(hList
, stringW
, len
* sizeof(WCHAR
), lpRegNum
);
852 /*************************************************************************
853 * CreateMRUListLazy_common (internal)
855 HANDLE
CreateMRUListLazy_common(LPWINEMRULIST mp
)
859 DWORD datasize
, dwdisp
;
863 static const WCHAR emptyW
[] = {'\0'};
865 /* get space to save indices that will turn into names
866 * but in order of most to least recently used
868 mp
->realMRU
= Alloc(mp
->extview
.nMaxItems
+ 2);
870 /* get space to save pointers to actual data in order of
871 * 'a' to 'z' (0 to n).
873 mp
->array
= Alloc(mp
->extview
.nMaxItems
* sizeof(LPVOID
));
875 /* open the sub key */
876 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
879 REG_OPTION_NON_VOLATILE
,
880 KEY_READ
| KEY_WRITE
,
884 /* error - what to do ??? */
885 ERR("(%lu %lu %lx %lx \"%s\" %p): Can not open key, error=%d\n",
886 mp
->extview
.cbSize
, mp
->extview
.nMaxItems
, mp
->extview
.dwFlags
,
887 (DWORD
)mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
888 mp
->extview
.lpfnCompare
, err
);
892 /* get values from key 'MRUList' */
894 datasize
= mp
->extview
.nMaxItems
+ 1;
895 if((err
=RegQueryValueExA( newkey
, "MRUList", 0, &type
, mp
->realMRU
,
897 /* not present - set size to 1 (will become 0 later) */
902 TRACE("MRU list = %s\n", mp
->realMRU
);
904 mp
->cursize
= datasize
- 1;
905 /* datasize now has number of items in the MRUList */
907 /* get actual values for each entry */
909 for(i
=0; i
<mp
->cursize
; i
++) {
910 realname
[0] = 'a' + i
;
911 if(RegQueryValueExW( newkey
, realname
, 0, &type
, 0, &datasize
)) {
912 /* not present - what to do ??? */
913 ERR("Key %s not found 1\n", debugstr_w(realname
));
915 mp
->array
[i
] = witem
= Alloc(datasize
+ sizeof(WINEMRUITEM
));
916 witem
->size
= datasize
;
917 if(RegQueryValueExW( newkey
, realname
, 0, &type
,
918 &witem
->datastart
, &datasize
)) {
919 /* not present - what to do ??? */
920 ERR("Key %s not found 2\n", debugstr_w(realname
));
923 RegCloseKey( newkey
);
928 TRACE("(%lu %lu %lx %lx \"%s\" %p): Current Size = %ld\n",
929 mp
->extview
.cbSize
, mp
->extview
.nMaxItems
, mp
->extview
.dwFlags
,
930 (DWORD
)mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
931 mp
->extview
.lpfnCompare
, mp
->cursize
);
935 /**************************************************************************
936 * CreateMRUListLazyW [COMCTL32.404]
938 * See CreateMRUListLazyA.
941 CreateMRUListLazyW (LPCREATEMRULISTW lpcml
, DWORD dwParam2
, DWORD dwParam3
, DWORD dwParam4
)
948 if (lpcml
->cbSize
< sizeof(CREATEMRULISTW
))
951 mp
= Alloc(sizeof(WINEMRULIST
));
952 memcpy(&mp
->extview
, lpcml
, sizeof(CREATEMRULISTW
));
953 mp
->extview
.lpszSubKey
= Alloc((strlenW(lpcml
->lpszSubKey
) + 1) * sizeof(WCHAR
));
954 strcpyW((LPWSTR
)mp
->extview
.lpszSubKey
, lpcml
->lpszSubKey
);
955 mp
->isUnicode
= TRUE
;
957 return CreateMRUListLazy_common(mp
);
960 /**************************************************************************
961 * CreateMRUListLazyA [COMCTL32.157]
963 * Creates a most-recently-used list.
966 * lpcml [I] ptr to CREATEMRULIST structure.
967 * dwParam2 [I] Unknown
968 * dwParam3 [I] Unknown
969 * dwParam4 [I] Unknown
972 * Handle to MRU list.
975 CreateMRUListLazyA (LPCREATEMRULISTA lpcml
, DWORD dwParam2
, DWORD dwParam3
, DWORD dwParam4
)
983 if (lpcml
->cbSize
< sizeof(CREATEMRULISTA
))
986 mp
= Alloc(sizeof(WINEMRULIST
));
987 memcpy(&mp
->extview
, lpcml
, sizeof(CREATEMRULISTW
));
988 len
= MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1, NULL
, 0);
989 mp
->extview
.lpszSubKey
= Alloc(len
* sizeof(WCHAR
));
990 MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1,
991 (LPWSTR
)mp
->extview
.lpszSubKey
, len
);
992 mp
->isUnicode
= FALSE
;
993 return CreateMRUListLazy_common(mp
);
996 /**************************************************************************
997 * CreateMRUListW [COMCTL32.400]
999 * See CreateMRUListA.
1002 CreateMRUListW (LPCREATEMRULISTW lpcml
)
1004 return CreateMRUListLazyW(lpcml
, 0, 0, 0);
1007 /**************************************************************************
1008 * CreateMRUListA [COMCTL32.151]
1010 * Creates a most-recently-used list.
1013 * lpcml [I] ptr to CREATEMRULIST structure.
1016 * Handle to MRU list.
1019 CreateMRUListA (LPCREATEMRULISTA lpcml
)
1021 return CreateMRUListLazyA (lpcml
, 0, 0, 0);
1025 /**************************************************************************
1026 * EnumMRUListW [COMCTL32.403]
1028 * Enumerate item in a most-recenty-used list
1031 * hList [I] list handle
1032 * nItemPos [I] item position to enumerate
1033 * lpBuffer [O] buffer to receive item
1034 * nBufferSize [I] size of buffer
1037 * For binary lists specifies how many bytes were copied to buffer, for
1038 * string lists specifies full length of string. Enumerating past the end
1039 * of list returns -1.
1040 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
1043 INT WINAPI
EnumMRUListW(HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
1046 LPWINEMRULIST mp
= (LPWINEMRULIST
) hList
;
1047 LPWINEMRUITEM witem
;
1048 INT desired
, datasize
;
1050 if (nItemPos
>= mp
->cursize
) return -1;
1051 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
1052 desired
= mp
->realMRU
[nItemPos
];
1054 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
1055 witem
= mp
->array
[desired
];
1056 datasize
= min( witem
->size
, nBufferSize
);
1057 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
1058 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1059 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
1063 /**************************************************************************
1064 * EnumMRUListA [COMCTL32.154]
1068 INT WINAPI
EnumMRUListA(HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
1071 LPWINEMRULIST mp
= (LPWINEMRULIST
) hList
;
1072 LPWINEMRUITEM witem
;
1073 INT desired
, datasize
;
1076 if (nItemPos
>= mp
->cursize
) return -1;
1077 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
1078 desired
= mp
->realMRU
[nItemPos
];
1080 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
1081 witem
= mp
->array
[desired
];
1082 if(mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) {
1083 datasize
= min( witem
->size
, nBufferSize
);
1084 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
1086 lenA
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
1087 NULL
, 0, NULL
, NULL
);
1088 datasize
= min( witem
->size
, nBufferSize
);
1089 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
1090 lpBuffer
, datasize
, NULL
, NULL
);
1092 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1093 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
1098 /**************************************************************************
1099 * Str_GetPtrA [COMCTL32.233]
1101 * Copies a string into a destination buffer.
1104 * lpSrc [I] Source string
1105 * lpDest [O] Destination buffer
1106 * nMaxLen [I] Size of buffer in characters
1109 * The number of characters copied.
1113 Str_GetPtrA (LPCSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
1117 TRACE("(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
1119 if (!lpDest
&& lpSrc
)
1120 return strlen (lpSrc
);
1125 if (lpSrc
== NULL
) {
1130 len
= strlen (lpSrc
);
1134 RtlMoveMemory (lpDest
, lpSrc
, len
);
1141 /**************************************************************************
1142 * Str_SetPtrA [COMCTL32.234]
1144 * Makes a copy of a string, allocating memory if necessary.
1147 * lppDest [O] Pointer to destination string
1148 * lpSrc [I] Source string
1155 * Set lpSrc to NULL to free the memory allocated by a previous call
1160 Str_SetPtrA (LPSTR
*lppDest
, LPCSTR lpSrc
)
1162 TRACE("(%p %p)\n", lppDest
, lpSrc
);
1165 LPSTR ptr
= ReAlloc (*lppDest
, strlen (lpSrc
) + 1);
1168 strcpy (ptr
, lpSrc
);
1182 /**************************************************************************
1183 * Str_GetPtrW [COMCTL32.235]
1189 Str_GetPtrW (LPCWSTR lpSrc
, LPWSTR lpDest
, INT nMaxLen
)
1193 TRACE("(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
1195 if (!lpDest
&& lpSrc
)
1196 return strlenW (lpSrc
);
1201 if (lpSrc
== NULL
) {
1206 len
= strlenW (lpSrc
);
1210 RtlMoveMemory (lpDest
, lpSrc
, len
*sizeof(WCHAR
));
1211 lpDest
[len
] = L
'\0';
1217 /**************************************************************************
1218 * Str_SetPtrW [COMCTL32.236]
1224 Str_SetPtrW (LPWSTR
*lppDest
, LPCWSTR lpSrc
)
1226 TRACE("(%p %p)\n", lppDest
, lpSrc
);
1229 INT len
= strlenW (lpSrc
) + 1;
1230 LPWSTR ptr
= ReAlloc (*lppDest
, len
* sizeof(WCHAR
));
1233 strcpyW (ptr
, lpSrc
);
1247 /**************************************************************************
1248 * Str_GetPtrWtoA [internal]
1250 * Converts a unicode string into a multi byte string
1253 * lpSrc [I] Pointer to the unicode source string
1254 * lpDest [O] Pointer to caller supplied storage for the multi byte string
1255 * nMaxLen [I] Size, in bytes, of the destination buffer
1258 * Length, in bytes, of the converted string.
1262 Str_GetPtrWtoA (LPCWSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
1266 TRACE("(%s %p %d)\n", debugstr_w(lpSrc
), lpDest
, nMaxLen
);
1268 if (!lpDest
&& lpSrc
)
1269 return WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
1274 if (lpSrc
== NULL
) {
1279 len
= WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
1283 WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, lpDest
, len
, NULL
, NULL
);
1290 /**************************************************************************
1291 * Str_SetPtrAtoW [internal]
1293 * Converts a multi byte string to a unicode string.
1294 * If the pointer to the destination buffer is NULL a buffer is allocated.
1295 * If the destination buffer is too small to keep the converted multi byte
1296 * string the destination buffer is reallocated. If the source pointer is
1297 * NULL, the destination buffer is freed.
1300 * lppDest [I/O] pointer to a pointer to the destination buffer
1301 * lpSrc [I] pointer to a multi byte string
1304 * TRUE: conversion successful
1309 Str_SetPtrAtoW (LPWSTR
*lppDest
, LPCSTR lpSrc
)
1311 TRACE("(%p %s)\n", lppDest
, lpSrc
);
1314 INT len
= MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,NULL
,0);
1315 LPWSTR ptr
= ReAlloc (*lppDest
, len
*sizeof(WCHAR
));
1319 MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,ptr
,len
);
1333 /**************************************************************************
1334 * DSA_Create [COMCTL32.320]
1336 * Creates a dynamic storage array
1339 * nSize [I] size of the array elements
1340 * nGrow [I] number of elements by which the array grows when it is filled
1343 * Success: pointer to an array control structure. Use this like a handle.
1347 * The DSA_ functions can be used to create and manipulate arrays of
1348 * fixed-size memory blocks. These arrays can store any kind of data
1349 * (e.g. strings and icons).
1353 DSA_Create (INT nSize
, INT nGrow
)
1357 TRACE("(size=%d grow=%d)\n", nSize
, nGrow
);
1359 hdsa
= Alloc (sizeof(*hdsa
));
1362 hdsa
->nItemCount
= 0;
1364 hdsa
->nMaxCount
= 0;
1365 hdsa
->nItemSize
= nSize
;
1366 hdsa
->nGrow
= max(1, nGrow
);
1373 /**************************************************************************
1374 * DSA_Destroy [COMCTL32.321]
1376 * Destroys a dynamic storage array
1379 * hdsa [I] pointer to the array control structure
1387 DSA_Destroy (const HDSA hdsa
)
1389 TRACE("(%p)\n", hdsa
);
1394 if (hdsa
->pData
&& (!Free (hdsa
->pData
)))
1401 /**************************************************************************
1402 * DSA_GetItem [COMCTL32.322]
1404 * Copies the specified item into a caller-supplied buffer.
1407 * hdsa [I] pointer to the array control structure
1408 * nIndex [I] number of the Item to get
1409 * pDest [O] destination buffer. Has to be >= dwElementSize.
1417 DSA_GetItem (const HDSA hdsa
, INT nIndex
, LPVOID pDest
)
1421 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pDest
);
1425 if ((nIndex
< 0) || (nIndex
>= hdsa
->nItemCount
))
1428 pSrc
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1429 memmove (pDest
, pSrc
, hdsa
->nItemSize
);
1435 /**************************************************************************
1436 * DSA_GetItemPtr [COMCTL32.323]
1438 * Retrieves a pointer to the specified item.
1441 * hdsa [I] pointer to the array control structure
1442 * nIndex [I] index of the desired item
1445 * Success: pointer to an item
1450 DSA_GetItemPtr (const HDSA hdsa
, INT nIndex
)
1454 TRACE("(%p %d)\n", hdsa
, nIndex
);
1458 if ((nIndex
< 0) || (nIndex
>= hdsa
->nItemCount
))
1461 pSrc
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1463 TRACE("-- ret=%p\n", pSrc
);
1469 /**************************************************************************
1470 * DSA_SetItem [COMCTL32.325]
1472 * Sets the contents of an item in the array.
1475 * hdsa [I] pointer to the array control structure
1476 * nIndex [I] index for the item
1477 * pSrc [I] pointer to the new item data
1485 DSA_SetItem (const HDSA hdsa
, INT nIndex
, LPVOID pSrc
)
1487 INT nSize
, nNewItems
;
1488 LPVOID pDest
, lpTemp
;
1490 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pSrc
);
1492 if ((!hdsa
) || nIndex
< 0)
1495 if (hdsa
->nItemCount
<= nIndex
) {
1496 /* within the old array */
1497 if (hdsa
->nMaxCount
> nIndex
) {
1498 /* within the allocated space, set a new boundary */
1499 hdsa
->nItemCount
= nIndex
+ 1;
1502 /* resize the block of memory */
1504 hdsa
->nGrow
* ((INT
)(((nIndex
+ 1) - 1) / hdsa
->nGrow
) + 1);
1505 nSize
= hdsa
->nItemSize
* nNewItems
;
1507 lpTemp
= ReAlloc (hdsa
->pData
, nSize
);
1511 hdsa
->nMaxCount
= nNewItems
;
1512 hdsa
->nItemCount
= nIndex
+ 1;
1513 hdsa
->pData
= lpTemp
;
1517 /* put the new entry in */
1518 pDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1519 TRACE("-- move dest=%p src=%p size=%d\n",
1520 pDest
, pSrc
, hdsa
->nItemSize
);
1521 memmove (pDest
, pSrc
, hdsa
->nItemSize
);
1527 /**************************************************************************
1528 * DSA_InsertItem [COMCTL32.324]
1530 * Inserts an item into the array at the specified index.
1533 * hdsa [I] pointer to the array control structure
1534 * nIndex [I] index for the new item
1535 * pSrc [I] pointer to the element
1538 * Success: position of the new item
1543 DSA_InsertItem (const HDSA hdsa
, INT nIndex
, LPVOID pSrc
)
1545 INT nNewItems
, nSize
;
1546 LPVOID lpTemp
, lpDest
;
1548 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pSrc
);
1550 if ((!hdsa
) || nIndex
< 0)
1553 /* when nIndex >= nItemCount then append */
1554 if (nIndex
>= hdsa
->nItemCount
)
1555 nIndex
= hdsa
->nItemCount
;
1557 /* do we need to resize ? */
1558 if (hdsa
->nItemCount
>= hdsa
->nMaxCount
) {
1559 nNewItems
= hdsa
->nMaxCount
+ hdsa
->nGrow
;
1560 nSize
= hdsa
->nItemSize
* nNewItems
;
1562 lpTemp
= ReAlloc (hdsa
->pData
, nSize
);
1566 hdsa
->nMaxCount
= nNewItems
;
1567 hdsa
->pData
= lpTemp
;
1570 /* do we need to move elements ? */
1571 if (nIndex
< hdsa
->nItemCount
) {
1572 lpTemp
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1573 lpDest
= (char *) lpTemp
+ hdsa
->nItemSize
;
1574 nSize
= (hdsa
->nItemCount
- nIndex
) * hdsa
->nItemSize
;
1575 TRACE("-- move dest=%p src=%p size=%d\n",
1576 lpDest
, lpTemp
, nSize
);
1577 memmove (lpDest
, lpTemp
, nSize
);
1580 /* ok, we can put the new Item in */
1582 lpDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1583 TRACE("-- move dest=%p src=%p size=%d\n",
1584 lpDest
, pSrc
, hdsa
->nItemSize
);
1585 memmove (lpDest
, pSrc
, hdsa
->nItemSize
);
1591 /**************************************************************************
1592 * DSA_DeleteItem [COMCTL32.326]
1594 * Deletes the specified item from the array.
1597 * hdsa [I] pointer to the array control structure
1598 * nIndex [I] index for the element to delete
1601 * Success: number of the deleted element
1606 DSA_DeleteItem (const HDSA hdsa
, INT nIndex
)
1608 LPVOID lpDest
,lpSrc
;
1611 TRACE("(%p %d)\n", hdsa
, nIndex
);
1615 if (nIndex
< 0 || nIndex
>= hdsa
->nItemCount
)
1618 /* do we need to move ? */
1619 if (nIndex
< hdsa
->nItemCount
- 1) {
1620 lpDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1621 lpSrc
= (char *) lpDest
+ hdsa
->nItemSize
;
1622 nSize
= hdsa
->nItemSize
* (hdsa
->nItemCount
- nIndex
- 1);
1623 TRACE("-- move dest=%p src=%p size=%d\n",
1624 lpDest
, lpSrc
, nSize
);
1625 memmove (lpDest
, lpSrc
, nSize
);
1631 if ((hdsa
->nMaxCount
- hdsa
->nItemCount
) >= hdsa
->nGrow
) {
1632 nSize
= hdsa
->nItemSize
* hdsa
->nItemCount
;
1634 lpDest
= ReAlloc (hdsa
->pData
, nSize
);
1638 hdsa
->nMaxCount
= hdsa
->nItemCount
;
1639 hdsa
->pData
= lpDest
;
1646 /**************************************************************************
1647 * DSA_DeleteAllItems [COMCTL32.327]
1649 * Removes all items and reinitializes the array.
1652 * hdsa [I] pointer to the array control structure
1660 DSA_DeleteAllItems (const HDSA hdsa
)
1662 TRACE("(%p)\n", hdsa
);
1666 if (hdsa
->pData
&& (!Free (hdsa
->pData
)))
1669 hdsa
->nItemCount
= 0;
1671 hdsa
->nMaxCount
= 0;
1677 /**************************************************************************
1678 * DPA_Destroy [COMCTL32.329]
1680 * Destroys a dynamic pointer array
1683 * hdpa [I] handle (pointer) to the pointer array
1691 DPA_Destroy (const HDPA hdpa
)
1693 TRACE("(%p)\n", hdpa
);
1698 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
1701 return HeapFree (hdpa
->hHeap
, 0, hdpa
);
1705 /**************************************************************************
1706 * DPA_Grow [COMCTL32.330]
1708 * Sets the growth amount.
1711 * hdpa [I] handle (pointer) to the existing (source) pointer array
1712 * nGrow [I] number of items by which the array grows when it's too small
1720 DPA_Grow (const HDPA hdpa
, INT nGrow
)
1722 TRACE("(%p %d)\n", hdpa
, nGrow
);
1727 hdpa
->nGrow
= max(8, nGrow
);
1733 /**************************************************************************
1734 * DPA_Clone [COMCTL32.331]
1736 * Copies a pointer array to an other one or creates a copy
1739 * hdpa [I] handle (pointer) to the existing (source) pointer array
1740 * hdpaNew [O] handle (pointer) to the destination pointer array
1743 * Success: pointer to the destination pointer array.
1747 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
1748 * array will be created and it's handle (pointer) is returned.
1749 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
1750 * this implementation just returns NULL.
1754 DPA_Clone (const HDPA hdpa
, const HDPA hdpaNew
)
1756 INT nNewItems
, nSize
;
1762 TRACE("(%p %p)\n", hdpa
, hdpaNew
);
1765 /* create a new DPA */
1766 hdpaTemp
= (HDPA
)HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
1768 hdpaTemp
->hHeap
= hdpa
->hHeap
;
1769 hdpaTemp
->nGrow
= hdpa
->nGrow
;
1774 if (hdpaTemp
->ptrs
) {
1775 /* remove old pointer array */
1776 HeapFree (hdpaTemp
->hHeap
, 0, hdpaTemp
->ptrs
);
1777 hdpaTemp
->ptrs
= NULL
;
1778 hdpaTemp
->nItemCount
= 0;
1779 hdpaTemp
->nMaxCount
= 0;
1782 /* create a new pointer array */
1783 nNewItems
= hdpaTemp
->nGrow
*
1784 ((INT
)((hdpa
->nItemCount
- 1) / hdpaTemp
->nGrow
) + 1);
1785 nSize
= nNewItems
* sizeof(LPVOID
);
1787 (LPVOID
*)HeapAlloc (hdpaTemp
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
1788 hdpaTemp
->nMaxCount
= nNewItems
;
1790 /* clone the pointer array */
1791 hdpaTemp
->nItemCount
= hdpa
->nItemCount
;
1792 memmove (hdpaTemp
->ptrs
, hdpa
->ptrs
,
1793 hdpaTemp
->nItemCount
* sizeof(LPVOID
));
1799 /**************************************************************************
1800 * DPA_GetPtr [COMCTL32.332]
1802 * Retrieves a pointer from a dynamic pointer array
1805 * hdpa [I] handle (pointer) to the pointer array
1806 * nIndex [I] array index of the desired pointer
1814 DPA_GetPtr (const HDPA hdpa
, INT nIndex
)
1816 TRACE("(%p %d)\n", hdpa
, nIndex
);
1821 WARN("no pointer array.\n");
1824 if ((nIndex
< 0) || (nIndex
>= hdpa
->nItemCount
)) {
1825 WARN("not enough pointers in array (%d vs %d).\n",nIndex
,hdpa
->nItemCount
);
1829 TRACE("-- %p\n", hdpa
->ptrs
[nIndex
]);
1831 return hdpa
->ptrs
[nIndex
];
1835 /**************************************************************************
1836 * DPA_GetPtrIndex [COMCTL32.333]
1838 * Retrieves the index of the specified pointer
1841 * hdpa [I] handle (pointer) to the pointer array
1845 * Success: index of the specified pointer
1850 DPA_GetPtrIndex (const HDPA hdpa
, LPVOID p
)
1854 if (!hdpa
|| !hdpa
->ptrs
)
1857 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
1858 if (hdpa
->ptrs
[i
] == p
)
1866 /**************************************************************************
1867 * DPA_InsertPtr [COMCTL32.334]
1869 * Inserts a pointer into a dynamic pointer array
1872 * hdpa [I] handle (pointer) to the array
1874 * p [I] pointer to insert
1877 * Success: index of the inserted pointer
1882 DPA_InsertPtr (const HDPA hdpa
, INT i
, LPVOID p
)
1884 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
1886 if (!hdpa
|| i
< 0) return -1;
1889 i
= hdpa
->nItemCount
;
1891 if (i
>= hdpa
->nItemCount
)
1892 return DPA_SetPtr(hdpa
, i
, p
) ? i
: -1;
1894 /* create empty spot at the end */
1895 if (!DPA_SetPtr(hdpa
, hdpa
->nItemCount
, 0)) return -1;
1896 memmove (hdpa
->ptrs
+ i
+ 1, hdpa
->ptrs
+ i
, (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
));
1901 /**************************************************************************
1902 * DPA_SetPtr [COMCTL32.335]
1904 * Sets a pointer in the pointer array
1907 * hdpa [I] handle (pointer) to the pointer array
1908 * i [I] index of the pointer that will be set
1909 * p [I] pointer to be set
1917 DPA_SetPtr (const HDPA hdpa
, INT i
, LPVOID p
)
1921 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
1923 if (!hdpa
|| i
< 0 || i
> 0x7fff)
1926 if (hdpa
->nItemCount
<= i
) {
1927 /* within the old array */
1928 if (hdpa
->nMaxCount
<= i
) {
1929 /* resize the block of memory */
1931 hdpa
->nGrow
* ((INT
)(((i
+1) - 1) / hdpa
->nGrow
) + 1);
1932 INT nSize
= nNewItems
* sizeof(LPVOID
);
1935 lpTemp
= (LPVOID
*)HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, hdpa
->ptrs
, nSize
);
1937 lpTemp
= (LPVOID
*)HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
1942 hdpa
->nMaxCount
= nNewItems
;
1943 hdpa
->ptrs
= lpTemp
;
1945 hdpa
->nItemCount
= i
+1;
1948 /* put the new entry in */
1955 /**************************************************************************
1956 * DPA_DeletePtr [COMCTL32.336]
1958 * Removes a pointer from the pointer array.
1961 * hdpa [I] handle (pointer) to the pointer array
1962 * i [I] index of the pointer that will be deleted
1965 * Success: deleted pointer
1970 DPA_DeletePtr (const HDPA hdpa
, INT i
)
1972 LPVOID
*lpDest
, *lpSrc
, lpTemp
= NULL
;
1975 TRACE("(%p %d)\n", hdpa
, i
);
1977 if ((!hdpa
) || i
< 0 || i
>= hdpa
->nItemCount
)
1980 lpTemp
= hdpa
->ptrs
[i
];
1982 /* do we need to move ?*/
1983 if (i
< hdpa
->nItemCount
- 1) {
1984 lpDest
= hdpa
->ptrs
+ i
;
1986 nSize
= (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
);
1987 TRACE("-- move dest=%p src=%p size=%x\n",
1988 lpDest
, lpSrc
, nSize
);
1989 memmove (lpDest
, lpSrc
, nSize
);
1992 hdpa
->nItemCount
--;
1995 if ((hdpa
->nMaxCount
- hdpa
->nItemCount
) >= hdpa
->nGrow
) {
1996 INT nNewItems
= max(hdpa
->nGrow
* 2, hdpa
->nItemCount
);
1997 nSize
= nNewItems
* sizeof(LPVOID
);
1998 lpDest
= (LPVOID
)HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
2003 hdpa
->nMaxCount
= nNewItems
;
2004 hdpa
->ptrs
= (LPVOID
*)lpDest
;
2011 /**************************************************************************
2012 * DPA_DeleteAllPtrs [COMCTL32.337]
2014 * Removes all pointers and reinitializes the array.
2017 * hdpa [I] handle (pointer) to the pointer array
2025 DPA_DeleteAllPtrs (const HDPA hdpa
)
2027 TRACE("(%p)\n", hdpa
);
2032 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
2035 hdpa
->nItemCount
= 0;
2036 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
2037 hdpa
->ptrs
= (LPVOID
*)HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
2038 hdpa
->nMaxCount
* sizeof(LPVOID
));
2044 /**************************************************************************
2045 * DPA_QuickSort [Internal]
2047 * Ordinary quicksort (used by DPA_Sort).
2050 * lpPtrs [I] pointer to the pointer array
2051 * l [I] index of the "left border" of the partition
2052 * r [I] index of the "right border" of the partition
2053 * pfnCompare [I] pointer to the compare function
2054 * lParam [I] user defined value (3rd parameter in compare function)
2061 DPA_QuickSort (LPVOID
*lpPtrs
, INT l
, INT r
,
2062 PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
2067 TRACE("l=%i r=%i\n", l
, r
);
2069 if (l
==r
) /* one element is always sorted */
2071 if (r
<l
) /* oops, got it in the wrong order */
2073 DPA_QuickSort(lpPtrs
, r
, l
, pfnCompare
, lParam
);
2076 m
= (l
+r
)/2; /* divide by two */
2077 DPA_QuickSort(lpPtrs
, l
, m
, pfnCompare
, lParam
);
2078 DPA_QuickSort(lpPtrs
, m
+1, r
, pfnCompare
, lParam
);
2080 /* join the two sides */
2081 while( (l
<=m
) && (m
<r
) )
2083 if(pfnCompare(lpPtrs
[l
],lpPtrs
[m
+1],lParam
)>0)
2086 memmove(&lpPtrs
[l
+1],&lpPtrs
[l
],(m
-l
+1)*sizeof(lpPtrs
[l
]));
2096 /**************************************************************************
2097 * DPA_Sort [COMCTL32.338]
2099 * Sorts a pointer array using a user defined compare function
2102 * hdpa [I] handle (pointer) to the pointer array
2103 * pfnCompare [I] pointer to the compare function
2104 * lParam [I] user defined value (3rd parameter of compare function)
2112 DPA_Sort (const HDPA hdpa
, PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
2114 if (!hdpa
|| !pfnCompare
)
2117 TRACE("(%p %p 0x%lx)\n", hdpa
, pfnCompare
, lParam
);
2119 if ((hdpa
->nItemCount
> 1) && (hdpa
->ptrs
))
2120 DPA_QuickSort (hdpa
->ptrs
, 0, hdpa
->nItemCount
- 1,
2121 pfnCompare
, lParam
);
2127 /**************************************************************************
2128 * DPA_Search [COMCTL32.339]
2130 * Searches a pointer array for a specified pointer
2133 * hdpa [I] handle (pointer) to the pointer array
2134 * pFind [I] pointer to search for
2135 * nStart [I] start index
2136 * pfnCompare [I] pointer to the compare function
2137 * lParam [I] user defined value (3rd parameter of compare function)
2138 * uOptions [I] search options
2141 * Success: index of the pointer in the array.
2145 * Binary search taken from R.Sedgewick "Algorithms in C"!
2146 * Function is NOT tested!
2147 * If something goes wrong, blame HIM not ME! (Eric Kohl)
2151 DPA_Search (const HDPA hdpa
, LPVOID pFind
, INT nStart
,
2152 PFNDPACOMPARE pfnCompare
, LPARAM lParam
, UINT uOptions
)
2154 if (!hdpa
|| !pfnCompare
|| !pFind
)
2157 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
2158 hdpa
, pFind
, nStart
, pfnCompare
, lParam
, uOptions
);
2160 if (uOptions
& DPAS_SORTED
) {
2161 /* array is sorted --> use binary search */
2165 TRACE("binary search\n");
2167 l
= (nStart
== -1) ? 0 : nStart
;
2168 r
= hdpa
->nItemCount
- 1;
2172 n
= (pfnCompare
)(pFind
, lpPtr
[x
], lParam
);
2178 TRACE("-- ret=%d\n", n
);
2183 if (uOptions
& DPAS_INSERTBEFORE
) {
2185 TRACE("-- ret=%d\n", r
);
2189 if (uOptions
& DPAS_INSERTAFTER
) {
2190 TRACE("-- ret=%d\n", l
);
2195 /* array is not sorted --> use linear search */
2199 TRACE("linear search\n");
2201 nIndex
= (nStart
== -1)? 0 : nStart
;
2203 for (; nIndex
< hdpa
->nItemCount
; nIndex
++) {
2204 if ((pfnCompare
)(pFind
, lpPtr
[nIndex
], lParam
) == 0) {
2205 TRACE("-- ret=%d\n", nIndex
);
2211 TRACE("-- not found: ret=-1\n");
2216 /**************************************************************************
2217 * DPA_CreateEx [COMCTL32.340]
2219 * Creates a dynamic pointer array using the specified size and heap.
2222 * nGrow [I] number of items by which the array grows when it is filled
2223 * hHeap [I] handle to the heap where the array is stored
2226 * Success: handle (pointer) to the pointer array.
2230 * The DPA_ functions can be used to create and manipulate arrays of
2235 DPA_CreateEx (INT nGrow
, HANDLE hHeap
)
2239 TRACE("(%d %p)\n", nGrow
, hHeap
);
2242 hdpa
= (HDPA
)HeapAlloc (hHeap
, HEAP_ZERO_MEMORY
, sizeof(*hdpa
));
2244 hdpa
= Alloc (sizeof(*hdpa
));
2247 hdpa
->nGrow
= max(8, nGrow
);
2248 hdpa
->hHeap
= hHeap
? hHeap
: GetProcessHeap();
2249 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
2250 hdpa
->ptrs
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
2251 hdpa
->nMaxCount
* sizeof(LPVOID
));
2254 TRACE("-- %p\n", hdpa
);
2260 /**************************************************************************
2261 * DPA_Create [COMCTL32.328]
2263 * Creates a dynamic pointer array.
2266 * nGrow [I] number of items by which the array grows when it is filled
2269 * Success: handle (pointer) to the pointer array.
2273 * The DPA_ functions can be used to create and manipulate arrays of
2278 DPA_Create (INT nGrow
)
2280 return DPA_CreateEx( nGrow
, 0 );
2284 /**************************************************************************
2285 * Notification functions
2288 typedef struct tagNOTIFYDATA
2296 } NOTIFYDATA
, *LPNOTIFYDATA
;
2299 /**************************************************************************
2300 * DoNotify [Internal]
2304 DoNotify (LPNOTIFYDATA lpNotify
, UINT uCode
, LPNMHDR lpHdr
)
2307 LPNMHDR lpNmh
= NULL
;
2310 TRACE("(%p %p %d %p 0x%08lx)\n",
2311 lpNotify
->hwndFrom
, lpNotify
->hwndTo
, uCode
, lpHdr
,
2312 lpNotify
->dwParam5
);
2314 if (!lpNotify
->hwndTo
)
2317 if (lpNotify
->hwndFrom
== (HWND
)-1) {
2319 idFrom
= lpHdr
->idFrom
;
2322 if (lpNotify
->hwndFrom
)
2323 idFrom
= GetDlgCtrlID (lpNotify
->hwndFrom
);
2325 lpNmh
= (lpHdr
) ? lpHdr
: &nmhdr
;
2327 lpNmh
->hwndFrom
= lpNotify
->hwndFrom
;
2328 lpNmh
->idFrom
= idFrom
;
2329 lpNmh
->code
= uCode
;
2332 return SendMessageA (lpNotify
->hwndTo
, WM_NOTIFY
, idFrom
, (LPARAM
)lpNmh
);
2336 /**************************************************************************
2337 * SendNotify [COMCTL32.341]
2339 * Sends a WM_NOTIFY message to the specified window.
2342 * hwndTo [I] Window to receive the message
2343 * hwndFrom [I] Window that the message is from (see notes)
2344 * uCode [I] Notification code
2345 * lpHdr [I] The NMHDR and any additional information to send or NULL
2348 * Success: return value from notification
2352 * If hwndFrom is -1 then the identifier of the control sending the
2353 * message is taken from the NMHDR structure.
2354 * If hwndFrom is not -1 then lpHdr can be NULL.
2357 LRESULT WINAPI
SendNotify (HWND hwndTo
, HWND hwndFrom
, UINT uCode
, LPNMHDR lpHdr
)
2361 TRACE("(%p %p %d %p)\n",
2362 hwndTo
, hwndFrom
, uCode
, lpHdr
);
2364 notify
.hwndFrom
= hwndFrom
;
2365 notify
.hwndTo
= hwndTo
;
2366 notify
.dwParam5
= 0;
2367 notify
.dwParam6
= 0;
2369 return DoNotify (¬ify
, uCode
, lpHdr
);
2373 /**************************************************************************
2374 * SendNotifyEx [COMCTL32.342]
2376 * Sends a WM_NOTIFY message to the specified window.
2379 * hwndFrom [I] Window to receive the message
2380 * hwndTo [I] Window that the message is from
2381 * uCode [I] Notification code
2382 * lpHdr [I] The NMHDR and any additional information to send or NULL
2383 * dwParam5 [I] Unknown
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.
2395 LRESULT WINAPI
SendNotifyEx (HWND hwndTo
, HWND hwndFrom
, UINT uCode
,
2396 LPNMHDR lpHdr
, DWORD dwParam5
)
2401 TRACE("(%p %p %d %p 0x%08lx)\n",
2402 hwndFrom
, hwndTo
, uCode
, lpHdr
, dwParam5
);
2404 hwndNotify
= hwndTo
;
2406 if (IsWindow (hwndFrom
)) {
2407 hwndNotify
= GetParent (hwndFrom
);
2413 notify
.hwndFrom
= hwndFrom
;
2414 notify
.hwndTo
= hwndNotify
;
2415 notify
.dwParam5
= dwParam5
;
2416 notify
.dwParam6
= 0;
2418 return DoNotify (¬ify
, uCode
, lpHdr
);
2424 /**************************************************************************
2425 * DPA_EnumCallback [COMCTL32.385]
2427 * Enumerates all items in a dynamic pointer array.
2430 * hdpa [I] handle to the dynamic pointer array
2439 DPA_EnumCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
, LPVOID lParam
)
2443 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
2447 if (hdpa
->nItemCount
<= 0)
2450 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
2451 if ((enumProc
)(hdpa
->ptrs
[i
], lParam
) == 0)
2459 /**************************************************************************
2460 * DPA_DestroyCallback [COMCTL32.386]
2462 * Enumerates all items in a dynamic pointer array and destroys it.
2465 * hdpa [I] handle to the dynamic pointer array
2474 DPA_DestroyCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
, LPVOID lParam
)
2476 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
2478 DPA_EnumCallback (hdpa
, enumProc
, lParam
);
2483 /**************************************************************************
2484 * DSA_EnumCallback [COMCTL32.387]
2486 * Enumerates all items in a dynamic storage array.
2489 * hdsa [I] handle to the dynamic storage array
2498 DSA_EnumCallback (HDSA hdsa
, PFNDSAENUMCALLBACK enumProc
, LPVOID lParam
)
2502 TRACE("(%p %p %p)\n", hdsa
, enumProc
, lParam
);
2506 if (hdsa
->nItemCount
<= 0)
2509 for (i
= 0; i
< hdsa
->nItemCount
; i
++) {
2510 LPVOID lpItem
= DSA_GetItemPtr (hdsa
, i
);
2511 if ((enumProc
)(lpItem
, lParam
) == 0)
2519 /**************************************************************************
2520 * DSA_DestroyCallback [COMCTL32.388]
2522 * Enumerates all items in a dynamic storage array and destroys it.
2525 * hdsa [I] handle to the dynamic storage array
2534 DSA_DestroyCallback (HDSA hdsa
, PFNDSAENUMCALLBACK enumProc
, LPVOID lParam
)
2536 TRACE("(%p %p %p)\n", hdsa
, enumProc
, lParam
);
2538 DSA_EnumCallback (hdsa
, enumProc
, lParam
);