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).
29 * - Add more functions.
30 * - Write some documentation.
33 #include "wine/port.h"
37 #include <stdlib.h> /* atoi */
41 #define NONAMELESSUNION
42 #define NONAMELESSSTRUCT
53 #include "wine/unicode.h"
56 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(commctrl
);
78 typedef struct _STREAMDATA
83 } STREAMDATA
, *PSTREAMDATA
;
85 typedef struct _LOADDATA
89 } LOADDATA
, *LPLOADDATA
;
91 typedef HRESULT (CALLBACK
*DPALOADPROC
)(LPLOADDATA
,IStream
*,LPARAM
);
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
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
200 * No more information available yet!
204 DPA_SaveStream (const HDPA hDpa
, DPALOADPROC loadProc
, IStream
*pStream
, LPARAM lParam
)
207 FIXME ("hDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
208 hDpa
, loadProc
, pStream
, lParam
);
214 /**************************************************************************
215 * DPA_Merge [COMCTL32.11]
218 * hdpa1 [I] handle to a dynamic pointer array
219 * hdpa2 [I] handle to a dynamic pointer array
221 * pfnCompare [I] pointer to sort function
222 * pfnMerge [I] pointer to merge function
223 * lParam [I] application specific value
226 * No more information available yet!
230 DPA_Merge (const HDPA hdpa1
, const HDPA hdpa2
, DWORD dwFlags
,
231 PFNDPACOMPARE pfnCompare
, PFNDPAMERGE pfnMerge
, LPARAM lParam
)
234 LPVOID
*pWork1
, *pWork2
;
238 TRACE("%p %p %08lx %p %p %08lx)\n",
239 hdpa1
, hdpa2
, dwFlags
, pfnCompare
, pfnMerge
, lParam
);
241 if (IsBadWritePtr (hdpa1
, sizeof(*hdpa1
)))
244 if (IsBadWritePtr (hdpa2
, sizeof(*hdpa2
)))
247 if (IsBadCodePtr ((FARPROC
)pfnCompare
))
250 if (IsBadCodePtr ((FARPROC
)pfnMerge
))
253 if (!(dwFlags
& DPAM_NOSORT
)) {
254 TRACE("sorting dpa's!\n");
255 if (hdpa1
->nItemCount
> 0)
256 DPA_Sort (hdpa1
, pfnCompare
, lParam
);
257 TRACE ("dpa 1 sorted!\n");
258 if (hdpa2
->nItemCount
> 0)
259 DPA_Sort (hdpa2
, pfnCompare
, lParam
);
260 TRACE ("dpa 2 sorted!\n");
263 if (hdpa2
->nItemCount
< 1)
266 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
267 hdpa1
->nItemCount
, hdpa2
->nItemCount
);
270 /* working but untrusted implementation */
272 pWork1
= &(hdpa1
->ptrs
[hdpa1
->nItemCount
- 1]);
273 pWork2
= &(hdpa2
->ptrs
[hdpa2
->nItemCount
- 1]);
275 nIndex
= hdpa1
->nItemCount
- 1;
276 nCount
= hdpa2
->nItemCount
- 1;
281 if ((nCount
>= 0) && (dwFlags
& DPAM_INSERT
)) {
282 /* Now insert the remaining new items into DPA 1 */
283 TRACE("%d items to be inserted at start of DPA 1\n",
285 for (i
=nCount
; i
>=0; i
--) {
288 ptr
= (pfnMerge
)(3, *pWork2
, NULL
, lParam
);
291 DPA_InsertPtr (hdpa1
, 0, ptr
);
297 nResult
= (pfnCompare
)(*pWork1
, *pWork2
, lParam
);
298 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
299 nResult
, nIndex
, nCount
);
305 ptr
= (pfnMerge
)(1, *pWork1
, *pWork2
, lParam
);
315 else if (nResult
> 0)
317 /* item in DPA 1 missing from DPA 2 */
318 if (dwFlags
& DPAM_DELETE
)
320 /* Now delete the extra item in DPA1 */
323 ptr
= DPA_DeletePtr (hdpa1
, hdpa1
->nItemCount
- 1);
325 (pfnMerge
)(2, ptr
, NULL
, lParam
);
332 /* new item in DPA 2 */
333 if (dwFlags
& DPAM_INSERT
)
335 /* Now insert the new item in DPA 1 */
338 ptr
= (pfnMerge
)(3, *pWork2
, NULL
, lParam
);
341 DPA_InsertPtr (hdpa1
, nIndex
+1, ptr
);
354 /**************************************************************************
355 * Alloc [COMCTL32.71]
357 * Allocates memory block from the dll's private heap
360 * dwSize [I] size of the allocated memory block
363 * Success: pointer to allocated memory block
367 LPVOID WINAPI
Alloc (DWORD dwSize
)
369 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
373 /**************************************************************************
374 * ReAlloc [COMCTL32.72]
376 * Changes the size of an allocated memory block or allocates a memory
377 * block using the dll's private heap.
380 * lpSrc [I] pointer to memory block which will be resized
381 * dwSize [I] new size of the memory block.
384 * Success: pointer to the resized memory block
388 * If lpSrc is a NULL-pointer, then ReAlloc allocates a memory
392 LPVOID WINAPI
ReAlloc (LPVOID lpSrc
, DWORD dwSize
)
395 return LocalReAlloc( lpSrc
, dwSize
, LMEM_ZEROINIT
);
397 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
401 /**************************************************************************
404 * Frees an allocated memory block from the dll's private heap.
407 * lpMem [I] pointer to memory block which will be freed
414 BOOL WINAPI
Free (LPVOID lpMem
)
416 return !LocalFree( lpMem
);
420 /**************************************************************************
421 * GetSize [COMCTL32.74]
423 * Retrieves the size of the specified memory block from the dll's
427 * lpMem [I] pointer to an allocated memory block
430 * Success: size of the specified memory block
434 DWORD WINAPI
GetSize (LPVOID lpMem
)
436 return LocalSize( lpMem
);
440 /**************************************************************************
441 * The MRU-API is a set of functions to manipulate MRU(Most Recently Used)
444 * Stored in the reg. as a set of values under a single key. Each item in the
445 * list has a value name that is a single char. 'a' - 'z', '{', '|' or '}'.
446 * The order of the list is stored with value name 'MRUList' which is a string
447 * containing the value names (i.e. 'a', 'b', etc.) in the relevant order.
450 typedef struct tagCREATEMRULISTA
452 DWORD cbSize
; /* size of struct */
453 DWORD nMaxItems
; /* max no. of items in list */
454 DWORD dwFlags
; /* see below */
455 HKEY hKey
; /* root reg. key under which list is saved */
456 LPCSTR lpszSubKey
; /* reg. subkey */
457 PROC lpfnCompare
; /* item compare proc */
458 } CREATEMRULISTA
, *LPCREATEMRULISTA
;
460 typedef struct tagCREATEMRULISTW
462 DWORD cbSize
; /* size of struct */
463 DWORD nMaxItems
; /* max no. of items in list */
464 DWORD dwFlags
; /* see below */
465 HKEY hKey
; /* root reg. key under which list is saved */
466 LPCWSTR lpszSubKey
; /* reg. subkey */
467 PROC lpfnCompare
; /* item compare proc */
468 } CREATEMRULISTW
, *LPCREATEMRULISTW
;
471 #define MRUF_STRING_LIST 0 /* list will contain strings */
472 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
473 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
475 /* If list is a string list lpfnCompare has the following prototype
476 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
477 * for binary lists the prototype is
478 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
479 * where cbData is the no. of bytes to compare.
480 * Need to check what return value means identical - 0?
483 typedef struct tagWINEMRUITEM
485 DWORD size
; /* size of data stored */
486 DWORD itemFlag
; /* flags */
488 } WINEMRUITEM
, *LPWINEMRUITEM
;
491 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
493 typedef struct tagWINEMRULIST
495 CREATEMRULISTW extview
; /* original create information */
496 BOOL isUnicode
; /* is compare fn Unicode */
497 DWORD wineFlags
; /* internal flags */
498 DWORD cursize
; /* current size of realMRU */
499 LPSTR realMRU
; /* pointer to string of index names */
500 LPWINEMRUITEM
*array
; /* array of pointers to data */
501 /* in 'a' to 'z' order */
502 } WINEMRULIST
, *LPWINEMRULIST
;
505 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
507 /**************************************************************************
508 * MRU_SaveChanged - Localize MRU saving code
511 VOID
MRU_SaveChanged( LPWINEMRULIST mp
)
517 WCHAR emptyW
[] = {'\0'};
519 /* or should we do the following instead of RegOpenKeyEx:
522 /* open the sub key */
523 if ((err
= RegOpenKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
524 0, KEY_WRITE
, &newkey
))) {
525 /* not present - what to do ??? */
526 ERR("Can not open key, error=%d, attempting to create\n",
528 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
531 REG_OPTION_NON_VOLATILE
,
532 KEY_READ
| KEY_WRITE
,
536 ERR("failed to create key /%s/, err=%d\n",
537 debugstr_w(mp
->extview
.lpszSubKey
), err
);
541 if (mp
->wineFlags
& WMRUF_CHANGED
) {
542 mp
->wineFlags
&= ~WMRUF_CHANGED
;
543 err
= RegSetValueExA(newkey
, "MRUList", 0, REG_SZ
,
544 mp
->realMRU
, strlen(mp
->realMRU
) + 1);
546 ERR("error saving MRUList, err=%d\n", err
);
548 TRACE("saving MRUList=/%s/\n", mp
->realMRU
);
551 for(i
=0; i
<mp
->cursize
; i
++) {
552 witem
= mp
->array
[i
];
553 if (witem
->itemFlag
& WMRUIF_CHANGED
) {
554 witem
->itemFlag
&= ~WMRUIF_CHANGED
;
555 realname
[0] = 'a' + i
;
556 err
= RegSetValueExW(newkey
, realname
, 0,
557 (mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) ?
559 &witem
->datastart
, witem
->size
);
561 ERR("error saving /%s/, err=%d\n", debugstr_w(realname
), err
);
563 TRACE("saving value for name /%s/ size=%ld\n",
564 debugstr_w(realname
), witem
->size
);
567 RegCloseKey( newkey
);
570 /**************************************************************************
571 * FreeMRUList [COMCTL32.152]
574 * hMRUList [I] Handle to list.
578 FreeMRUList (HANDLE hMRUList
)
580 LPWINEMRULIST mp
= (LPWINEMRULIST
)hMRUList
;
584 if (mp
->wineFlags
& WMRUF_CHANGED
) {
585 /* need to open key and then save the info */
586 MRU_SaveChanged( mp
);
589 for(i
=0; i
<mp
->extview
.nMaxItems
; i
++) {
595 Free((LPWSTR
)mp
->extview
.lpszSubKey
);
600 /**************************************************************************
601 * FindMRUData [COMCTL32.169]
603 * Searches binary list for item that matches lpData of length cbData.
604 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
605 * corresponding to item's reg. name will be stored in it ('a' -> 0).
608 * hList [I] list handle
609 * lpData [I] data to find
610 * cbData [I] length of data
611 * lpRegNum [O] position in registry (maybe NULL)
614 * Position in list 0 -> MRU. -1 if item not found.
617 FindMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
, LPINT lpRegNum
)
619 LPWINEMRULIST mp
= (LPWINEMRULIST
)hList
;
623 if (!mp
->extview
.lpfnCompare
) {
624 ERR("MRU list not properly created. No compare procedure.\n");
628 if(!(mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) && !mp
->isUnicode
) {
629 DWORD len
= WideCharToMultiByte(CP_ACP
, 0, lpData
, -1,
630 NULL
, 0, NULL
, NULL
);
632 WideCharToMultiByte(CP_ACP
, 0, lpData
, -1, dataA
, len
, NULL
, NULL
);
635 for(i
=0; i
<mp
->cursize
; i
++) {
636 if (mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) {
637 if (!mp
->extview
.lpfnCompare(lpData
, &mp
->array
[i
]->datastart
,
643 if (!mp
->extview
.lpfnCompare(lpData
, &mp
->array
[i
]->datastart
))
646 DWORD len
= WideCharToMultiByte(CP_ACP
, 0,
647 (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
648 NULL
, 0, NULL
, NULL
);
649 LPSTR itemA
= Alloc(len
);
651 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
652 itemA
, len
, NULL
, NULL
);
654 cmp
= mp
->extview
.lpfnCompare(dataA
, itemA
);
667 if (lpRegNum
&& (ret
!= -1))
670 TRACE("(%p, %p, %ld, %p) returning %d\n",
671 hList
, lpData
, cbData
, lpRegNum
, ret
);
677 /**************************************************************************
678 * AddMRUData [COMCTL32.167]
680 * Add item to MRU binary list. If item already exists in list then it is
681 * simply moved up to the top of the list and not added again. If list is
682 * full then the least recently used item is removed to make room.
685 * hList [I] Handle to list.
686 * lpData [I] ptr to data to add.
687 * cbData [I] no. of bytes of data.
690 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
694 AddMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
)
696 LPWINEMRULIST mp
= (LPWINEMRULIST
)hList
;
700 if ((replace
= FindMRUData (hList
, lpData
, cbData
, NULL
)) < 0) {
701 /* either add a new entry or replace oldest */
702 if (mp
->cursize
< mp
->extview
.nMaxItems
) {
703 /* Add in a new item */
704 replace
= mp
->cursize
;
708 /* get the oldest entry and replace data */
709 replace
= mp
->realMRU
[mp
->cursize
- 1] - 'a';
710 Free(mp
->array
[replace
]);
714 /* free up the old data */
715 Free(mp
->array
[replace
]);
718 /* Allocate space for new item and move in the data */
719 mp
->array
[replace
] = witem
= Alloc(cbData
+ sizeof(WINEMRUITEM
));
720 witem
->itemFlag
|= WMRUIF_CHANGED
;
721 witem
->size
= cbData
;
722 memcpy( &witem
->datastart
, lpData
, cbData
);
724 /* now rotate MRU list */
725 mp
->wineFlags
|= WMRUF_CHANGED
;
726 for(i
=mp
->cursize
-1; i
>=1; i
--) {
727 mp
->realMRU
[i
] = mp
->realMRU
[i
-1];
729 mp
->realMRU
[0] = replace
+ 'a';
730 TRACE("(%p, %p, %ld) adding data, /%c/ now most current\n",
731 hList
, lpData
, cbData
, replace
+'a');
734 if (!(mp
->extview
.dwFlags
& MRUF_DELAYED_SAVE
)) {
735 /* save changed stuff right now */
736 MRU_SaveChanged( mp
);
742 /**************************************************************************
743 * AddMRUStringW [COMCTL32.401]
745 * Add item to MRU string list. If item already exists in list them it is
746 * simply moved up to the top of the list and not added again. If list is
747 * full then the least recently used item is removed to make room.
750 * hList [I] Handle to list.
751 * lpszString [I] ptr to string to add.
754 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
758 AddMRUStringW(HANDLE hList
, LPCWSTR lpszString
)
760 FIXME("(%p, %s) empty stub!\n", hList
, debugstr_w(lpszString
));
765 /**************************************************************************
766 * AddMRUStringA [COMCTL32.153]
769 AddMRUStringA(HANDLE hList
, LPCSTR lpszString
)
771 FIXME("(%p, %s) empty stub!\n", hList
, debugstr_a(lpszString
));
776 /**************************************************************************
777 * DelMRUString [COMCTL32.156]
779 * Removes item from either string or binary list (despite its name)
782 * hList [I] list handle
783 * nItemPos [I] item position to remove 0 -> MRU
786 * TRUE if successful, FALSE if nItemPos is out of range.
789 DelMRUString(HANDLE hList
, INT nItemPos
)
791 FIXME("(%p, %d): stub\n", hList
, nItemPos
);
795 /**************************************************************************
796 * FindMRUStringW [COMCTL32.402]
799 FindMRUStringW (HANDLE hList
, LPCWSTR lpszString
, LPINT lpRegNum
)
805 /**************************************************************************
806 * FindMRUStringA [COMCTL32.155]
808 * Searches string list for item that matches lpszString.
809 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
810 * corresponding to item's reg. name will be stored in it ('a' -> 0).
813 * hList [I] list handle
814 * lpszString [I] string to find
815 * lpRegNum [O] position in registry (maybe NULL)
818 * Position in list 0 -> MRU. -1 if item not found.
821 FindMRUStringA (HANDLE hList
, LPCSTR lpszString
, LPINT lpRegNum
)
823 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, NULL
, 0);
824 LPWSTR stringW
= Alloc(len
* sizeof(WCHAR
));
827 MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, stringW
, len
);
828 ret
= FindMRUData(hList
, stringW
, len
* sizeof(WCHAR
), lpRegNum
);
833 /*************************************************************************
834 * CreateMRUListLazy_common
836 HANDLE
CreateMRUListLazy_common(LPWINEMRULIST mp
)
840 DWORD datasize
, dwdisp
;
844 WCHAR emptyW
[] = {'\0'};
846 /* get space to save indices that will turn into names
847 * but in order of most to least recently used
849 mp
->realMRU
= Alloc(mp
->extview
.nMaxItems
+ 2);
851 /* get space to save pointers to actual data in order of
852 * 'a' to 'z' (0 to n).
854 mp
->array
= Alloc(mp
->extview
.nMaxItems
* sizeof(LPVOID
));
856 /* open the sub key */
857 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
860 REG_OPTION_NON_VOLATILE
,
861 KEY_READ
| KEY_WRITE
,
865 /* error - what to do ??? */
866 ERR("(%lu %lu %lx %lx \"%s\" %p): Can not open key, error=%d\n",
867 mp
->extview
.cbSize
, mp
->extview
.nMaxItems
, mp
->extview
.dwFlags
,
868 (DWORD
)mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
869 mp
->extview
.lpfnCompare
, err
);
873 /* get values from key 'MRUList' */
875 datasize
= mp
->extview
.nMaxItems
+ 1;
876 if((err
=RegQueryValueExA( newkey
, "MRUList", 0, &type
, mp
->realMRU
,
878 /* not present - set size to 1 (will become 0 later) */
883 TRACE("MRU list = %s\n", mp
->realMRU
);
885 mp
->cursize
= datasize
- 1;
886 /* datasize now has number of items in the MRUList */
888 /* get actual values for each entry */
890 for(i
=0; i
<mp
->cursize
; i
++) {
891 realname
[0] = 'a' + i
;
892 if(RegQueryValueExW( newkey
, realname
, 0, &type
, 0, &datasize
)) {
893 /* not present - what to do ??? */
894 ERR("Key %s not found 1\n", debugstr_w(realname
));
896 mp
->array
[i
] = witem
= Alloc(datasize
+ sizeof(WINEMRUITEM
));
897 witem
->size
= datasize
;
898 if(RegQueryValueExW( newkey
, realname
, 0, &type
,
899 &witem
->datastart
, &datasize
)) {
900 /* not present - what to do ??? */
901 ERR("Key %s not found 2\n", debugstr_w(realname
));
904 RegCloseKey( newkey
);
909 TRACE("(%lu %lu %lx %lx \"%s\" %p): Current Size = %ld\n",
910 mp
->extview
.cbSize
, mp
->extview
.nMaxItems
, mp
->extview
.dwFlags
,
911 (DWORD
)mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
912 mp
->extview
.lpfnCompare
, mp
->cursize
);
916 /**************************************************************************
917 * CreateMRUListLazyW [COMCTL32.404]
920 CreateMRUListLazyW (LPCREATEMRULISTW lpcml
, DWORD dwParam2
, DWORD dwParam3
, DWORD dwParam4
)
927 if (lpcml
->cbSize
< sizeof(CREATEMRULISTW
))
930 mp
= Alloc(sizeof(WINEMRULIST
));
931 memcpy(&mp
->extview
, lpcml
, sizeof(CREATEMRULISTW
));
932 mp
->extview
.lpszSubKey
= Alloc((strlenW(lpcml
->lpszSubKey
) + 1) * sizeof(WCHAR
));
933 strcpyW((LPWSTR
)mp
->extview
.lpszSubKey
, lpcml
->lpszSubKey
);
934 mp
->isUnicode
= TRUE
;
936 return CreateMRUListLazy_common(mp
);
939 /**************************************************************************
940 * CreateMRUListLazyA [COMCTL32.157]
943 CreateMRUListLazyA (LPCREATEMRULISTA lpcml
, DWORD dwParam2
, DWORD dwParam3
, DWORD dwParam4
)
951 if (lpcml
->cbSize
< sizeof(CREATEMRULISTA
))
954 mp
= Alloc(sizeof(WINEMRULIST
));
955 memcpy(&mp
->extview
, lpcml
, sizeof(CREATEMRULISTW
));
956 len
= MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1, NULL
, 0);
957 mp
->extview
.lpszSubKey
= Alloc(len
* sizeof(WCHAR
));
958 MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1,
959 (LPWSTR
)mp
->extview
.lpszSubKey
, len
);
960 mp
->isUnicode
= FALSE
;
961 return CreateMRUListLazy_common(mp
);
964 /**************************************************************************
965 * CreateMRUListW [COMCTL32.400]
968 * lpcml [I] ptr to CREATEMRULIST structure.
971 * Handle to MRU list.
974 CreateMRUListW (LPCREATEMRULISTW lpcml
)
976 return CreateMRUListLazyW(lpcml
, 0, 0, 0);
979 /**************************************************************************
980 * CreateMRUListA [COMCTL32.151]
983 CreateMRUListA (LPCREATEMRULISTA lpcml
)
985 return CreateMRUListLazyA (lpcml
, 0, 0, 0);
989 /**************************************************************************
990 * EnumMRUListW [COMCTL32.403]
992 * Enumerate item in a list
995 * hList [I] list handle
996 * nItemPos [I] item position to enumerate
997 * lpBuffer [O] buffer to receive item
998 * nBufferSize [I] size of buffer
1001 * For binary lists specifies how many bytes were copied to buffer, for
1002 * string lists specifies full length of string. Enumerating past the end
1003 * of list returns -1.
1004 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
1007 INT WINAPI
EnumMRUListW(HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
1010 LPWINEMRULIST mp
= (LPWINEMRULIST
) hList
;
1011 LPWINEMRUITEM witem
;
1012 INT desired
, datasize
;
1014 if (nItemPos
>= mp
->cursize
) return -1;
1015 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
1016 desired
= mp
->realMRU
[nItemPos
];
1018 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
1019 witem
= mp
->array
[desired
];
1020 datasize
= min( witem
->size
, nBufferSize
);
1021 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
1022 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1023 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
1027 /**************************************************************************
1028 * EnumMRUListA [COMCTL32.154]
1031 INT WINAPI
EnumMRUListA(HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
1034 LPWINEMRULIST mp
= (LPWINEMRULIST
) hList
;
1035 LPWINEMRUITEM witem
;
1036 INT desired
, datasize
;
1039 if (nItemPos
>= mp
->cursize
) return -1;
1040 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
1041 desired
= mp
->realMRU
[nItemPos
];
1043 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
1044 witem
= mp
->array
[desired
];
1045 if(mp
->extview
.dwFlags
& MRUF_BINARY_LIST
) {
1046 datasize
= min( witem
->size
, nBufferSize
);
1047 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
1049 lenA
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
1050 NULL
, 0, NULL
, NULL
);
1051 datasize
= min( witem
->size
, nBufferSize
);
1052 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
1053 lpBuffer
, datasize
, NULL
, NULL
);
1055 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
1056 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
1061 /**************************************************************************
1062 * Str_GetPtrA [COMCTL32.233]
1073 Str_GetPtrA (LPCSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
1077 TRACE("(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
1079 if (!lpDest
&& lpSrc
)
1080 return strlen (lpSrc
);
1085 if (lpSrc
== NULL
) {
1090 len
= strlen (lpSrc
);
1094 RtlMoveMemory (lpDest
, lpSrc
, len
);
1101 /**************************************************************************
1102 * Str_SetPtrA [COMCTL32.234]
1112 Str_SetPtrA (LPSTR
*lppDest
, LPCSTR lpSrc
)
1114 TRACE("(%p %p)\n", lppDest
, lpSrc
);
1117 LPSTR ptr
= ReAlloc (*lppDest
, strlen (lpSrc
) + 1);
1120 strcpy (ptr
, lpSrc
);
1134 /**************************************************************************
1135 * Str_GetPtrW [COMCTL32.235]
1146 Str_GetPtrW (LPCWSTR lpSrc
, LPWSTR lpDest
, INT nMaxLen
)
1150 TRACE("(%p %p %d)\n", lpSrc
, lpDest
, nMaxLen
);
1152 if (!lpDest
&& lpSrc
)
1153 return strlenW (lpSrc
);
1158 if (lpSrc
== NULL
) {
1163 len
= strlenW (lpSrc
);
1167 RtlMoveMemory (lpDest
, lpSrc
, len
*sizeof(WCHAR
));
1168 lpDest
[len
] = L
'\0';
1174 /**************************************************************************
1175 * Str_SetPtrW [COMCTL32.236]
1185 Str_SetPtrW (LPWSTR
*lppDest
, LPCWSTR lpSrc
)
1187 TRACE("(%p %p)\n", lppDest
, lpSrc
);
1190 INT len
= strlenW (lpSrc
) + 1;
1191 LPWSTR ptr
= ReAlloc (*lppDest
, len
* sizeof(WCHAR
));
1194 strcpyW (ptr
, lpSrc
);
1208 /**************************************************************************
1209 * Str_GetPtrWtoA [internal]
1211 * Converts a unicode string into a multi byte string
1214 * lpSrc [I] Pointer to the unicode source string
1215 * lpDest [O] Pointer to caller supplied storage for the multi byte string
1216 * nMaxLen [I] Size, in bytes, of the destination buffer
1219 * Length, in bytes, of the converted string.
1223 Str_GetPtrWtoA (LPCWSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
1227 TRACE("(%s %p %d)\n", debugstr_w(lpSrc
), lpDest
, nMaxLen
);
1229 if (!lpDest
&& lpSrc
)
1230 return WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
1235 if (lpSrc
== NULL
) {
1240 len
= WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
1244 WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, lpDest
, len
, NULL
, NULL
);
1251 /**************************************************************************
1252 * Str_SetPtrAtoW [internal]
1254 * Converts a multi byte string to a unicode string.
1255 * If the pointer to the destination buffer is NULL a buffer is allocated.
1256 * If the destination buffer is too small to keep the converted multi byte
1257 * string the destination buffer is reallocated. If the source pointer is
1258 * NULL, the destination buffer is freed.
1261 * lppDest [I/O] pointer to a pointer to the destination buffer
1262 * lpSrc [I] pointer to a multi byte string
1265 * TRUE: conversion successful
1270 Str_SetPtrAtoW (LPWSTR
*lppDest
, LPCSTR lpSrc
)
1272 TRACE("(%p %s)\n", lppDest
, lpSrc
);
1275 INT len
= MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,NULL
,0);
1276 LPWSTR ptr
= ReAlloc (*lppDest
, len
*sizeof(WCHAR
));
1280 MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,ptr
,len
);
1294 /**************************************************************************
1295 * The DSA-API is a set of functions to create and manipulate arrays of
1296 * fixed-size memory blocks. These arrays can store any kind of data
1297 * (strings, icons...).
1300 /**************************************************************************
1301 * DSA_Create [COMCTL32.320] Creates a dynamic storage array
1304 * nSize [I] size of the array elements
1305 * nGrow [I] number of elements by which the array grows when it is filled
1308 * Success: pointer to an array control structure. Use this like a handle.
1313 DSA_Create (INT nSize
, INT nGrow
)
1317 TRACE("(size=%d grow=%d)\n", nSize
, nGrow
);
1319 hdsa
= Alloc (sizeof(*hdsa
));
1322 hdsa
->nItemCount
= 0;
1324 hdsa
->nMaxCount
= 0;
1325 hdsa
->nItemSize
= nSize
;
1326 hdsa
->nGrow
= max(1, nGrow
);
1333 /**************************************************************************
1334 * DSA_Destroy [COMCTL32.321] Destroys a dynamic storage array
1337 * hdsa [I] pointer to the array control structure
1345 DSA_Destroy (const HDSA hdsa
)
1347 TRACE("(%p)\n", hdsa
);
1352 if (hdsa
->pData
&& (!Free (hdsa
->pData
)))
1359 /**************************************************************************
1360 * DSA_GetItem [COMCTL32.322]
1363 * hdsa [I] pointer to the array control structure
1364 * nIndex [I] number of the Item to get
1365 * pDest [O] destination buffer. Has to be >= dwElementSize.
1373 DSA_GetItem (const HDSA hdsa
, INT nIndex
, LPVOID pDest
)
1377 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pDest
);
1381 if ((nIndex
< 0) || (nIndex
>= hdsa
->nItemCount
))
1384 pSrc
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1385 memmove (pDest
, pSrc
, hdsa
->nItemSize
);
1391 /**************************************************************************
1392 * DSA_GetItemPtr [COMCTL32.323]
1394 * Retrieves a pointer to the specified item.
1397 * hdsa [I] pointer to the array control structure
1398 * nIndex [I] index of the desired item
1401 * Success: pointer to an item
1406 DSA_GetItemPtr (const HDSA hdsa
, INT nIndex
)
1410 TRACE("(%p %d)\n", hdsa
, nIndex
);
1414 if ((nIndex
< 0) || (nIndex
>= hdsa
->nItemCount
))
1417 pSrc
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1419 TRACE("-- ret=%p\n", pSrc
);
1425 /**************************************************************************
1426 * DSA_SetItem [COMCTL32.325]
1428 * Sets the contents of an item in the array.
1431 * hdsa [I] pointer to the array control structure
1432 * nIndex [I] index for the item
1433 * pSrc [I] pointer to the new item data
1441 DSA_SetItem (const HDSA hdsa
, INT nIndex
, LPVOID pSrc
)
1443 INT nSize
, nNewItems
;
1444 LPVOID pDest
, lpTemp
;
1446 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pSrc
);
1448 if ((!hdsa
) || nIndex
< 0)
1451 if (hdsa
->nItemCount
<= nIndex
) {
1452 /* within the old array */
1453 if (hdsa
->nMaxCount
> nIndex
) {
1454 /* within the allocated space, set a new boundary */
1455 hdsa
->nItemCount
= nIndex
+ 1;
1458 /* resize the block of memory */
1460 hdsa
->nGrow
* ((INT
)(((nIndex
+ 1) - 1) / hdsa
->nGrow
) + 1);
1461 nSize
= hdsa
->nItemSize
* nNewItems
;
1463 lpTemp
= ReAlloc (hdsa
->pData
, nSize
);
1467 hdsa
->nMaxCount
= nNewItems
;
1468 hdsa
->nItemCount
= nIndex
+ 1;
1469 hdsa
->pData
= lpTemp
;
1473 /* put the new entry in */
1474 pDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1475 TRACE("-- move dest=%p src=%p size=%d\n",
1476 pDest
, pSrc
, hdsa
->nItemSize
);
1477 memmove (pDest
, pSrc
, hdsa
->nItemSize
);
1483 /**************************************************************************
1484 * DSA_InsertItem [COMCTL32.324]
1487 * hdsa [I] pointer to the array control structure
1488 * nIndex [I] index for the new item
1489 * pSrc [I] pointer to the element
1492 * Success: position of the new item
1497 DSA_InsertItem (const HDSA hdsa
, INT nIndex
, LPVOID pSrc
)
1499 INT nNewItems
, nSize
;
1500 LPVOID lpTemp
, lpDest
;
1502 TRACE("(%p %d %p)\n", hdsa
, nIndex
, pSrc
);
1504 if ((!hdsa
) || nIndex
< 0)
1507 /* when nIndex >= nItemCount then append */
1508 if (nIndex
>= hdsa
->nItemCount
)
1509 nIndex
= hdsa
->nItemCount
;
1511 /* do we need to resize ? */
1512 if (hdsa
->nItemCount
>= hdsa
->nMaxCount
) {
1513 nNewItems
= hdsa
->nMaxCount
+ hdsa
->nGrow
;
1514 nSize
= hdsa
->nItemSize
* nNewItems
;
1516 lpTemp
= ReAlloc (hdsa
->pData
, nSize
);
1520 hdsa
->nMaxCount
= nNewItems
;
1521 hdsa
->pData
= lpTemp
;
1524 /* do we need to move elements ? */
1525 if (nIndex
< hdsa
->nItemCount
) {
1526 lpTemp
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1527 lpDest
= (char *) lpTemp
+ hdsa
->nItemSize
;
1528 nSize
= (hdsa
->nItemCount
- nIndex
) * hdsa
->nItemSize
;
1529 TRACE("-- move dest=%p src=%p size=%d\n",
1530 lpDest
, lpTemp
, nSize
);
1531 memmove (lpDest
, lpTemp
, nSize
);
1534 /* ok, we can put the new Item in */
1536 lpDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1537 TRACE("-- move dest=%p src=%p size=%d\n",
1538 lpDest
, pSrc
, hdsa
->nItemSize
);
1539 memmove (lpDest
, pSrc
, hdsa
->nItemSize
);
1545 /**************************************************************************
1546 * DSA_DeleteItem [COMCTL32.326]
1549 * hdsa [I] pointer to the array control structure
1550 * nIndex [I] index for the element to delete
1553 * Success: number of the deleted element
1558 DSA_DeleteItem (const HDSA hdsa
, INT nIndex
)
1560 LPVOID lpDest
,lpSrc
;
1563 TRACE("(%p %d)\n", hdsa
, nIndex
);
1567 if (nIndex
< 0 || nIndex
>= hdsa
->nItemCount
)
1570 /* do we need to move ? */
1571 if (nIndex
< hdsa
->nItemCount
- 1) {
1572 lpDest
= (char *) hdsa
->pData
+ (hdsa
->nItemSize
* nIndex
);
1573 lpSrc
= (char *) lpDest
+ hdsa
->nItemSize
;
1574 nSize
= hdsa
->nItemSize
* (hdsa
->nItemCount
- nIndex
- 1);
1575 TRACE("-- move dest=%p src=%p size=%d\n",
1576 lpDest
, lpSrc
, nSize
);
1577 memmove (lpDest
, lpSrc
, nSize
);
1583 if ((hdsa
->nMaxCount
- hdsa
->nItemCount
) >= hdsa
->nGrow
) {
1584 nSize
= hdsa
->nItemSize
* hdsa
->nItemCount
;
1586 lpDest
= ReAlloc (hdsa
->pData
, nSize
);
1590 hdsa
->nMaxCount
= hdsa
->nItemCount
;
1591 hdsa
->pData
= lpDest
;
1598 /**************************************************************************
1599 * DSA_DeleteAllItems [COMCTL32.327]
1601 * Removes all items and reinitializes the array.
1604 * hdsa [I] pointer to the array control structure
1612 DSA_DeleteAllItems (const HDSA hdsa
)
1614 TRACE("(%p)\n", hdsa
);
1618 if (hdsa
->pData
&& (!Free (hdsa
->pData
)))
1621 hdsa
->nItemCount
= 0;
1623 hdsa
->nMaxCount
= 0;
1629 /**************************************************************************
1630 * The DPA-API is a set of functions to create and manipulate arrays of
1634 /**************************************************************************
1635 * DPA_Destroy [COMCTL32.329] Destroys a dynamic pointer array
1638 * hdpa [I] handle (pointer) to the pointer array
1646 DPA_Destroy (const HDPA hdpa
)
1648 TRACE("(%p)\n", hdpa
);
1653 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
1656 return HeapFree (hdpa
->hHeap
, 0, hdpa
);
1660 /**************************************************************************
1661 * DPA_Grow [COMCTL32.330]
1663 * Sets the growth amount.
1666 * hdpa [I] handle (pointer) to the existing (source) pointer array
1667 * nGrow [I] number of items by which the array grows when it's too small
1675 DPA_Grow (const HDPA hdpa
, INT nGrow
)
1677 TRACE("(%p %d)\n", hdpa
, nGrow
);
1682 hdpa
->nGrow
= max(8, nGrow
);
1688 /**************************************************************************
1689 * DPA_Clone [COMCTL32.331]
1691 * Copies a pointer array to an other one or creates a copy
1694 * hdpa [I] handle (pointer) to the existing (source) pointer array
1695 * hdpaNew [O] handle (pointer) to the destination pointer array
1698 * Success: pointer to the destination pointer array.
1702 * - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer
1703 * array will be created and it's handle (pointer) is returned.
1704 * - If 'hdpa' is a NULL-Pointer, the original implementation crashes,
1705 * this implementation just returns NULL.
1709 DPA_Clone (const HDPA hdpa
, const HDPA hdpaNew
)
1711 INT nNewItems
, nSize
;
1717 TRACE("(%p %p)\n", hdpa
, hdpaNew
);
1720 /* create a new DPA */
1721 hdpaTemp
= (HDPA
)HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
1723 hdpaTemp
->hHeap
= hdpa
->hHeap
;
1724 hdpaTemp
->nGrow
= hdpa
->nGrow
;
1729 if (hdpaTemp
->ptrs
) {
1730 /* remove old pointer array */
1731 HeapFree (hdpaTemp
->hHeap
, 0, hdpaTemp
->ptrs
);
1732 hdpaTemp
->ptrs
= NULL
;
1733 hdpaTemp
->nItemCount
= 0;
1734 hdpaTemp
->nMaxCount
= 0;
1737 /* create a new pointer array */
1738 nNewItems
= hdpaTemp
->nGrow
*
1739 ((INT
)((hdpa
->nItemCount
- 1) / hdpaTemp
->nGrow
) + 1);
1740 nSize
= nNewItems
* sizeof(LPVOID
);
1742 (LPVOID
*)HeapAlloc (hdpaTemp
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
1743 hdpaTemp
->nMaxCount
= nNewItems
;
1745 /* clone the pointer array */
1746 hdpaTemp
->nItemCount
= hdpa
->nItemCount
;
1747 memmove (hdpaTemp
->ptrs
, hdpa
->ptrs
,
1748 hdpaTemp
->nItemCount
* sizeof(LPVOID
));
1754 /**************************************************************************
1755 * DPA_GetPtr [COMCTL32.332]
1757 * Retrieves a pointer from a dynamic pointer array
1760 * hdpa [I] handle (pointer) to the pointer array
1761 * nIndex [I] array index of the desired pointer
1769 DPA_GetPtr (const HDPA hdpa
, INT nIndex
)
1771 TRACE("(%p %d)\n", hdpa
, nIndex
);
1776 WARN("no pointer array.\n");
1779 if ((nIndex
< 0) || (nIndex
>= hdpa
->nItemCount
)) {
1780 WARN("not enough pointers in array (%d vs %d).\n",nIndex
,hdpa
->nItemCount
);
1784 TRACE("-- %p\n", hdpa
->ptrs
[nIndex
]);
1786 return hdpa
->ptrs
[nIndex
];
1790 /**************************************************************************
1791 * DPA_GetPtrIndex [COMCTL32.333]
1793 * Retrieves the index of the specified pointer
1796 * hdpa [I] handle (pointer) to the pointer array
1800 * Success: index of the specified pointer
1805 DPA_GetPtrIndex (const HDPA hdpa
, LPVOID p
)
1809 if (!hdpa
|| !hdpa
->ptrs
)
1812 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
1813 if (hdpa
->ptrs
[i
] == p
)
1821 /**************************************************************************
1822 * DPA_InsertPtr [COMCTL32.334]
1824 * Inserts a pointer into a dynamic pointer array
1827 * hdpa [I] handle (pointer) to the array
1829 * p [I] pointer to insert
1832 * Success: index of the inserted pointer
1837 DPA_InsertPtr (const HDPA hdpa
, INT i
, LPVOID p
)
1839 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
1841 if (!hdpa
|| i
< 0) return -1;
1844 i
= hdpa
->nItemCount
;
1846 if (i
>= hdpa
->nItemCount
)
1847 return DPA_SetPtr(hdpa
, i
, p
) ? i
: -1;
1849 /* create empty spot at the end */
1850 if (!DPA_SetPtr(hdpa
, hdpa
->nItemCount
, 0)) return -1;
1851 memmove (hdpa
->ptrs
+ i
+ 1, hdpa
->ptrs
+ i
, (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
));
1856 /**************************************************************************
1857 * DPA_SetPtr [COMCTL32.335]
1859 * Sets a pointer in the pointer array
1862 * hdpa [I] handle (pointer) to the pointer array
1863 * i [I] index of the pointer that will be set
1864 * p [I] pointer to be set
1872 DPA_SetPtr (const HDPA hdpa
, INT i
, LPVOID p
)
1876 TRACE("(%p %d %p)\n", hdpa
, i
, p
);
1878 if (!hdpa
|| i
< 0 || i
> 0x7fff)
1881 if (hdpa
->nItemCount
<= i
) {
1882 /* within the old array */
1883 if (hdpa
->nMaxCount
<= i
) {
1884 /* resize the block of memory */
1886 hdpa
->nGrow
* ((INT
)(((i
+1) - 1) / hdpa
->nGrow
) + 1);
1887 INT nSize
= nNewItems
* sizeof(LPVOID
);
1890 lpTemp
= (LPVOID
*)HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, hdpa
->ptrs
, nSize
);
1892 lpTemp
= (LPVOID
*)HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
, nSize
);
1897 hdpa
->nMaxCount
= nNewItems
;
1898 hdpa
->ptrs
= lpTemp
;
1900 hdpa
->nItemCount
= i
+1;
1903 /* put the new entry in */
1910 /**************************************************************************
1911 * DPA_DeletePtr [COMCTL32.336]
1913 * Removes a pointer from the pointer array.
1916 * hdpa [I] handle (pointer) to the pointer array
1917 * i [I] index of the pointer that will be deleted
1920 * Success: deleted pointer
1925 DPA_DeletePtr (const HDPA hdpa
, INT i
)
1927 LPVOID
*lpDest
, *lpSrc
, lpTemp
= NULL
;
1930 TRACE("(%p %d)\n", hdpa
, i
);
1932 if ((!hdpa
) || i
< 0 || i
>= hdpa
->nItemCount
)
1935 lpTemp
= hdpa
->ptrs
[i
];
1937 /* do we need to move ?*/
1938 if (i
< hdpa
->nItemCount
- 1) {
1939 lpDest
= hdpa
->ptrs
+ i
;
1941 nSize
= (hdpa
->nItemCount
- i
- 1) * sizeof(LPVOID
);
1942 TRACE("-- move dest=%p src=%p size=%x\n",
1943 lpDest
, lpSrc
, nSize
);
1944 memmove (lpDest
, lpSrc
, nSize
);
1947 hdpa
->nItemCount
--;
1950 if ((hdpa
->nMaxCount
- hdpa
->nItemCount
) >= hdpa
->nGrow
) {
1951 INT nNewItems
= max(hdpa
->nGrow
* 2, hdpa
->nItemCount
);
1952 nSize
= nNewItems
* sizeof(LPVOID
);
1953 lpDest
= (LPVOID
)HeapReAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
1958 hdpa
->nMaxCount
= nNewItems
;
1959 hdpa
->ptrs
= (LPVOID
*)lpDest
;
1966 /**************************************************************************
1967 * DPA_DeleteAllPtrs [COMCTL32.337]
1969 * Removes all pointers and reinitializes the array.
1972 * hdpa [I] handle (pointer) to the pointer array
1980 DPA_DeleteAllPtrs (const HDPA hdpa
)
1982 TRACE("(%p)\n", hdpa
);
1987 if (hdpa
->ptrs
&& (!HeapFree (hdpa
->hHeap
, 0, hdpa
->ptrs
)))
1990 hdpa
->nItemCount
= 0;
1991 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
1992 hdpa
->ptrs
= (LPVOID
*)HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
1993 hdpa
->nMaxCount
* sizeof(LPVOID
));
1999 /**************************************************************************
2000 * DPA_QuickSort [Internal]
2002 * Ordinary quicksort (used by DPA_Sort).
2005 * lpPtrs [I] pointer to the pointer array
2006 * l [I] index of the "left border" of the partition
2007 * r [I] index of the "right border" of the partition
2008 * pfnCompare [I] pointer to the compare function
2009 * lParam [I] user defined value (3rd parameter in compare function)
2016 DPA_QuickSort (LPVOID
*lpPtrs
, INT l
, INT r
,
2017 PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
2022 TRACE("l=%i r=%i\n", l
, r
);
2024 if (l
==r
) /* one element is always sorted */
2026 if (r
<l
) /* oops, got it in the wrong order */
2028 DPA_QuickSort(lpPtrs
, r
, l
, pfnCompare
, lParam
);
2031 m
= (l
+r
)/2; /* divide by two */
2032 DPA_QuickSort(lpPtrs
, l
, m
, pfnCompare
, lParam
);
2033 DPA_QuickSort(lpPtrs
, m
+1, r
, pfnCompare
, lParam
);
2035 /* join the two sides */
2036 while( (l
<=m
) && (m
<r
) )
2038 if(pfnCompare(lpPtrs
[l
],lpPtrs
[m
+1],lParam
)>0)
2041 memmove(&lpPtrs
[l
+1],&lpPtrs
[l
],(m
-l
+1)*sizeof(lpPtrs
[l
]));
2051 /**************************************************************************
2052 * DPA_Sort [COMCTL32.338]
2054 * Sorts a pointer array using a user defined compare function
2057 * hdpa [I] handle (pointer) to the pointer array
2058 * pfnCompare [I] pointer to the compare function
2059 * lParam [I] user defined value (3rd parameter of compare function)
2067 DPA_Sort (const HDPA hdpa
, PFNDPACOMPARE pfnCompare
, LPARAM lParam
)
2069 if (!hdpa
|| !pfnCompare
)
2072 TRACE("(%p %p 0x%lx)\n", hdpa
, pfnCompare
, lParam
);
2074 if ((hdpa
->nItemCount
> 1) && (hdpa
->ptrs
))
2075 DPA_QuickSort (hdpa
->ptrs
, 0, hdpa
->nItemCount
- 1,
2076 pfnCompare
, lParam
);
2082 /**************************************************************************
2083 * DPA_Search [COMCTL32.339]
2085 * Searches a pointer array for a specified pointer
2088 * hdpa [I] handle (pointer) to the pointer array
2089 * pFind [I] pointer to search for
2090 * nStart [I] start index
2091 * pfnCompare [I] pointer to the compare function
2092 * lParam [I] user defined value (3rd parameter of compare function)
2093 * uOptions [I] search options
2096 * Success: index of the pointer in the array.
2100 * Binary search taken from R.Sedgewick "Algorithms in C"!
2101 * Function is NOT tested!
2102 * If something goes wrong, blame HIM not ME! (Eric Kohl)
2106 DPA_Search (const HDPA hdpa
, LPVOID pFind
, INT nStart
,
2107 PFNDPACOMPARE pfnCompare
, LPARAM lParam
, UINT uOptions
)
2109 if (!hdpa
|| !pfnCompare
|| !pFind
)
2112 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
2113 hdpa
, pFind
, nStart
, pfnCompare
, lParam
, uOptions
);
2115 if (uOptions
& DPAS_SORTED
) {
2116 /* array is sorted --> use binary search */
2120 TRACE("binary search\n");
2122 l
= (nStart
== -1) ? 0 : nStart
;
2123 r
= hdpa
->nItemCount
- 1;
2127 n
= (pfnCompare
)(pFind
, lpPtr
[x
], lParam
);
2133 TRACE("-- ret=%d\n", n
);
2138 if (uOptions
& DPAS_INSERTBEFORE
) {
2140 TRACE("-- ret=%d\n", r
);
2144 if (uOptions
& DPAS_INSERTAFTER
) {
2145 TRACE("-- ret=%d\n", l
);
2150 /* array is not sorted --> use linear search */
2154 TRACE("linear search\n");
2156 nIndex
= (nStart
== -1)? 0 : nStart
;
2158 for (; nIndex
< hdpa
->nItemCount
; nIndex
++) {
2159 if ((pfnCompare
)(pFind
, lpPtr
[nIndex
], lParam
) == 0) {
2160 TRACE("-- ret=%d\n", nIndex
);
2166 TRACE("-- not found: ret=-1\n");
2171 /**************************************************************************
2172 * DPA_CreateEx [COMCTL32.340]
2174 * Creates a dynamic pointer array using the specified size and heap.
2177 * nGrow [I] number of items by which the array grows when it is filled
2178 * hHeap [I] handle to the heap where the array is stored
2181 * Success: handle (pointer) to the pointer array.
2186 DPA_CreateEx (INT nGrow
, HANDLE hHeap
)
2190 TRACE("(%d %p)\n", nGrow
, hHeap
);
2193 hdpa
= (HDPA
)HeapAlloc (hHeap
, HEAP_ZERO_MEMORY
, sizeof(*hdpa
));
2195 hdpa
= Alloc (sizeof(*hdpa
));
2198 hdpa
->nGrow
= min(8, nGrow
);
2199 hdpa
->hHeap
= hHeap
? hHeap
: GetProcessHeap();
2200 hdpa
->nMaxCount
= hdpa
->nGrow
* 2;
2201 hdpa
->ptrs
= HeapAlloc (hdpa
->hHeap
, HEAP_ZERO_MEMORY
,
2202 hdpa
->nMaxCount
* sizeof(LPVOID
));
2205 TRACE("-- %p\n", hdpa
);
2211 /**************************************************************************
2212 * DPA_Create [COMCTL32.328] Creates a dynamic pointer array
2215 * nGrow [I] number of items by which the array grows when it is filled
2218 * Success: handle (pointer) to the pointer array.
2223 DPA_Create (INT nGrow
)
2225 return DPA_CreateEx( nGrow
, 0 );
2229 /**************************************************************************
2230 * Notification functions
2233 typedef struct tagNOTIFYDATA
2241 } NOTIFYDATA
, *LPNOTIFYDATA
;
2244 /**************************************************************************
2245 * DoNotify [Internal]
2249 DoNotify (LPNOTIFYDATA lpNotify
, UINT uCode
, LPNMHDR lpHdr
)
2252 LPNMHDR lpNmh
= NULL
;
2255 TRACE("(%p %p %d %p 0x%08lx)\n",
2256 lpNotify
->hwndFrom
, lpNotify
->hwndTo
, uCode
, lpHdr
,
2257 lpNotify
->dwParam5
);
2259 if (!lpNotify
->hwndTo
)
2262 if (lpNotify
->hwndFrom
== (HWND
)-1) {
2264 idFrom
= lpHdr
->idFrom
;
2267 if (lpNotify
->hwndFrom
)
2268 idFrom
= GetDlgCtrlID (lpNotify
->hwndFrom
);
2270 lpNmh
= (lpHdr
) ? lpHdr
: &nmhdr
;
2272 lpNmh
->hwndFrom
= lpNotify
->hwndFrom
;
2273 lpNmh
->idFrom
= idFrom
;
2274 lpNmh
->code
= uCode
;
2277 return SendMessageA (lpNotify
->hwndTo
, WM_NOTIFY
, idFrom
, (LPARAM
)lpNmh
);
2281 /**************************************************************************
2282 * SendNotify [COMCTL32.341]
2291 * Success: return value from notification
2295 LRESULT WINAPI
SendNotify (HWND hwndTo
, HWND hwndFrom
, UINT uCode
, LPNMHDR lpHdr
)
2299 TRACE("(%p %p %d %p)\n",
2300 hwndTo
, hwndFrom
, uCode
, lpHdr
);
2302 notify
.hwndFrom
= hwndFrom
;
2303 notify
.hwndTo
= hwndTo
;
2304 notify
.dwParam5
= 0;
2305 notify
.dwParam6
= 0;
2307 return DoNotify (¬ify
, uCode
, lpHdr
);
2311 /**************************************************************************
2312 * SendNotifyEx [COMCTL32.342]
2322 * Success: return value from notification
2326 LRESULT WINAPI
SendNotifyEx (HWND hwndTo
, HWND hwndFrom
, UINT uCode
,
2327 LPNMHDR lpHdr
, DWORD dwParam5
)
2332 TRACE("(%p %p %d %p 0x%08lx)\n",
2333 hwndFrom
, hwndTo
, uCode
, lpHdr
, dwParam5
);
2335 hwndNotify
= hwndTo
;
2337 if (IsWindow (hwndFrom
)) {
2338 hwndNotify
= GetParent (hwndFrom
);
2344 notify
.hwndFrom
= hwndFrom
;
2345 notify
.hwndTo
= hwndNotify
;
2346 notify
.dwParam5
= dwParam5
;
2347 notify
.dwParam6
= 0;
2349 return DoNotify (¬ify
, uCode
, lpHdr
);
2353 /**************************************************************************
2354 * StrChrA [COMCTL32.350]
2358 LPSTR WINAPI
StrChrA (LPCSTR lpString
, CHAR cChar
)
2360 return strchr (lpString
, cChar
);
2364 /**************************************************************************
2365 * StrStrIA [COMCTL32.355]
2368 LPSTR WINAPI
StrStrIA (LPCSTR lpStr1
, LPCSTR lpStr2
)
2374 return ((LPSTR
)lpStr1
);
2376 while (lpStr1
[len1
] != 0) ++len1
;
2378 while (lpStr2
[len2
] != 0) ++len2
;
2380 return ((LPSTR
)(lpStr1
+ len1
));
2381 first
= tolower (*lpStr2
);
2382 while (len1
>= len2
) {
2383 if (tolower(*lpStr1
) == first
) {
2384 for (i
= 1; i
< len2
; ++i
)
2385 if (tolower (lpStr1
[i
]) != tolower(lpStr2
[i
]))
2388 return ((LPSTR
)lpStr1
);
2395 /**************************************************************************
2396 * StrToIntA [COMCTL32.357] Converts a string to a signed integer.
2399 INT WINAPI
StrToIntA (LPSTR lpString
)
2401 return atoi(lpString
);
2404 /**************************************************************************
2405 * StrStrIW [COMCTL32.363]
2408 LPWSTR WINAPI
StrStrIW (LPCWSTR lpStr1
, LPCWSTR lpStr2
)
2414 return ((LPWSTR
)lpStr1
);
2416 while (lpStr1
[len1
] != 0) ++len1
;
2418 while (lpStr2
[len2
] != 0) ++len2
;
2420 return ((LPWSTR
)(lpStr1
+ len1
));
2421 first
= tolowerW (*lpStr2
);
2422 while (len1
>= len2
) {
2423 if (tolowerW (*lpStr1
) == first
) {
2424 for (i
= 1; i
< len2
; ++i
)
2425 if (tolowerW (lpStr1
[i
]) != tolowerW(lpStr2
[i
]))
2428 return ((LPWSTR
)lpStr1
);
2435 /**************************************************************************
2436 * StrToIntW [COMCTL32.365] Converts a wide char string to a signed integer.
2439 INT WINAPI
StrToIntW (LPWSTR lpString
)
2441 return atoiW(lpString
);
2445 /**************************************************************************
2446 * DPA_EnumCallback [COMCTL32.385]
2448 * Enumerates all items in a dynamic pointer array.
2451 * hdpa [I] handle to the dynamic pointer array
2460 DPA_EnumCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
, LPVOID lParam
)
2464 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
2468 if (hdpa
->nItemCount
<= 0)
2471 for (i
= 0; i
< hdpa
->nItemCount
; i
++) {
2472 if ((enumProc
)(hdpa
->ptrs
[i
], lParam
) == 0)
2480 /**************************************************************************
2481 * DPA_DestroyCallback [COMCTL32.386]
2483 * Enumerates all items in a dynamic pointer array and destroys it.
2486 * hdpa [I] handle to the dynamic pointer array
2495 DPA_DestroyCallback (HDPA hdpa
, PFNDPAENUMCALLBACK enumProc
, LPVOID lParam
)
2497 TRACE("(%p %p %p)\n", hdpa
, enumProc
, lParam
);
2499 DPA_EnumCallback (hdpa
, enumProc
, lParam
);
2504 /**************************************************************************
2505 * DSA_EnumCallback [COMCTL32.387]
2507 * Enumerates all items in a dynamic storage array.
2510 * hdsa [I] handle to the dynamic storage array
2519 DSA_EnumCallback (HDSA hdsa
, PFNDSAENUMCALLBACK enumProc
, LPVOID lParam
)
2523 TRACE("(%p %p %p)\n", hdsa
, enumProc
, lParam
);
2527 if (hdsa
->nItemCount
<= 0)
2530 for (i
= 0; i
< hdsa
->nItemCount
; i
++) {
2531 LPVOID lpItem
= DSA_GetItemPtr (hdsa
, i
);
2532 if ((enumProc
)(lpItem
, lParam
) == 0)
2540 /**************************************************************************
2541 * DSA_DestroyCallback [COMCTL32.388]
2543 * Enumerates all items in a dynamic storage array and destroys it.
2546 * hdsa [I] handle to the dynamic storage array
2555 DSA_DestroyCallback (HDSA hdsa
, PFNDSAENUMCALLBACK enumProc
, LPVOID lParam
)
2557 TRACE("(%p %p %p)\n", hdsa
, enumProc
, lParam
);
2559 DSA_EnumCallback (hdsa
, enumProc
, lParam
);
2563 /**************************************************************************
2564 * StrCSpnA [COMCTL32.356]
2567 INT WINAPI
StrCSpnA( LPCSTR lpStr
, LPCSTR lpSet
)
2569 return strcspn(lpStr
, lpSet
);
2572 /**************************************************************************
2573 * StrChrW [COMCTL32.358]
2576 LPWSTR WINAPI
StrChrW( LPCWSTR lpStart
, WORD wMatch
)
2578 return strchrW(lpStart
, wMatch
);
2581 /**************************************************************************
2582 * StrCmpNA [COMCTL32.352]
2585 INT WINAPI
StrCmpNA( LPCSTR lpStr1
, LPCSTR lpStr2
, int nChar
)
2587 return strncmp(lpStr1
, lpStr2
, nChar
);
2590 /**************************************************************************
2591 * StrCmpNIA [COMCTL32.353]
2594 INT WINAPI
StrCmpNIA( LPCSTR lpStr1
, LPCSTR lpStr2
, int nChar
)
2596 return strncasecmp(lpStr1
, lpStr2
, nChar
);
2599 /**************************************************************************
2600 * StrCmpNW [COMCTL32.360]
2603 INT WINAPI
StrCmpNW( LPCWSTR lpStr1
, LPCWSTR lpStr2
, int nChar
)
2605 return strncmpW(lpStr1
, lpStr2
, nChar
);
2608 /**************************************************************************
2609 * StrCmpNIW [COMCTL32.361]
2612 INT WINAPI
StrCmpNIW( LPCWSTR lpStr1
, LPCWSTR lpStr2
, int nChar
)
2614 FIXME("(%s, %s, %i): stub\n", debugstr_w(lpStr1
), debugstr_w(lpStr2
), nChar
);
2618 /**************************************************************************
2619 * StrRChrA [COMCTL32.351]
2622 LPSTR WINAPI
StrRChrA( LPCSTR lpStart
, LPCSTR lpEnd
, WORD wMatch
)
2624 LPCSTR lpGotIt
= NULL
;
2625 BOOL dbcs
= IsDBCSLeadByte( LOBYTE(wMatch
) );
2627 TRACE("(%p, %p, %x)\n", lpStart
, lpEnd
, wMatch
);
2629 if (!lpEnd
) lpEnd
= lpStart
+ strlen(lpStart
);
2631 for(; lpStart
< lpEnd
; lpStart
= CharNextA(lpStart
))
2633 if (*lpStart
!= LOBYTE(wMatch
)) continue;
2634 if (dbcs
&& lpStart
[1] != HIBYTE(wMatch
)) continue;
2637 return (LPSTR
)lpGotIt
;
2641 /**************************************************************************
2642 * StrRChrW [COMCTL32.359]
2645 LPWSTR WINAPI
StrRChrW( LPCWSTR lpStart
, LPCWSTR lpEnd
, WORD wMatch
)
2647 LPCWSTR lpGotIt
= NULL
;
2649 TRACE("(%p, %p, %x)\n", lpStart
, lpEnd
, wMatch
);
2650 if (!lpEnd
) lpEnd
= lpStart
+ strlenW(lpStart
);
2652 for(; lpStart
< lpEnd
; lpStart
= CharNextW(lpStart
))
2653 if (*lpStart
== wMatch
) lpGotIt
= lpStart
;
2655 return (LPWSTR
)lpGotIt
;
2659 /**************************************************************************
2660 * StrStrA [COMCTL32.354]
2663 LPSTR WINAPI
StrStrA( LPCSTR lpFirst
, LPCSTR lpSrch
)
2665 return strstr(lpFirst
, lpSrch
);
2668 /**************************************************************************
2669 * StrStrW [COMCTL32.362]
2672 LPWSTR WINAPI
StrStrW( LPCWSTR lpFirst
, LPCWSTR lpSrch
)
2674 return strstrW(lpFirst
, lpSrch
);
2677 /**************************************************************************
2678 * StrSpnW [COMCTL32.364]
2681 INT WINAPI
StrSpnW( LPWSTR lpStr
, LPWSTR lpSet
)
2683 LPWSTR lpLoop
= lpStr
;
2686 if ((lpStr
== 0) || (lpSet
== 0)) return 0;
2688 /* while(*lpLoop) { if lpLoop++; } */
2690 for(; (*lpLoop
!= 0); lpLoop
++)
2691 if( strchrW(lpSet
, *(WORD
*)lpLoop
))
2692 return (INT
)(lpLoop
-lpStr
);
2694 return (INT
)(lpLoop
-lpStr
);
2697 /**************************************************************************
2700 * FIXME: What's this supposed to do?
2701 * Parameter 1 is an HWND, you're on your own for the rest.
2704 BOOL WINAPI
DrawTextWrap( HWND hwnd
, DWORD b
, DWORD c
, DWORD d
, DWORD e
)
2707 FIXME("(%p, %lx, %lx, %lx, %lx): stub!\n", hwnd
, b
, c
, d
, e
);
2712 /**************************************************************************
2716 BOOL WINAPI
ExtTextOutWrap(HDC hdc
, INT x
, INT y
, UINT flags
, const RECT
*lprect
,
2717 LPCWSTR str
, UINT count
, const INT
*lpDx
)
2719 return ExtTextOutW(hdc
, x
, y
, flags
, lprect
, str
, count
, lpDx
);
2722 /**************************************************************************
2725 * FIXME: What's this supposed to do?
2728 BOOL WINAPI
GetTextExtentPointWrap( DWORD a
, DWORD b
, DWORD c
, DWORD d
)
2731 FIXME("(%lx, %lx, %lx, %lx): stub!\n", a
, b
, c
, d
);