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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * All of these functions are UNDOCUMENTED!! And I mean UNDOCUMENTED!!!!
24 * Do NOT rely on names or contents of undocumented structures and types!!!
25 * These functions are used by EXPLORER.EXE, IEXPLORE.EXE and
26 * COMCTL32.DLL (internally).
30 #include "wine/port.h"
38 #define NONAMELESSUNION
50 #include "wine/unicode.h"
53 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(commctrl
);
57 static const WCHAR strMRUList
[] = { 'M','R','U','L','i','s','t',0 };
59 /**************************************************************************
62 * Allocates memory block from the dll's private heap
65 * dwSize [I] size of the allocated memory block
68 * Success: pointer to allocated memory block
71 LPVOID WINAPI
Alloc (DWORD dwSize
)
73 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
77 /**************************************************************************
78 * ReAlloc [COMCTL32.72]
80 * Changes the size of an allocated memory block or allocates a memory
81 * block using the dll's private heap.
84 * lpSrc [I] pointer to memory block which will be resized
85 * dwSize [I] new size of the memory block.
88 * Success: pointer to the resized memory block
92 * If lpSrc is a NULL-pointer, then ReAlloc allocates a memory
95 LPVOID WINAPI
ReAlloc (LPVOID lpSrc
, DWORD dwSize
)
98 return LocalReAlloc( lpSrc
, dwSize
, LMEM_ZEROINIT
| LMEM_MOVEABLE
);
100 return LocalAlloc( LMEM_ZEROINIT
, dwSize
);
104 /**************************************************************************
107 * Frees an allocated memory block from the dll's private heap.
110 * lpMem [I] pointer to memory block which will be freed
116 BOOL WINAPI
Free (LPVOID lpMem
)
118 return !LocalFree( lpMem
);
122 /**************************************************************************
123 * GetSize [COMCTL32.74]
125 * Retrieves the size of the specified memory block from the dll's
129 * lpMem [I] pointer to an allocated memory block
132 * Success: size of the specified memory block
135 DWORD WINAPI
GetSize (LPVOID lpMem
)
137 return LocalSize( lpMem
);
141 /**************************************************************************
142 * MRU-Functions {COMCTL32}
145 * The MRU-API is a set of functions to manipulate lists of M.R.U. (Most Recently
146 * Used) items. It is an undocumented API that is used (at least) by the shell
147 * and explorer to implement their recent documents feature.
149 * Since these functions are undocumented, they are unsupported by MS and
150 * may change at any time.
152 * Internally, the list is implemented as a last in, last out list of items
153 * persisted into the system registry under a caller chosen key. Each list
154 * item is given a one character identifier in the Ascii range from 'a' to
155 * '}'. A list of the identifiers in order from newest to oldest is stored
156 * under the same key in a value named "MRUList".
158 * Items are re-ordered by changing the order of the values in the MRUList
159 * value. When a new item is added, it becomes the new value of the oldest
160 * identifier, and that identifier is moved to the front of the MRUList value.
162 * Wine stores MRU-lists in the same registry format as Windows, so when
163 * switching between the builtin and native comctl32.dll no problems or
164 * incompatibilities should occur.
166 * The following undocumented structure is used to create an MRU-list:
167 *|typedef INT (CALLBACK *MRUStringCmpFn)(LPCTSTR lhs, LPCTSTR rhs);
168 *|typedef INT (CALLBACK *MRUBinaryCmpFn)(LPCVOID lhs, LPCVOID rhs, DWORD length);
170 *|typedef struct tagMRUINFO
176 *| LPTSTR lpszSubKey;
178 *|} MRUINFO, *LPMRUINFO;
181 * cbSize [I] The size of the MRUINFO structure. This must be set
182 * to sizeof(MRUINFO) by the caller.
183 * uMax [I] The maximum number of items allowed in the list. Because
184 * of the limited number of identifiers, this should be set to
185 * a value from 1 to 30 by the caller.
186 * fFlags [I] If bit 0 is set, the list will be used to store binary
187 * data, otherwise it is assumed to store strings. If bit 1
188 * is set, every change made to the list will be reflected in
189 * the registry immediately, otherwise changes will only be
190 * written when the list is closed.
191 * hKey [I] The registry key that the list should be written under.
192 * This must be supplied by the caller.
193 * lpszSubKey [I] A caller supplied name of a subkey under hKey to write
194 * the list to. This may not be blank.
195 * lpfnCompare [I] A caller supplied comparison function, which may be either
196 * an MRUStringCmpFn if dwFlags does not have bit 0 set, or a
197 * MRUBinaryCmpFn otherwise.
200 * - Create an MRU-list with CreateMRUList() or CreateMRUListLazy().
201 * - Add items to an MRU-list with AddMRUString() or AddMRUData().
202 * - Remove items from an MRU-list with DelMRUString().
203 * - Find data in an MRU-list with FindMRUString() or FindMRUData().
204 * - Iterate through an MRU-list with EnumMRUList().
205 * - Free an MRU-list with FreeMRUList().
208 typedef INT (CALLBACK
*MRUStringCmpFnA
)(LPCSTR lhs
, LPCSTR rhs
);
209 typedef INT (CALLBACK
*MRUStringCmpFnW
)(LPCWSTR lhs
, LPCWSTR rhs
);
210 typedef INT (CALLBACK
*MRUBinaryCmpFn
)(LPCVOID lhs
, LPCVOID rhs
, DWORD length
);
212 typedef struct tagMRUINFOA
221 MRUStringCmpFnA string_cmpfn
;
222 MRUBinaryCmpFn binary_cmpfn
;
224 } MRUINFOA
, *LPMRUINFOA
;
226 typedef struct tagMRUINFOW
235 MRUStringCmpFnW string_cmpfn
;
236 MRUBinaryCmpFn binary_cmpfn
;
238 } MRUINFOW
, *LPMRUINFOW
;
241 #define MRU_STRING 0 /* list will contain strings */
242 #define MRU_BINARY 1 /* list will contain binary data */
243 #define MRU_CACHEWRITE 2 /* only save list order to reg. is FreeMRUList */
245 /* If list is a string list lpfnCompare has the following prototype
246 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
247 * for binary lists the prototype is
248 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
249 * where cbData is the no. of bytes to compare.
250 * Need to check what return value means identical - 0?
253 typedef struct tagWINEMRUITEM
255 DWORD size
; /* size of data stored */
256 DWORD itemFlag
; /* flags */
258 } WINEMRUITEM
, *LPWINEMRUITEM
;
261 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
263 typedef struct tagWINEMRULIST
265 MRUINFOW extview
; /* original create information */
266 BOOL isUnicode
; /* is compare fn Unicode */
267 DWORD wineFlags
; /* internal flags */
268 DWORD cursize
; /* current size of realMRU */
269 LPWSTR realMRU
; /* pointer to string of index names */
270 LPWINEMRUITEM
*array
; /* array of pointers to data */
271 /* in 'a' to 'z' order */
272 } WINEMRULIST
, *LPWINEMRULIST
;
275 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
277 /**************************************************************************
278 * MRU_SaveChanged (internal)
280 * Local MRU saving code
282 static void MRU_SaveChanged ( LPWINEMRULIST mp
)
289 /* or should we do the following instead of RegOpenKeyEx:
292 /* open the sub key */
293 if ((err
= RegOpenKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
294 0, KEY_WRITE
, &newkey
))) {
295 /* not present - what to do ??? */
296 ERR("Could not open key, error=%d, attempting to create\n",
298 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
301 REG_OPTION_NON_VOLATILE
,
302 KEY_READ
| KEY_WRITE
,
306 ERR("failed to create key /%s/, err=%d\n",
307 debugstr_w(mp
->extview
.lpszSubKey
), err
);
311 if (mp
->wineFlags
& WMRUF_CHANGED
) {
312 mp
->wineFlags
&= ~WMRUF_CHANGED
;
313 err
= RegSetValueExW(newkey
, strMRUList
, 0, REG_SZ
, (LPBYTE
)mp
->realMRU
,
314 (strlenW(mp
->realMRU
) + 1)*sizeof(WCHAR
));
316 ERR("error saving MRUList, err=%d\n", err
);
318 TRACE("saving MRUList=/%s/\n", debugstr_w(mp
->realMRU
));
321 for(i
=0; i
<mp
->cursize
; i
++) {
322 witem
= mp
->array
[i
];
323 if (witem
->itemFlag
& WMRUIF_CHANGED
) {
324 witem
->itemFlag
&= ~WMRUIF_CHANGED
;
325 realname
[0] = 'a' + i
;
326 err
= RegSetValueExW(newkey
, realname
, 0,
327 (mp
->extview
.fFlags
& MRU_BINARY
) ?
329 &witem
->datastart
, witem
->size
);
331 ERR("error saving /%s/, err=%d\n", debugstr_w(realname
), err
);
333 TRACE("saving value for name /%s/ size=%d\n",
334 debugstr_w(realname
), witem
->size
);
337 RegCloseKey( newkey
);
340 /**************************************************************************
341 * FreeMRUList [COMCTL32.152]
343 * Frees a most-recently-used items list.
346 * hMRUList [I] Handle to list.
351 void WINAPI
FreeMRUList (HANDLE hMRUList
)
353 LPWINEMRULIST mp
= hMRUList
;
356 TRACE("(%p)\n", hMRUList
);
360 if (mp
->wineFlags
& WMRUF_CHANGED
) {
361 /* need to open key and then save the info */
362 MRU_SaveChanged( mp
);
365 for(i
=0; i
<mp
->extview
.uMax
; i
++)
370 Free(mp
->extview
.lpszSubKey
);
375 /**************************************************************************
376 * FindMRUData [COMCTL32.169]
378 * Searches binary list for item that matches lpData of length cbData.
379 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
380 * corresponding to item's reg. name will be stored in it ('a' -> 0).
383 * hList [I] list handle
384 * lpData [I] data to find
385 * cbData [I] length of data
386 * lpRegNum [O] position in registry (maybe NULL)
389 * Position in list 0 -> MRU. -1 if item not found.
391 INT WINAPI
FindMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
,
394 const WINEMRULIST
*mp
= hList
;
399 if (!mp
|| !mp
->extview
.u
.string_cmpfn
)
402 if(!(mp
->extview
.fFlags
& MRU_BINARY
) && !mp
->isUnicode
) {
403 DWORD len
= WideCharToMultiByte(CP_ACP
, 0, lpData
, -1,
404 NULL
, 0, NULL
, NULL
);
406 WideCharToMultiByte(CP_ACP
, 0, lpData
, -1, dataA
, len
, NULL
, NULL
);
409 for(i
=0; i
<mp
->cursize
; i
++) {
410 if (mp
->extview
.fFlags
& MRU_BINARY
) {
411 if (!mp
->extview
.u
.binary_cmpfn(lpData
, &mp
->array
[i
]->datastart
, cbData
))
416 if (!mp
->extview
.u
.string_cmpfn(lpData
, (LPWSTR
)&mp
->array
[i
]->datastart
))
419 DWORD len
= WideCharToMultiByte(CP_ACP
, 0,
420 (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
421 NULL
, 0, NULL
, NULL
);
422 LPSTR itemA
= Alloc(len
);
424 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
425 itemA
, len
, NULL
, NULL
);
427 cmp
= mp
->extview
.u
.string_cmpfn((LPWSTR
)dataA
, (LPWSTR
)itemA
);
439 if (lpRegNum
&& (ret
!= -1))
442 TRACE("(%p, %p, %d, %p) returning %d\n",
443 hList
, lpData
, cbData
, lpRegNum
, ret
);
449 /**************************************************************************
450 * AddMRUData [COMCTL32.167]
452 * Add item to MRU binary list. If item already exists in list then it is
453 * simply moved up to the top of the list and not added again. If list is
454 * full then the least recently used item is removed to make room.
457 * hList [I] Handle to list.
458 * lpData [I] ptr to data to add.
459 * cbData [I] no. of bytes of data.
462 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
465 INT WINAPI
AddMRUData (HANDLE hList
, LPCVOID lpData
, DWORD cbData
)
467 LPWINEMRULIST mp
= hList
;
471 if ((replace
= FindMRUData (hList
, lpData
, cbData
, NULL
)) >= 0) {
472 /* Item exists, just move it to the front */
473 LPWSTR pos
= strchrW(mp
->realMRU
, replace
+ 'a');
474 while (pos
> mp
->realMRU
)
481 /* either add a new entry or replace oldest */
482 if (mp
->cursize
< mp
->extview
.uMax
) {
483 /* Add in a new item */
484 replace
= mp
->cursize
;
488 /* get the oldest entry and replace data */
489 replace
= mp
->realMRU
[mp
->cursize
- 1] - 'a';
490 Free(mp
->array
[replace
]);
493 /* Allocate space for new item and move in the data */
494 mp
->array
[replace
] = witem
= Alloc(cbData
+ sizeof(WINEMRUITEM
));
495 witem
->itemFlag
|= WMRUIF_CHANGED
;
496 witem
->size
= cbData
;
497 memcpy( &witem
->datastart
, lpData
, cbData
);
499 /* now rotate MRU list */
500 for(i
=mp
->cursize
-1; i
>=1; i
--)
501 mp
->realMRU
[i
] = mp
->realMRU
[i
-1];
504 /* The new item gets the front spot */
505 mp
->wineFlags
|= WMRUF_CHANGED
;
506 mp
->realMRU
[0] = replace
+ 'a';
508 TRACE("(%p, %p, %d) adding data, /%c/ now most current\n",
509 hList
, lpData
, cbData
, replace
+'a');
511 if (!(mp
->extview
.fFlags
& MRU_CACHEWRITE
)) {
512 /* save changed stuff right now */
513 MRU_SaveChanged( mp
);
519 /**************************************************************************
520 * AddMRUStringW [COMCTL32.401]
522 * Add an item to an MRU string list.
525 * hList [I] Handle to list.
526 * lpszString [I] The string to add.
529 * Success: The number corresponding to the registry name where the string
530 * has been stored (0 maps to 'a', 1 to 'b' and so on).
531 * Failure: -1, if hList is NULL or memory allocation fails. If lpszString
532 * is invalid, the function returns 0, and GetLastError() returns
533 * ERROR_INVALID_PARAMETER. The last error value is set only in
537 * -If lpszString exists in the list already, it is moved to the top of the
538 * MRU list (it is not duplicated).
539 * -If the list is full the least recently used list entry is replaced with
541 * -If this function returns 0 you should check the last error value to
542 * ensure the call really succeeded.
544 INT WINAPI
AddMRUStringW(HANDLE hList
, LPCWSTR lpszString
)
546 TRACE("(%p,%s)\n", hList
, debugstr_w(lpszString
));
551 if (!lpszString
|| IsBadStringPtrW(lpszString
, -1))
553 SetLastError(ERROR_INVALID_PARAMETER
);
557 return AddMRUData(hList
, lpszString
,
558 (strlenW(lpszString
) + 1) * sizeof(WCHAR
));
561 /**************************************************************************
562 * AddMRUStringA [COMCTL32.153]
566 INT WINAPI
AddMRUStringA(HANDLE hList
, LPCSTR lpszString
)
572 TRACE("(%p,%s)\n", hList
, debugstr_a(lpszString
));
577 if (IsBadStringPtrA(lpszString
, -1))
579 SetLastError(ERROR_INVALID_PARAMETER
);
583 len
= MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, NULL
, 0) * sizeof(WCHAR
);
584 stringW
= Alloc(len
);
588 MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, stringW
, len
/sizeof(WCHAR
));
589 ret
= AddMRUData(hList
, stringW
, len
);
594 /**************************************************************************
595 * DelMRUString [COMCTL32.156]
597 * Removes item from either string or binary list (despite its name)
600 * hList [I] list handle
601 * nItemPos [I] item position to remove 0 -> MRU
604 * TRUE if successful, FALSE if nItemPos is out of range.
606 BOOL WINAPI
DelMRUString(HANDLE hList
, INT nItemPos
)
608 FIXME("(%p, %d): stub\n", hList
, nItemPos
);
612 /**************************************************************************
613 * FindMRUStringW [COMCTL32.402]
615 * See FindMRUStringA.
617 INT WINAPI
FindMRUStringW (HANDLE hList
, LPCWSTR lpszString
, LPINT lpRegNum
)
619 return FindMRUData(hList
, lpszString
,
620 (lstrlenW(lpszString
) + 1) * sizeof(WCHAR
), lpRegNum
);
623 /**************************************************************************
624 * FindMRUStringA [COMCTL32.155]
626 * Searches string list for item that matches lpszString.
627 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
628 * corresponding to item's reg. name will be stored in it ('a' -> 0).
631 * hList [I] list handle
632 * lpszString [I] string to find
633 * lpRegNum [O] position in registry (maybe NULL)
636 * Position in list 0 -> MRU. -1 if item not found.
638 INT WINAPI
FindMRUStringA (HANDLE hList
, LPCSTR lpszString
, LPINT lpRegNum
)
640 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, NULL
, 0);
641 LPWSTR stringW
= Alloc(len
* sizeof(WCHAR
));
644 MultiByteToWideChar(CP_ACP
, 0, lpszString
, -1, stringW
, len
);
645 ret
= FindMRUData(hList
, stringW
, len
* sizeof(WCHAR
), lpRegNum
);
650 /*************************************************************************
651 * create_mru_list (internal)
653 static HANDLE
create_mru_list(LPWINEMRULIST mp
)
657 DWORD datasize
, dwdisp
;
662 /* get space to save indices that will turn into names
663 * but in order of most to least recently used
665 mp
->realMRU
= Alloc((mp
->extview
.uMax
+ 2) * sizeof(WCHAR
));
667 /* get space to save pointers to actual data in order of
668 * 'a' to 'z' (0 to n).
670 mp
->array
= Alloc(mp
->extview
.uMax
* sizeof(LPVOID
));
672 /* open the sub key */
673 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
,
676 REG_OPTION_NON_VOLATILE
,
677 KEY_READ
| KEY_WRITE
,
681 /* error - what to do ??? */
682 ERR("(%u %u %x %p %s %p): Could not open key, error=%d\n",
683 mp
->extview
.cbSize
, mp
->extview
.uMax
, mp
->extview
.fFlags
,
684 mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
685 mp
->extview
.u
.string_cmpfn
, err
);
689 /* get values from key 'MRUList' */
691 datasize
= (mp
->extview
.uMax
+ 1) * sizeof(WCHAR
);
692 if (RegQueryValueExW( newkey
, strMRUList
, 0, &type
,
693 (LPBYTE
)mp
->realMRU
, &datasize
)) {
694 /* not present - set size to 1 (will become 0 later) */
699 datasize
/= sizeof(WCHAR
);
701 TRACE("MRU list = %s, datasize = %d\n", debugstr_w(mp
->realMRU
), datasize
);
703 mp
->cursize
= datasize
- 1;
704 /* datasize now has number of items in the MRUList */
706 /* get actual values for each entry */
708 for(i
=0; i
<mp
->cursize
; i
++) {
709 realname
[0] = 'a' + i
;
710 if(RegQueryValueExW( newkey
, realname
, 0, &type
, 0, &datasize
)) {
711 /* not present - what to do ??? */
712 ERR("Key %s not found 1\n", debugstr_w(realname
));
714 mp
->array
[i
] = witem
= Alloc(datasize
+ sizeof(WINEMRUITEM
));
715 witem
->size
= datasize
;
716 if(RegQueryValueExW( newkey
, realname
, 0, &type
,
717 &witem
->datastart
, &datasize
)) {
718 /* not present - what to do ??? */
719 ERR("Key %s not found 2\n", debugstr_w(realname
));
722 RegCloseKey( newkey
);
727 TRACE("(%u %u %x %p %s %p): Current Size = %d\n",
728 mp
->extview
.cbSize
, mp
->extview
.uMax
, mp
->extview
.fFlags
,
729 mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
),
730 mp
->extview
.u
.string_cmpfn
, mp
->cursize
);
734 /**************************************************************************
735 * CreateMRUListLazyW [COMCTL32.404]
737 * See CreateMRUListLazyA.
739 HANDLE WINAPI
CreateMRUListLazyW (const MRUINFOW
*infoW
, DWORD dwParam2
,
740 DWORD dwParam3
, DWORD dwParam4
)
744 /* Native does not check for a NULL lpcml */
745 if (!infoW
->hKey
|| IsBadStringPtrW(infoW
->lpszSubKey
, -1))
748 mp
= Alloc(sizeof(WINEMRULIST
));
749 memcpy(&mp
->extview
, infoW
, sizeof(MRUINFOW
));
750 mp
->extview
.lpszSubKey
= Alloc((strlenW(infoW
->lpszSubKey
) + 1) * sizeof(WCHAR
));
751 strcpyW(mp
->extview
.lpszSubKey
, infoW
->lpszSubKey
);
752 mp
->isUnicode
= TRUE
;
754 return create_mru_list(mp
);
757 /**************************************************************************
758 * CreateMRUListLazyA [COMCTL32.157]
760 * Creates a most-recently-used list.
763 * lpcml [I] ptr to CREATEMRULIST structure.
764 * dwParam2 [I] Unknown
765 * dwParam3 [I] Unknown
766 * dwParam4 [I] Unknown
769 * Handle to MRU list.
771 HANDLE WINAPI
CreateMRUListLazyA (const MRUINFOA
*lpcml
, DWORD dwParam2
,
772 DWORD dwParam3
, DWORD dwParam4
)
777 /* Native does not check for a NULL lpcml */
779 if (!lpcml
->hKey
|| IsBadStringPtrA(lpcml
->lpszSubKey
, -1))
782 mp
= Alloc(sizeof(WINEMRULIST
));
783 memcpy(&mp
->extview
, lpcml
, sizeof(MRUINFOA
));
784 len
= MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1, NULL
, 0);
785 mp
->extview
.lpszSubKey
= Alloc(len
* sizeof(WCHAR
));
786 MultiByteToWideChar(CP_ACP
, 0, lpcml
->lpszSubKey
, -1,
787 mp
->extview
.lpszSubKey
, len
);
788 mp
->isUnicode
= FALSE
;
789 return create_mru_list(mp
);
792 /**************************************************************************
793 * CreateMRUListW [COMCTL32.400]
795 * See CreateMRUListA.
797 HANDLE WINAPI
CreateMRUListW (const MRUINFOW
*infoW
)
799 return CreateMRUListLazyW(infoW
, 0, 0, 0);
802 /**************************************************************************
803 * CreateMRUListA [COMCTL32.151]
805 * Creates a most-recently-used list.
808 * lpcml [I] ptr to CREATEMRULIST structure.
811 * Handle to MRU list.
813 HANDLE WINAPI
CreateMRUListA (const MRUINFOA
*lpcml
)
815 return CreateMRUListLazyA (lpcml
, 0, 0, 0);
819 /**************************************************************************
820 * EnumMRUListW [COMCTL32.403]
822 * Enumerate item in a most-recently-used list
825 * hList [I] list handle
826 * nItemPos [I] item position to enumerate
827 * lpBuffer [O] buffer to receive item
828 * nBufferSize [I] size of buffer
831 * For binary lists specifies how many bytes were copied to buffer, for
832 * string lists specifies full length of string. Enumerating past the end
833 * of list returns -1.
834 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
837 INT WINAPI
EnumMRUListW (HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
840 const WINEMRULIST
*mp
= hList
;
841 const WINEMRUITEM
*witem
;
842 INT desired
, datasize
;
845 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
846 if (nItemPos
>= mp
->cursize
) return -1;
847 desired
= mp
->realMRU
[nItemPos
];
849 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
850 witem
= mp
->array
[desired
];
851 datasize
= min( witem
->size
, nBufferSize
);
852 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
853 TRACE("(%p, %d, %p, %d): returning len=%d\n",
854 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
858 /**************************************************************************
859 * EnumMRUListA [COMCTL32.154]
863 INT WINAPI
EnumMRUListA (HANDLE hList
, INT nItemPos
, LPVOID lpBuffer
,
866 const WINEMRULIST
*mp
= hList
;
868 INT desired
, datasize
;
872 if ((nItemPos
< 0) || !lpBuffer
) return mp
->cursize
;
873 if (nItemPos
>= mp
->cursize
) return -1;
874 desired
= mp
->realMRU
[nItemPos
];
876 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
877 witem
= mp
->array
[desired
];
878 if(mp
->extview
.fFlags
& MRU_BINARY
) {
879 datasize
= min( witem
->size
, nBufferSize
);
880 memcpy( lpBuffer
, &witem
->datastart
, datasize
);
882 lenA
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
883 NULL
, 0, NULL
, NULL
);
884 datasize
= min( lenA
, nBufferSize
);
885 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1,
886 lpBuffer
, datasize
, NULL
, NULL
);
887 ((char *)lpBuffer
)[ datasize
- 1 ] = '\0';
890 TRACE("(%p, %d, %p, %d): returning len=%d\n",
891 hList
, nItemPos
, lpBuffer
, nBufferSize
, datasize
);
895 /**************************************************************************
896 * Str_GetPtrWtoA [internal]
898 * Converts a unicode string into a multi byte string
901 * lpSrc [I] Pointer to the unicode source string
902 * lpDest [O] Pointer to caller supplied storage for the multi byte string
903 * nMaxLen [I] Size, in bytes, of the destination buffer
906 * Length, in bytes, of the converted string.
909 INT
Str_GetPtrWtoA (LPCWSTR lpSrc
, LPSTR lpDest
, INT nMaxLen
)
913 TRACE("(%s %p %d)\n", debugstr_w(lpSrc
), lpDest
, nMaxLen
);
915 if (!lpDest
&& lpSrc
)
916 return WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
926 len
= WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, 0, 0, NULL
, NULL
);
930 WideCharToMultiByte(CP_ACP
, 0, lpSrc
, -1, lpDest
, len
, NULL
, NULL
);
936 /**************************************************************************
937 * Str_GetPtrAtoW [internal]
939 * Converts a multibyte string into a unicode string
942 * lpSrc [I] Pointer to the multibyte source string
943 * lpDest [O] Pointer to caller supplied storage for the unicode string
944 * nMaxLen [I] Size, in characters, of the destination buffer
947 * Length, in characters, of the converted string.
950 INT
Str_GetPtrAtoW (LPCSTR lpSrc
, LPWSTR lpDest
, INT nMaxLen
)
954 TRACE("(%s %p %d)\n", debugstr_a(lpSrc
), lpDest
, nMaxLen
);
956 if (!lpDest
&& lpSrc
)
957 return MultiByteToWideChar(CP_ACP
, 0, lpSrc
, -1, 0, 0);
967 len
= MultiByteToWideChar(CP_ACP
, 0, lpSrc
, -1, 0, 0);
971 MultiByteToWideChar(CP_ACP
, 0, lpSrc
, -1, lpDest
, len
);
978 /**************************************************************************
979 * Str_SetPtrAtoW [internal]
981 * Converts a multi byte string to a unicode string.
982 * If the pointer to the destination buffer is NULL a buffer is allocated.
983 * If the destination buffer is too small to keep the converted multi byte
984 * string the destination buffer is reallocated. If the source pointer is
985 * NULL, the destination buffer is freed.
988 * lppDest [I/O] pointer to a pointer to the destination buffer
989 * lpSrc [I] pointer to a multi byte string
992 * TRUE: conversion successful
995 BOOL
Str_SetPtrAtoW (LPWSTR
*lppDest
, LPCSTR lpSrc
)
997 TRACE("(%p %s)\n", lppDest
, lpSrc
);
1000 INT len
= MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,NULL
,0);
1001 LPWSTR ptr
= ReAlloc (*lppDest
, len
*sizeof(WCHAR
));
1005 MultiByteToWideChar(CP_ACP
,0,lpSrc
,-1,ptr
,len
);
1016 /**************************************************************************
1017 * Str_SetPtrWtoA [internal]
1019 * Converts a unicode string to a multi byte string.
1020 * If the pointer to the destination buffer is NULL a buffer is allocated.
1021 * If the destination buffer is too small to keep the converted wide
1022 * string the destination buffer is reallocated. If the source pointer is
1023 * NULL, the destination buffer is freed.
1026 * lppDest [I/O] pointer to a pointer to the destination buffer
1027 * lpSrc [I] pointer to a wide string
1030 * TRUE: conversion successful
1033 BOOL
Str_SetPtrWtoA (LPSTR
*lppDest
, LPCWSTR lpSrc
)
1035 TRACE("(%p %s)\n", lppDest
, debugstr_w(lpSrc
));
1038 INT len
= WideCharToMultiByte(CP_ACP
,0,lpSrc
,-1,NULL
,0,NULL
,FALSE
);
1039 LPSTR ptr
= ReAlloc (*lppDest
, len
*sizeof(CHAR
));
1043 WideCharToMultiByte(CP_ACP
,0,lpSrc
,-1,ptr
,len
,NULL
,FALSE
);
1055 /**************************************************************************
1056 * Notification functions
1059 typedef struct tagNOTIFYDATA
1067 } NOTIFYDATA
, *LPNOTIFYDATA
;
1070 /**************************************************************************
1071 * DoNotify [Internal]
1074 static LRESULT
DoNotify (const NOTIFYDATA
*lpNotify
, UINT uCode
, LPNMHDR lpHdr
)
1077 LPNMHDR lpNmh
= NULL
;
1080 TRACE("(%p %p %d %p 0x%08x)\n",
1081 lpNotify
->hwndFrom
, lpNotify
->hwndTo
, uCode
, lpHdr
,
1082 lpNotify
->dwParam5
);
1084 if (!lpNotify
->hwndTo
)
1087 if (lpNotify
->hwndFrom
== (HWND
)-1) {
1089 idFrom
= lpHdr
->idFrom
;
1092 if (lpNotify
->hwndFrom
)
1093 idFrom
= GetDlgCtrlID (lpNotify
->hwndFrom
);
1095 lpNmh
= (lpHdr
) ? lpHdr
: &nmhdr
;
1097 lpNmh
->hwndFrom
= lpNotify
->hwndFrom
;
1098 lpNmh
->idFrom
= idFrom
;
1099 lpNmh
->code
= uCode
;
1102 return SendMessageW (lpNotify
->hwndTo
, WM_NOTIFY
, idFrom
, (LPARAM
)lpNmh
);
1106 /**************************************************************************
1107 * SendNotify [COMCTL32.341]
1109 * Sends a WM_NOTIFY message to the specified window.
1112 * hwndTo [I] Window to receive the message
1113 * hwndFrom [I] Window that the message is from (see notes)
1114 * uCode [I] Notification code
1115 * lpHdr [I] The NMHDR and any additional information to send or NULL
1118 * Success: return value from notification
1122 * If hwndFrom is -1 then the identifier of the control sending the
1123 * message is taken from the NMHDR structure.
1124 * If hwndFrom is not -1 then lpHdr can be NULL.
1126 LRESULT WINAPI
SendNotify (HWND hwndTo
, HWND hwndFrom
, UINT uCode
, LPNMHDR lpHdr
)
1130 TRACE("(%p %p %d %p)\n",
1131 hwndTo
, hwndFrom
, uCode
, lpHdr
);
1133 notify
.hwndFrom
= hwndFrom
;
1134 notify
.hwndTo
= hwndTo
;
1135 notify
.dwParam5
= 0;
1136 notify
.dwParam6
= 0;
1138 return DoNotify (¬ify
, uCode
, lpHdr
);
1142 /**************************************************************************
1143 * SendNotifyEx [COMCTL32.342]
1145 * Sends a WM_NOTIFY message to the specified window.
1148 * hwndFrom [I] Window to receive the message
1149 * hwndTo [I] Window that the message is from
1150 * uCode [I] Notification code
1151 * lpHdr [I] The NMHDR and any additional information to send or NULL
1152 * dwParam5 [I] Unknown
1155 * Success: return value from notification
1159 * If hwndFrom is -1 then the identifier of the control sending the
1160 * message is taken from the NMHDR structure.
1161 * If hwndFrom is not -1 then lpHdr can be NULL.
1163 LRESULT WINAPI
SendNotifyEx (HWND hwndTo
, HWND hwndFrom
, UINT uCode
,
1164 LPNMHDR lpHdr
, DWORD dwParam5
)
1169 TRACE("(%p %p %d %p 0x%08x)\n",
1170 hwndFrom
, hwndTo
, uCode
, lpHdr
, dwParam5
);
1172 hwndNotify
= hwndTo
;
1174 if (IsWindow (hwndFrom
)) {
1175 hwndNotify
= GetParent (hwndFrom
);
1181 notify
.hwndFrom
= hwndFrom
;
1182 notify
.hwndTo
= hwndNotify
;
1183 notify
.dwParam5
= dwParam5
;
1184 notify
.dwParam6
= 0;
1186 return DoNotify (¬ify
, uCode
, lpHdr
);