Add a MsgWaitForMultipleObjects test.
[wine/wine-kai.git] / dlls / comctl32 / comctl32undoc.c
blob65e018e1c53ce9eb196e751498a6957b3f86dc6a
1 /*
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
22 * NOTES
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 #include "config.h"
30 #include "wine/port.h"
32 #include <stdarg.h>
33 #include <string.h>
34 #include <ctype.h>
35 #include <limits.h>
37 #define COBJMACROS
38 #define NONAMELESSUNION
39 #define NONAMELESSSTRUCT
41 #include "windef.h"
42 #include "winbase.h"
43 #include "wingdi.h"
44 #include "winuser.h"
45 #include "winnls.h"
46 #include "winreg.h"
47 #include "commctrl.h"
48 #include "objbase.h"
49 #include "winerror.h"
51 #include "wine/unicode.h"
52 #include "comctl32.h"
54 #include "wine/debug.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(commctrl);
58 static const WCHAR strMRUList[] = { 'M','R','U','L','i','s','t',0 };
60 /**************************************************************************
61 * Alloc [COMCTL32.71]
63 * Allocates memory block from the dll's private heap
65 * PARAMS
66 * dwSize [I] size of the allocated memory block
68 * RETURNS
69 * Success: pointer to allocated memory block
70 * Failure: NULL
72 LPVOID WINAPI Alloc (DWORD dwSize)
74 return LocalAlloc( LMEM_ZEROINIT, dwSize );
78 /**************************************************************************
79 * ReAlloc [COMCTL32.72]
81 * Changes the size of an allocated memory block or allocates a memory
82 * block using the dll's private heap.
84 * PARAMS
85 * lpSrc [I] pointer to memory block which will be resized
86 * dwSize [I] new size of the memory block.
88 * RETURNS
89 * Success: pointer to the resized memory block
90 * Failure: NULL
92 * NOTES
93 * If lpSrc is a NULL-pointer, then ReAlloc allocates a memory
94 * block like Alloc.
96 LPVOID WINAPI ReAlloc (LPVOID lpSrc, DWORD dwSize)
98 if (lpSrc)
99 return LocalReAlloc( lpSrc, dwSize, LMEM_ZEROINIT );
100 else
101 return LocalAlloc( LMEM_ZEROINIT, dwSize);
105 /**************************************************************************
106 * Free [COMCTL32.73]
108 * Frees an allocated memory block from the dll's private heap.
110 * PARAMS
111 * lpMem [I] pointer to memory block which will be freed
113 * RETURNS
114 * Success: TRUE
115 * Failure: FALSE
117 BOOL WINAPI Free (LPVOID lpMem)
119 return !LocalFree( lpMem );
123 /**************************************************************************
124 * GetSize [COMCTL32.74]
126 * Retrieves the size of the specified memory block from the dll's
127 * private heap.
129 * PARAMS
130 * lpMem [I] pointer to an allocated memory block
132 * RETURNS
133 * Success: size of the specified memory block
134 * Failure: 0
136 DWORD WINAPI GetSize (LPVOID lpMem)
138 return LocalSize( lpMem );
142 /**************************************************************************
143 * MRU-Functions {COMCTL32}
145 * NOTES
146 * The MRU-Api is a set of functions to manipulate lists of M.R.U. (Most Recently
147 * Used) items. It is an undocumented Api that is used (at least) by the shell
148 * and explorer to implement their recent documents feature.
150 * Since these functions are undocumented, they are unsupported by MS and
151 * may change at any time.
153 * Internally, the list is implemented as a last in, last out list of items
154 * persisted into the system registry under a caller chosen key. Each list
155 * item is given a one character identifier in the Ascii range from 'a' to
156 * '}'. A list of the identifiers in order from newest to oldest is stored
157 * under the same key in a value named "MRUList".
159 * Items are re-ordered by changing the order of the values in the MRUList
160 * value. When a new item is added, it becomes the new value of the oldest
161 * identifier, and that identifier is moved to the front of the MRUList value.
163 * Wine stores MRU-lists in the same registry format as Windows, so when
164 * switching between the builtin and native comctl32.dll no problems or
165 * incompatibilities should occur.
167 * The following undocumented structure is used to create an MRU-list:
168 *|typedef INT (CALLBACK *MRUStringCmpFn)(LPCTSTR lhs, LPCTSTR rhs);
169 *|typedef INT (CALLBACK *MRUBinaryCmpFn)(LPCVOID lhs, LPCVOID rhs, DWORD length);
171 *|typedef struct tagCREATEMRULIST
173 *| DWORD cbSize;
174 *| DWORD nMaxItems;
175 *| DWORD dwFlags;
176 *| HKEY hKey;
177 *| LPCTSTR lpszSubKey;
178 *| PROC lpfnCompare;
179 *|} CREATEMRULIST, *LPCREATEMRULIST;
181 * MEMBERS
182 * cbSize [I] The size of the CREATEMRULIST structure. This must be set
183 * to sizeof(CREATEMRULIST) by the caller.
184 * nMaxItems [I] The maximum number of items allowed in the list. Because
185 * of the limited number of identifiers, this should be set to
186 * a value from 1 to 30 by the caller.
187 * dwFlags [I] If bit 0 is set, the list will be used to store binary
188 * data, otherwise it is assumed to store strings. If bit 1
189 * is set, every change made to the list will be reflected in
190 * the registry immediately, otherwise changes will only be
191 * written when the list is closed.
192 * hKey [I] The registry key that the list should be written under.
193 * This must be supplied by the caller.
194 * lpszSubKey [I] A caller supplied name of a subkey under hKey to write
195 * the list to. This may not be blank.
196 * lpfnCompare [I] A caller supplied comparison function, which may be either
197 * an MRUStringCmpFn if dwFlags does not have bit 0 set, or a
198 * MRUBinaryCmpFn otherwise.
200 * FUNCTIONS
201 * - Create an MRU-list with CreateMRUList() or CreateMRUListLazy().
202 * - Add items to an MRU-list with AddMRUString() or AddMRUData().
203 * - Remove items from an MRU-list with DelMRUString().
204 * - Find data in an MRU-list with FindMRUString() or FindMRUData().
205 * - Iterate through an MRU-list with EnumMRUList().
206 * - Free an MRU-list with FreeMRUList().
209 typedef struct tagCREATEMRULISTA
211 DWORD cbSize;
212 DWORD nMaxItems;
213 DWORD dwFlags;
214 HKEY hKey;
215 LPCSTR lpszSubKey;
216 PROC lpfnCompare;
217 } CREATEMRULISTA, *LPCREATEMRULISTA;
219 typedef struct tagCREATEMRULISTW
221 DWORD cbSize;
222 DWORD nMaxItems;
223 DWORD dwFlags;
224 HKEY hKey;
225 LPCWSTR lpszSubKey;
226 PROC lpfnCompare;
227 } CREATEMRULISTW, *LPCREATEMRULISTW;
229 /* dwFlags */
230 #define MRUF_STRING_LIST 0 /* list will contain strings */
231 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
232 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
234 /* If list is a string list lpfnCompare has the following prototype
235 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
236 * for binary lists the prototype is
237 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
238 * where cbData is the no. of bytes to compare.
239 * Need to check what return value means identical - 0?
242 typedef struct tagWINEMRUITEM
244 DWORD size; /* size of data stored */
245 DWORD itemFlag; /* flags */
246 BYTE datastart;
247 } WINEMRUITEM, *LPWINEMRUITEM;
249 /* itemFlag */
250 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
252 typedef struct tagWINEMRULIST
254 CREATEMRULISTW extview; /* original create information */
255 BOOL isUnicode; /* is compare fn Unicode */
256 DWORD wineFlags; /* internal flags */
257 DWORD cursize; /* current size of realMRU */
258 LPWSTR realMRU; /* pointer to string of index names */
259 LPWINEMRUITEM *array; /* array of pointers to data */
260 /* in 'a' to 'z' order */
261 } WINEMRULIST, *LPWINEMRULIST;
263 /* wineFlags */
264 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
266 /**************************************************************************
267 * MRU_SaveChanged (internal)
269 * Local MRU saving code
271 static void MRU_SaveChanged ( LPWINEMRULIST mp )
273 UINT i, err;
274 HKEY newkey;
275 WCHAR realname[2];
276 LPWINEMRUITEM witem;
277 static const WCHAR emptyW[] = {'\0'};
279 /* or should we do the following instead of RegOpenKeyEx:
282 /* open the sub key */
283 if ((err = RegOpenKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
284 0, KEY_WRITE, &newkey))) {
285 /* not present - what to do ??? */
286 ERR("Could not open key, error=%d, attempting to create\n",
287 err);
288 if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
290 emptyW,
291 REG_OPTION_NON_VOLATILE,
292 KEY_READ | KEY_WRITE,
294 &newkey,
295 0))) {
296 ERR("failed to create key /%s/, err=%d\n",
297 debugstr_w(mp->extview.lpszSubKey), err);
298 return;
301 if (mp->wineFlags & WMRUF_CHANGED) {
302 mp->wineFlags &= ~WMRUF_CHANGED;
303 err = RegSetValueExW(newkey, strMRUList, 0, REG_SZ, (LPBYTE)mp->realMRU,
304 (strlenW(mp->realMRU) + 1)*sizeof(WCHAR));
305 if (err) {
306 ERR("error saving MRUList, err=%d\n", err);
308 TRACE("saving MRUList=/%s/\n", debugstr_w(mp->realMRU));
310 realname[1] = 0;
311 for(i=0; i<mp->cursize; i++) {
312 witem = mp->array[i];
313 if (witem->itemFlag & WMRUIF_CHANGED) {
314 witem->itemFlag &= ~WMRUIF_CHANGED;
315 realname[0] = 'a' + i;
316 err = RegSetValueExW(newkey, realname, 0,
317 (mp->extview.dwFlags & MRUF_BINARY_LIST) ?
318 REG_BINARY : REG_SZ,
319 &witem->datastart, witem->size);
320 if (err) {
321 ERR("error saving /%s/, err=%d\n", debugstr_w(realname), err);
323 TRACE("saving value for name /%s/ size=%ld\n",
324 debugstr_w(realname), witem->size);
327 RegCloseKey( newkey );
330 /**************************************************************************
331 * FreeMRUList [COMCTL32.152]
333 * Frees a most-recently-used items list.
335 * PARAMS
336 * hMRUList [I] Handle to list.
338 * RETURNS
339 * Nothing.
341 void WINAPI FreeMRUList (HANDLE hMRUList)
343 LPWINEMRULIST mp = (LPWINEMRULIST)hMRUList;
344 UINT i;
346 TRACE("(%p)\n", hMRUList);
347 if (!hMRUList)
348 return;
350 if (mp->wineFlags & WMRUF_CHANGED) {
351 /* need to open key and then save the info */
352 MRU_SaveChanged( mp );
355 for(i=0; i<mp->extview.nMaxItems; i++) {
356 if (mp->array[i])
357 Free(mp->array[i]);
359 Free(mp->realMRU);
360 Free(mp->array);
361 Free((LPWSTR)mp->extview.lpszSubKey);
362 Free(mp);
366 /**************************************************************************
367 * FindMRUData [COMCTL32.169]
369 * Searches binary list for item that matches lpData of length cbData.
370 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
371 * corresponding to item's reg. name will be stored in it ('a' -> 0).
373 * PARAMS
374 * hList [I] list handle
375 * lpData [I] data to find
376 * cbData [I] length of data
377 * lpRegNum [O] position in registry (maybe NULL)
379 * RETURNS
380 * Position in list 0 -> MRU. -1 if item not found.
382 INT WINAPI FindMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData,
383 LPINT lpRegNum)
385 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
386 INT ret;
387 UINT i;
388 LPSTR dataA = NULL;
390 if (!mp->extview.lpfnCompare) {
391 ERR("MRU list not properly created. No compare procedure.\n");
392 return -1;
395 if(!(mp->extview.dwFlags & MRUF_BINARY_LIST) && !mp->isUnicode) {
396 DWORD len = WideCharToMultiByte(CP_ACP, 0, lpData, -1,
397 NULL, 0, NULL, NULL);
398 dataA = Alloc(len);
399 WideCharToMultiByte(CP_ACP, 0, lpData, -1, dataA, len, NULL, NULL);
402 for(i=0; i<mp->cursize; i++) {
403 if (mp->extview.dwFlags & MRUF_BINARY_LIST) {
404 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart,
405 cbData))
406 break;
408 else {
409 if(mp->isUnicode) {
410 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart))
411 break;
412 } else {
413 DWORD len = WideCharToMultiByte(CP_ACP, 0,
414 (LPWSTR)&mp->array[i]->datastart, -1,
415 NULL, 0, NULL, NULL);
416 LPSTR itemA = Alloc(len);
417 INT cmp;
418 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&mp->array[i]->datastart, -1,
419 itemA, len, NULL, NULL);
421 cmp = mp->extview.lpfnCompare(dataA, itemA);
422 Free(itemA);
423 if(!cmp)
424 break;
428 if(dataA)
429 Free(dataA);
430 if (i < mp->cursize)
431 ret = i;
432 else
433 ret = -1;
434 if (lpRegNum && (ret != -1))
435 *lpRegNum = 'a' + i;
437 TRACE("(%p, %p, %ld, %p) returning %d\n",
438 hList, lpData, cbData, lpRegNum, ret);
440 return ret;
444 /**************************************************************************
445 * AddMRUData [COMCTL32.167]
447 * Add item to MRU binary list. If item already exists in list then it is
448 * simply moved up to the top of the list and not added again. If list is
449 * full then the least recently used item is removed to make room.
451 * PARAMS
452 * hList [I] Handle to list.
453 * lpData [I] ptr to data to add.
454 * cbData [I] no. of bytes of data.
456 * RETURNS
457 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
458 * -1 on error.
460 INT WINAPI AddMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData)
462 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
463 LPWINEMRUITEM witem;
464 INT i, replace;
466 if ((replace = FindMRUData (hList, lpData, cbData, NULL)) >= 0) {
467 /* Item exists, just move it to the front */
468 LPWSTR pos = strchrW(mp->realMRU, replace + 'a');
469 while (pos > mp->realMRU)
471 pos[0] = pos[-1];
472 pos--;
475 else {
476 /* either add a new entry or replace oldest */
477 if (mp->cursize < mp->extview.nMaxItems) {
478 /* Add in a new item */
479 replace = mp->cursize;
480 mp->cursize++;
482 else {
483 /* get the oldest entry and replace data */
484 replace = mp->realMRU[mp->cursize - 1] - 'a';
485 Free(mp->array[replace]);
488 /* Allocate space for new item and move in the data */
489 mp->array[replace] = witem = Alloc(cbData + sizeof(WINEMRUITEM));
490 witem->itemFlag |= WMRUIF_CHANGED;
491 witem->size = cbData;
492 memcpy( &witem->datastart, lpData, cbData);
494 /* now rotate MRU list */
495 for(i=mp->cursize-1; i>=1; i--)
496 mp->realMRU[i] = mp->realMRU[i-1];
499 /* The new item gets the front spot */
500 mp->wineFlags |= WMRUF_CHANGED;
501 mp->realMRU[0] = replace + 'a';
503 TRACE("(%p, %p, %ld) adding data, /%c/ now most current\n",
504 hList, lpData, cbData, replace+'a');
506 if (!(mp->extview.dwFlags & MRUF_DELAYED_SAVE)) {
507 /* save changed stuff right now */
508 MRU_SaveChanged( mp );
511 return replace;
514 /**************************************************************************
515 * AddMRUStringW [COMCTL32.401]
517 * Add an item to an MRU string list.
519 * PARAMS
520 * hList [I] Handle to list.
521 * lpszString [I] The string to add.
523 * RETURNS
524 * Success: The number corresponding to the registry name where the string
525 * has been stored (0 maps to 'a', 1 to 'b' and so on).
526 * Failure: -1, if hList is NULL or memory allocation fails. If lpszString
527 * is invalid, the function returns 0, and GetLastError() returns
528 * ERROR_INVALID_PARAMETER. The last error value is set only in
529 * this case.
531 * NOTES
532 * -If lpszString exists in the list already, it is moved to the top of the
533 * MRU list (it is not duplicated).
534 * -If the list is full the least recently used list entry is replaced with
535 * lpszString.
536 * -If this function returns 0 you should check the last error value to
537 * ensure the call really succeeded.
539 INT WINAPI AddMRUStringW(HANDLE hList, LPCWSTR lpszString)
541 TRACE("(%p,%s)\n", hList, debugstr_w(lpszString));
543 if (!hList)
544 return -1;
546 if (!lpszString || IsBadStringPtrW(lpszString, -1))
548 SetLastError(ERROR_INVALID_PARAMETER);
549 return 0;
552 return AddMRUData(hList, lpszString,
553 (strlenW(lpszString) + 1) * sizeof(WCHAR));
556 /**************************************************************************
557 * AddMRUStringA [COMCTL32.153]
559 * See AddMRUStringW.
561 INT WINAPI AddMRUStringA(HANDLE hList, LPCSTR lpszString)
563 DWORD len;
564 LPWSTR stringW;
565 INT ret;
567 TRACE("(%p,%s)\n", hList, debugstr_a(lpszString));
569 if (!hList)
570 return -1;
572 if (IsBadStringPtrA(lpszString, -1))
574 SetLastError(ERROR_INVALID_PARAMETER);
575 return 0;
578 len = MultiByteToWideChar(CP_ACP, 0, lpszString, -1, NULL, 0) * sizeof(WCHAR);
579 stringW = Alloc(len);
580 if (!stringW)
581 return -1;
583 MultiByteToWideChar(CP_ACP, 0, lpszString, -1, stringW, len);
584 ret = AddMRUData(hList, stringW, len);
585 Free(stringW);
586 return ret;
589 /**************************************************************************
590 * DelMRUString [COMCTL32.156]
592 * Removes item from either string or binary list (despite its name)
594 * PARAMS
595 * hList [I] list handle
596 * nItemPos [I] item position to remove 0 -> MRU
598 * RETURNS
599 * TRUE if successful, FALSE if nItemPos is out of range.
601 BOOL WINAPI DelMRUString(HANDLE hList, INT nItemPos)
603 FIXME("(%p, %d): stub\n", hList, nItemPos);
604 return TRUE;
607 /**************************************************************************
608 * FindMRUStringW [COMCTL32.402]
610 * See FindMRUStringA.
612 INT WINAPI FindMRUStringW (HANDLE hList, LPCWSTR lpszString, LPINT lpRegNum)
614 return FindMRUData(hList, lpszString,
615 (lstrlenW(lpszString) + 1) * sizeof(WCHAR), lpRegNum);
618 /**************************************************************************
619 * FindMRUStringA [COMCTL32.155]
621 * Searches string list for item that matches lpszString.
622 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
623 * corresponding to item's reg. name will be stored in it ('a' -> 0).
625 * PARAMS
626 * hList [I] list handle
627 * lpszString [I] string to find
628 * lpRegNum [O] position in registry (maybe NULL)
630 * RETURNS
631 * Position in list 0 -> MRU. -1 if item not found.
633 INT WINAPI FindMRUStringA (HANDLE hList, LPCSTR lpszString, LPINT lpRegNum)
635 DWORD len = MultiByteToWideChar(CP_ACP, 0, lpszString, -1, NULL, 0);
636 LPWSTR stringW = Alloc(len * sizeof(WCHAR));
637 INT ret;
639 MultiByteToWideChar(CP_ACP, 0, lpszString, -1, stringW, len);
640 ret = FindMRUData(hList, stringW, len * sizeof(WCHAR), lpRegNum);
641 Free(stringW);
642 return ret;
645 /*************************************************************************
646 * CreateMRUListLazy_common (internal)
648 static HANDLE CreateMRUListLazy_common(LPWINEMRULIST mp)
650 UINT i, err;
651 HKEY newkey;
652 DWORD datasize, dwdisp;
653 WCHAR realname[2];
654 LPWINEMRUITEM witem;
655 DWORD type;
656 static const WCHAR emptyW[] = {'\0'};
658 /* get space to save indices that will turn into names
659 * but in order of most to least recently used
661 mp->realMRU = Alloc((mp->extview.nMaxItems + 2) * sizeof(WCHAR));
663 /* get space to save pointers to actual data in order of
664 * 'a' to 'z' (0 to n).
666 mp->array = Alloc(mp->extview.nMaxItems * sizeof(LPVOID));
668 /* open the sub key */
669 if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
671 emptyW,
672 REG_OPTION_NON_VOLATILE,
673 KEY_READ | KEY_WRITE,
675 &newkey,
676 &dwdisp))) {
677 /* error - what to do ??? */
678 ERR("(%lu %lu %lx %lx \"%s\" %p): Could not open key, error=%d\n",
679 mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
680 (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
681 mp->extview.lpfnCompare, err);
682 return 0;
685 /* get values from key 'MRUList' */
686 if (newkey) {
687 datasize = mp->extview.nMaxItems + 1;
688 if((err=RegQueryValueExW( newkey, strMRUList, 0, &type,
689 (LPBYTE)mp->realMRU, &datasize))) {
690 /* not present - set size to 1 (will become 0 later) */
691 datasize = 1;
692 *mp->realMRU = 0;
695 TRACE("MRU list = %s, datasize = %ld\n", debugstr_w(mp->realMRU), datasize);
697 mp->cursize = datasize - 1;
698 /* datasize now has number of items in the MRUList */
700 /* get actual values for each entry */
701 realname[1] = 0;
702 for(i=0; i<mp->cursize; i++) {
703 realname[0] = 'a' + i;
704 if(RegQueryValueExW( newkey, realname, 0, &type, 0, &datasize)) {
705 /* not present - what to do ??? */
706 ERR("Key %s not found 1\n", debugstr_w(realname));
708 mp->array[i] = witem = Alloc(datasize + sizeof(WINEMRUITEM));
709 witem->size = datasize;
710 if(RegQueryValueExW( newkey, realname, 0, &type,
711 &witem->datastart, &datasize)) {
712 /* not present - what to do ??? */
713 ERR("Key %s not found 2\n", debugstr_w(realname));
716 RegCloseKey( newkey );
718 else
719 mp->cursize = 0;
721 TRACE("(%lu %lu %lx %lx \"%s\" %p): Current Size = %ld\n",
722 mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags,
723 (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey),
724 mp->extview.lpfnCompare, mp->cursize);
725 return (HANDLE)mp;
728 /**************************************************************************
729 * CreateMRUListLazyW [COMCTL32.404]
731 * See CreateMRUListLazyA.
733 HANDLE WINAPI CreateMRUListLazyW (LPCREATEMRULISTW lpcml, DWORD dwParam2,
734 DWORD dwParam3, DWORD dwParam4)
736 LPWINEMRULIST mp;
738 /* Native does not check for a NULL lpcml */
740 if (lpcml->cbSize != sizeof(CREATEMRULISTW) || !lpcml->hKey ||
741 IsBadStringPtrW(lpcml->lpszSubKey, -1))
742 return NULL;
744 mp = Alloc(sizeof(WINEMRULIST));
745 memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
746 mp->extview.lpszSubKey = Alloc((strlenW(lpcml->lpszSubKey) + 1) * sizeof(WCHAR));
747 strcpyW((LPWSTR)mp->extview.lpszSubKey, lpcml->lpszSubKey);
748 mp->isUnicode = TRUE;
750 return CreateMRUListLazy_common(mp);
753 /**************************************************************************
754 * CreateMRUListLazyA [COMCTL32.157]
756 * Creates a most-recently-used list.
758 * PARAMS
759 * lpcml [I] ptr to CREATEMRULIST structure.
760 * dwParam2 [I] Unknown
761 * dwParam3 [I] Unknown
762 * dwParam4 [I] Unknown
764 * RETURNS
765 * Handle to MRU list.
767 HANDLE WINAPI CreateMRUListLazyA (LPCREATEMRULISTA lpcml, DWORD dwParam2,
768 DWORD dwParam3, DWORD dwParam4)
770 LPWINEMRULIST mp;
771 DWORD len;
773 /* Native does not check for a NULL lpcml */
775 if (lpcml->cbSize != sizeof(CREATEMRULISTA) || !lpcml->hKey ||
776 IsBadStringPtrA(lpcml->lpszSubKey, -1))
777 return 0;
779 mp = Alloc(sizeof(WINEMRULIST));
780 memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW));
781 len = MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1, NULL, 0);
782 mp->extview.lpszSubKey = Alloc(len * sizeof(WCHAR));
783 MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1,
784 (LPWSTR)mp->extview.lpszSubKey, len);
785 mp->isUnicode = FALSE;
786 return CreateMRUListLazy_common(mp);
789 /**************************************************************************
790 * CreateMRUListW [COMCTL32.400]
792 * See CreateMRUListA.
794 HANDLE WINAPI CreateMRUListW (LPCREATEMRULISTW lpcml)
796 return CreateMRUListLazyW(lpcml, 0, 0, 0);
799 /**************************************************************************
800 * CreateMRUListA [COMCTL32.151]
802 * Creates a most-recently-used list.
804 * PARAMS
805 * lpcml [I] ptr to CREATEMRULIST structure.
807 * RETURNS
808 * Handle to MRU list.
810 HANDLE WINAPI CreateMRUListA (LPCREATEMRULISTA lpcml)
812 return CreateMRUListLazyA (lpcml, 0, 0, 0);
816 /**************************************************************************
817 * EnumMRUListW [COMCTL32.403]
819 * Enumerate item in a most-recenty-used list
821 * PARAMS
822 * hList [I] list handle
823 * nItemPos [I] item position to enumerate
824 * lpBuffer [O] buffer to receive item
825 * nBufferSize [I] size of buffer
827 * RETURNS
828 * For binary lists specifies how many bytes were copied to buffer, for
829 * string lists specifies full length of string. Enumerating past the end
830 * of list returns -1.
831 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
832 * the list.
834 INT WINAPI EnumMRUListW (HANDLE hList, INT nItemPos, LPVOID lpBuffer,
835 DWORD nBufferSize)
837 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
838 LPWINEMRUITEM witem;
839 INT desired, datasize;
841 if (nItemPos >= mp->cursize) return -1;
842 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
843 desired = mp->realMRU[nItemPos];
844 desired -= 'a';
845 TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
846 witem = mp->array[desired];
847 datasize = min( witem->size, nBufferSize );
848 memcpy( lpBuffer, &witem->datastart, datasize);
849 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
850 hList, nItemPos, lpBuffer, nBufferSize, datasize);
851 return datasize;
854 /**************************************************************************
855 * EnumMRUListA [COMCTL32.154]
857 * See EnumMRUListW.
859 INT WINAPI EnumMRUListA (HANDLE hList, INT nItemPos, LPVOID lpBuffer,
860 DWORD nBufferSize)
862 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
863 LPWINEMRUITEM witem;
864 INT desired, datasize;
865 DWORD lenA;
867 if (nItemPos >= mp->cursize) return -1;
868 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
869 desired = mp->realMRU[nItemPos];
870 desired -= 'a';
871 TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired);
872 witem = mp->array[desired];
873 if(mp->extview.dwFlags & MRUF_BINARY_LIST) {
874 datasize = min( witem->size, nBufferSize );
875 memcpy( lpBuffer, &witem->datastart, datasize);
876 } else {
877 lenA = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
878 NULL, 0, NULL, NULL);
879 datasize = min( witem->size, nBufferSize );
880 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1,
881 lpBuffer, datasize, NULL, NULL);
883 TRACE("(%p, %d, %p, %ld): returning len=%d\n",
884 hList, nItemPos, lpBuffer, nBufferSize, datasize);
885 return datasize;
889 /**************************************************************************
890 * Str_GetPtrA [COMCTL32.233]
892 * Copies a string into a destination buffer.
894 * PARAMS
895 * lpSrc [I] Source string
896 * lpDest [O] Destination buffer
897 * nMaxLen [I] Size of buffer in characters
899 * RETURNS
900 * The number of characters copied.
902 INT WINAPI Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen)
904 INT len;
906 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
908 if (!lpDest && lpSrc)
909 return strlen (lpSrc);
911 if (nMaxLen == 0)
912 return 0;
914 if (lpSrc == NULL) {
915 lpDest[0] = '\0';
916 return 0;
919 len = strlen (lpSrc);
920 if (len >= nMaxLen)
921 len = nMaxLen - 1;
923 RtlMoveMemory (lpDest, lpSrc, len);
924 lpDest[len] = '\0';
926 return len;
930 /**************************************************************************
931 * Str_SetPtrA [COMCTL32.234]
933 * Makes a copy of a string, allocating memory if necessary.
935 * PARAMS
936 * lppDest [O] Pointer to destination string
937 * lpSrc [I] Source string
939 * RETURNS
940 * Success: TRUE
941 * Failure: FALSE
943 * NOTES
944 * Set lpSrc to NULL to free the memory allocated by a previous call
945 * to this function.
947 BOOL WINAPI Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc)
949 TRACE("(%p %p)\n", lppDest, lpSrc);
951 if (lpSrc) {
952 LPSTR ptr = ReAlloc (*lppDest, strlen (lpSrc) + 1);
953 if (!ptr)
954 return FALSE;
955 strcpy (ptr, lpSrc);
956 *lppDest = ptr;
958 else {
959 if (*lppDest) {
960 Free (*lppDest);
961 *lppDest = NULL;
965 return TRUE;
969 /**************************************************************************
970 * Str_GetPtrW [COMCTL32.235]
972 * See Str_GetPtrA.
974 INT WINAPI Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
976 INT len;
978 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
980 if (!lpDest && lpSrc)
981 return strlenW (lpSrc);
983 if (nMaxLen == 0)
984 return 0;
986 if (lpSrc == NULL) {
987 lpDest[0] = L'\0';
988 return 0;
991 len = strlenW (lpSrc);
992 if (len >= nMaxLen)
993 len = nMaxLen - 1;
995 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
996 lpDest[len] = L'\0';
998 return len;
1002 /**************************************************************************
1003 * Str_SetPtrW [COMCTL32.236]
1005 * See Str_SetPtrA.
1007 BOOL WINAPI Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
1009 TRACE("(%p %p)\n", lppDest, lpSrc);
1011 if (lpSrc) {
1012 INT len = strlenW (lpSrc) + 1;
1013 LPWSTR ptr = ReAlloc (*lppDest, len * sizeof(WCHAR));
1014 if (!ptr)
1015 return FALSE;
1016 strcpyW (ptr, lpSrc);
1017 *lppDest = ptr;
1019 else {
1020 if (*lppDest) {
1021 Free (*lppDest);
1022 *lppDest = NULL;
1026 return TRUE;
1030 /**************************************************************************
1031 * Str_GetPtrWtoA [internal]
1033 * Converts a unicode string into a multi byte string
1035 * PARAMS
1036 * lpSrc [I] Pointer to the unicode source string
1037 * lpDest [O] Pointer to caller supplied storage for the multi byte string
1038 * nMaxLen [I] Size, in bytes, of the destination buffer
1040 * RETURNS
1041 * Length, in bytes, of the converted string.
1044 INT Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1046 INT len;
1048 TRACE("(%s %p %d)\n", debugstr_w(lpSrc), lpDest, nMaxLen);
1050 if (!lpDest && lpSrc)
1051 return WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1053 if (nMaxLen == 0)
1054 return 0;
1056 if (lpSrc == NULL) {
1057 lpDest[0] = '\0';
1058 return 0;
1061 len = WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1062 if (len >= nMaxLen)
1063 len = nMaxLen - 1;
1065 WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, lpDest, len, NULL, NULL);
1066 lpDest[len] = '\0';
1068 return len;
1072 /**************************************************************************
1073 * Str_SetPtrAtoW [internal]
1075 * Converts a multi byte string to a unicode string.
1076 * If the pointer to the destination buffer is NULL a buffer is allocated.
1077 * If the destination buffer is too small to keep the converted multi byte
1078 * string the destination buffer is reallocated. If the source pointer is
1079 * NULL, the destination buffer is freed.
1081 * PARAMS
1082 * lppDest [I/O] pointer to a pointer to the destination buffer
1083 * lpSrc [I] pointer to a multi byte string
1085 * RETURNS
1086 * TRUE: conversion successful
1087 * FALSE: error
1089 BOOL Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc)
1091 TRACE("(%p %s)\n", lppDest, lpSrc);
1093 if (lpSrc) {
1094 INT len = MultiByteToWideChar(CP_ACP,0,lpSrc,-1,NULL,0);
1095 LPWSTR ptr = ReAlloc (*lppDest, len*sizeof(WCHAR));
1097 if (!ptr)
1098 return FALSE;
1099 MultiByteToWideChar(CP_ACP,0,lpSrc,-1,ptr,len);
1100 *lppDest = ptr;
1102 else {
1103 if (*lppDest) {
1104 Free (*lppDest);
1105 *lppDest = NULL;
1109 return TRUE;
1113 /**************************************************************************
1114 * Notification functions
1117 typedef struct tagNOTIFYDATA
1119 HWND hwndFrom;
1120 HWND hwndTo;
1121 DWORD dwParam3;
1122 DWORD dwParam4;
1123 DWORD dwParam5;
1124 DWORD dwParam6;
1125 } NOTIFYDATA, *LPNOTIFYDATA;
1128 /**************************************************************************
1129 * DoNotify [Internal]
1132 static LRESULT DoNotify (LPNOTIFYDATA lpNotify, UINT uCode, LPNMHDR lpHdr)
1134 NMHDR nmhdr;
1135 LPNMHDR lpNmh = NULL;
1136 UINT idFrom = 0;
1138 TRACE("(%p %p %d %p 0x%08lx)\n",
1139 lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr,
1140 lpNotify->dwParam5);
1142 if (!lpNotify->hwndTo)
1143 return 0;
1145 if (lpNotify->hwndFrom == (HWND)-1) {
1146 lpNmh = lpHdr;
1147 idFrom = lpHdr->idFrom;
1149 else {
1150 if (lpNotify->hwndFrom)
1151 idFrom = GetDlgCtrlID (lpNotify->hwndFrom);
1153 lpNmh = (lpHdr) ? lpHdr : &nmhdr;
1155 lpNmh->hwndFrom = lpNotify->hwndFrom;
1156 lpNmh->idFrom = idFrom;
1157 lpNmh->code = uCode;
1160 return SendMessageW (lpNotify->hwndTo, WM_NOTIFY, idFrom, (LPARAM)lpNmh);
1164 /**************************************************************************
1165 * SendNotify [COMCTL32.341]
1167 * Sends a WM_NOTIFY message to the specified window.
1169 * PARAMS
1170 * hwndTo [I] Window to receive the message
1171 * hwndFrom [I] Window that the message is from (see notes)
1172 * uCode [I] Notification code
1173 * lpHdr [I] The NMHDR and any additional information to send or NULL
1175 * RETURNS
1176 * Success: return value from notification
1177 * Failure: 0
1179 * NOTES
1180 * If hwndFrom is -1 then the identifier of the control sending the
1181 * message is taken from the NMHDR structure.
1182 * If hwndFrom is not -1 then lpHdr can be NULL.
1184 LRESULT WINAPI SendNotify (HWND hwndTo, HWND hwndFrom, UINT uCode, LPNMHDR lpHdr)
1186 NOTIFYDATA notify;
1188 TRACE("(%p %p %d %p)\n",
1189 hwndTo, hwndFrom, uCode, lpHdr);
1191 notify.hwndFrom = hwndFrom;
1192 notify.hwndTo = hwndTo;
1193 notify.dwParam5 = 0;
1194 notify.dwParam6 = 0;
1196 return DoNotify (&notify, uCode, lpHdr);
1200 /**************************************************************************
1201 * SendNotifyEx [COMCTL32.342]
1203 * Sends a WM_NOTIFY message to the specified window.
1205 * PARAMS
1206 * hwndFrom [I] Window to receive the message
1207 * hwndTo [I] Window that the message is from
1208 * uCode [I] Notification code
1209 * lpHdr [I] The NMHDR and any additional information to send or NULL
1210 * dwParam5 [I] Unknown
1212 * RETURNS
1213 * Success: return value from notification
1214 * Failure: 0
1216 * NOTES
1217 * If hwndFrom is -1 then the identifier of the control sending the
1218 * message is taken from the NMHDR structure.
1219 * If hwndFrom is not -1 then lpHdr can be NULL.
1221 LRESULT WINAPI SendNotifyEx (HWND hwndTo, HWND hwndFrom, UINT uCode,
1222 LPNMHDR lpHdr, DWORD dwParam5)
1224 NOTIFYDATA notify;
1225 HWND hwndNotify;
1227 TRACE("(%p %p %d %p 0x%08lx)\n",
1228 hwndFrom, hwndTo, uCode, lpHdr, dwParam5);
1230 hwndNotify = hwndTo;
1231 if (!hwndTo) {
1232 if (IsWindow (hwndFrom)) {
1233 hwndNotify = GetParent (hwndFrom);
1234 if (!hwndNotify)
1235 return 0;
1239 notify.hwndFrom = hwndFrom;
1240 notify.hwndTo = hwndNotify;
1241 notify.dwParam5 = dwParam5;
1242 notify.dwParam6 = 0;
1244 return DoNotify (&notify, uCode, lpHdr);