There is no need for a private heap in comctl32, memory allocations
[wine/multimedia.git] / dlls / comctl32 / comctl32undoc.c
blob6a4186eb880a6fb8768226f3f3f58117b0e11308
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).
28 * TODO
29 * - Add more functions.
30 * - Write some documentation.
32 #include "config.h"
33 #include "wine/port.h"
35 #include <stdarg.h>
36 #include <string.h>
37 #include <stdlib.h> /* atoi */
38 #include <ctype.h>
39 #include <limits.h>
41 #define NONAMELESSUNION
42 #define NONAMELESSSTRUCT
43 #include "windef.h"
44 #include "winbase.h"
45 #include "wingdi.h"
46 #include "winuser.h"
47 #include "winnls.h"
48 #include "winreg.h"
49 #include "commctrl.h"
50 #include "objbase.h"
51 #include "winerror.h"
53 #include "wine/unicode.h"
54 #include "comctl32.h"
56 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(commctrl);
60 struct _DSA
62 INT nItemCount;
63 LPVOID pData;
64 INT nMaxCount;
65 INT nItemSize;
66 INT nGrow;
69 struct _DPA
71 INT nItemCount;
72 LPVOID *ptrs;
73 HANDLE hHeap;
74 INT nGrow;
75 INT nMaxCount;
78 typedef struct _STREAMDATA
80 DWORD dwSize;
81 DWORD dwData2;
82 DWORD dwItems;
83 } STREAMDATA, *PSTREAMDATA;
85 typedef struct _LOADDATA
87 INT nCount;
88 PVOID ptr;
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
98 * PARAMS
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
104 * NOTES
105 * No more information available yet!
108 HRESULT WINAPI
109 DPA_LoadStream (HDPA *phDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam)
111 HRESULT errCode;
112 LARGE_INTEGER position;
113 ULARGE_INTEGER newPosition;
114 STREAMDATA streamData;
115 LOADDATA loadData;
116 ULONG ulRead;
117 HDPA hDpa;
118 PVOID *ptr;
120 FIXME ("phDpa=%p loadProc=%p pStream=%p lParam=%lx\n",
121 phDpa, loadProc, pStream, lParam);
123 if (!phDpa || !loadProc || !pStream)
124 return E_INVALIDARG;
126 *phDpa = (HDPA)NULL;
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);
136 if (errCode != S_OK)
137 return errCode;
139 errCode = IStream_Read (pStream, &streamData, sizeof(STREAMDATA), &ulRead);
140 if (errCode != S_OK)
141 return errCode;
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) {
150 errCode = E_FAIL;
153 if (streamData.dwItems > (UINT_MAX / 2 / sizeof(VOID*))) /* 536870911 */
154 return E_OUTOFMEMORY;
156 /* create the dpa */
157 hDpa = DPA_Create (streamData.dwItems);
158 if (!hDpa)
159 return E_OUTOFMEMORY;
161 if (!DPA_Grow (hDpa, streamData.dwItems))
162 return E_OUTOFMEMORY;
164 /* load data from the stream into the dpa */
165 ptr = hDpa->ptrs;
166 for (loadData.nCount = 0; loadData.nCount < streamData.dwItems; loadData.nCount++) {
167 errCode = (loadProc)(&loadData, pStream, lParam);
168 if (errCode != S_OK) {
169 errCode = S_FALSE;
170 break;
173 *ptr = loadData.ptr;
174 ptr++;
177 /* set the number of items */
178 hDpa->nItemCount = loadData.nCount;
180 /* store the handle to the dpa */
181 *phDpa = hDpa;
182 FIXME ("new hDpa=%p, errorcode=%lx\n", hDpa, errCode);
184 return errCode;
188 /**************************************************************************
189 * DPA_SaveStream [COMCTL32.10]
191 * Saves a dynamic pointer array to a stream
193 * PARAMS
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
199 * NOTES
200 * No more information available yet!
203 HRESULT WINAPI
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);
210 return E_FAIL;
214 /**************************************************************************
215 * DPA_Merge [COMCTL32.11]
217 * PARAMS
218 * hdpa1 [I] handle to a dynamic pointer array
219 * hdpa2 [I] handle to a dynamic pointer array
220 * dwFlags [I] flags
221 * pfnCompare [I] pointer to sort function
222 * pfnMerge [I] pointer to merge function
223 * lParam [I] application specific value
225 * NOTES
226 * No more information available yet!
229 BOOL WINAPI
230 DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags,
231 PFNDPACOMPARE pfnCompare, PFNDPAMERGE pfnMerge, LPARAM lParam)
233 INT nCount;
234 LPVOID *pWork1, *pWork2;
235 INT nResult, i;
236 INT nIndex;
238 TRACE("%p %p %08lx %p %p %08lx)\n",
239 hdpa1, hdpa2, dwFlags, pfnCompare, pfnMerge, lParam);
241 if (IsBadWritePtr (hdpa1, sizeof(*hdpa1)))
242 return FALSE;
244 if (IsBadWritePtr (hdpa2, sizeof(*hdpa2)))
245 return FALSE;
247 if (IsBadCodePtr ((FARPROC)pfnCompare))
248 return FALSE;
250 if (IsBadCodePtr ((FARPROC)pfnMerge))
251 return FALSE;
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)
264 return TRUE;
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;
280 if (nIndex < 0) {
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",
284 nCount+1);
285 for (i=nCount; i>=0; i--) {
286 PVOID ptr;
288 ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
289 if (!ptr)
290 return FALSE;
291 DPA_InsertPtr (hdpa1, 0, ptr);
292 pWork2--;
295 break;
297 nResult = (pfnCompare)(*pWork1, *pWork2, lParam);
298 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
299 nResult, nIndex, nCount);
301 if (nResult == 0)
303 PVOID ptr;
305 ptr = (pfnMerge)(1, *pWork1, *pWork2, lParam);
306 if (!ptr)
307 return FALSE;
309 nCount--;
310 pWork2--;
311 *pWork1 = ptr;
312 nIndex--;
313 pWork1--;
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 */
321 PVOID ptr;
323 ptr = DPA_DeletePtr (hdpa1, hdpa1->nItemCount - 1);
325 (pfnMerge)(2, ptr, NULL, lParam);
327 nIndex--;
328 pWork1--;
330 else
332 /* new item in DPA 2 */
333 if (dwFlags & DPAM_INSERT)
335 /* Now insert the new item in DPA 1 */
336 PVOID ptr;
338 ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
339 if (!ptr)
340 return FALSE;
341 DPA_InsertPtr (hdpa1, nIndex+1, ptr);
343 nCount--;
344 pWork2--;
348 while (nCount >= 0);
350 return TRUE;
354 /**************************************************************************
355 * Alloc [COMCTL32.71]
357 * Allocates memory block from the dll's private heap
359 * PARAMS
360 * dwSize [I] size of the allocated memory block
362 * RETURNS
363 * Success: pointer to allocated memory block
364 * Failure: NULL
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.
379 * PARAMS
380 * lpSrc [I] pointer to memory block which will be resized
381 * dwSize [I] new size of the memory block.
383 * RETURNS
384 * Success: pointer to the resized memory block
385 * Failure: NULL
387 * NOTES
388 * If lpSrc is a NULL-pointer, then ReAlloc allocates a memory
389 * block like Alloc.
392 LPVOID WINAPI ReAlloc (LPVOID lpSrc, DWORD dwSize)
394 if (lpSrc)
395 return LocalReAlloc( lpSrc, dwSize, LMEM_ZEROINIT );
396 else
397 return LocalAlloc( LMEM_ZEROINIT, dwSize);
401 /**************************************************************************
402 * Free [COMCTL32.73]
404 * Frees an allocated memory block from the dll's private heap.
406 * PARAMS
407 * lpMem [I] pointer to memory block which will be freed
409 * RETURNS
410 * Success: TRUE
411 * Failure: FALSE
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
424 * private heap.
426 * PARAMS
427 * lpMem [I] pointer to an allocated memory block
429 * RETURNS
430 * Success: size of the specified memory block
431 * Failure: 0
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)
442 * lists.
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;
470 /* dwFlags */
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 */
487 BYTE datastart;
488 } WINEMRUITEM, *LPWINEMRUITEM;
490 /* itemFlag */
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;
504 /* wineFlags */
505 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
507 /**************************************************************************
508 * MRU_SaveChanged - Localize MRU saving code
511 VOID MRU_SaveChanged( LPWINEMRULIST mp )
513 UINT i, err;
514 HKEY newkey;
515 WCHAR realname[2];
516 LPWINEMRUITEM witem;
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",
527 err);
528 if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey,
530 emptyW,
531 REG_OPTION_NON_VOLATILE,
532 KEY_READ | KEY_WRITE,
534 &newkey,
535 0))) {
536 ERR("failed to create key /%s/, err=%d\n",
537 debugstr_w(mp->extview.lpszSubKey), err);
538 return;
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);
545 if (err) {
546 ERR("error saving MRUList, err=%d\n", err);
548 TRACE("saving MRUList=/%s/\n", mp->realMRU);
550 realname[1] = 0;
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) ?
558 REG_BINARY : REG_SZ,
559 &witem->datastart, witem->size);
560 if (err) {
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]
573 * PARAMS
574 * hMRUList [I] Handle to list.
577 DWORD WINAPI
578 FreeMRUList (HANDLE hMRUList)
580 LPWINEMRULIST mp = (LPWINEMRULIST)hMRUList;
581 UINT i;
583 TRACE("\n");
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++) {
590 if (mp->array[i])
591 Free(mp->array[i]);
593 Free(mp->realMRU);
594 Free(mp->array);
595 Free((LPWSTR)mp->extview.lpszSubKey);
596 return Free(mp);
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).
607 * PARAMS
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)
613 * RETURNS
614 * Position in list 0 -> MRU. -1 if item not found.
616 INT WINAPI
617 FindMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum)
619 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
620 UINT i, ret;
621 LPSTR dataA = NULL;
623 if (!mp->extview.lpfnCompare) {
624 ERR("MRU list not properly created. No compare procedure.\n");
625 return -1;
628 if(!(mp->extview.dwFlags & MRUF_BINARY_LIST) && !mp->isUnicode) {
629 DWORD len = WideCharToMultiByte(CP_ACP, 0, lpData, -1,
630 NULL, 0, NULL, NULL);
631 dataA = Alloc(len);
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,
638 cbData))
639 break;
641 else {
642 if(mp->isUnicode) {
643 if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart))
644 break;
645 } else {
646 DWORD len = WideCharToMultiByte(CP_ACP, 0,
647 (LPWSTR)&mp->array[i]->datastart, -1,
648 NULL, 0, NULL, NULL);
649 LPSTR itemA = Alloc(len);
650 INT cmp;
651 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&mp->array[i]->datastart, -1,
652 itemA, len, NULL, NULL);
654 cmp = mp->extview.lpfnCompare(dataA, itemA);
655 Free(itemA);
656 if(!cmp)
657 break;
661 if(dataA)
662 Free(dataA);
663 if (i < mp->cursize)
664 ret = i;
665 else
666 ret = -1;
667 if (lpRegNum && (ret != -1))
668 *lpRegNum = 'a' + i;
670 TRACE("(%p, %p, %ld, %p) returning %d\n",
671 hList, lpData, cbData, lpRegNum, ret);
673 return 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.
684 * PARAMS
685 * hList [I] Handle to list.
686 * lpData [I] ptr to data to add.
687 * cbData [I] no. of bytes of data.
689 * RETURNS
690 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
691 * -1 on error.
693 INT WINAPI
694 AddMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData)
696 LPWINEMRULIST mp = (LPWINEMRULIST)hList;
697 LPWINEMRUITEM witem;
698 INT i, replace, ret;
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;
705 mp->cursize++;
707 else {
708 /* get the oldest entry and replace data */
709 replace = mp->realMRU[mp->cursize - 1] - 'a';
710 Free(mp->array[replace]);
713 else {
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');
732 ret = replace;
734 if (!(mp->extview.dwFlags & MRUF_DELAYED_SAVE)) {
735 /* save changed stuff right now */
736 MRU_SaveChanged( mp );
739 return ret;
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.
749 * PARAMS
750 * hList [I] Handle to list.
751 * lpszString [I] ptr to string to add.
753 * RETURNS
754 * No. corresponding to registry name where value is stored 'a' -> 0 etc.
755 * -1 on error.
757 INT WINAPI
758 AddMRUStringW(HANDLE hList, LPCWSTR lpszString)
760 FIXME("(%p, %s) empty stub!\n", hList, debugstr_w(lpszString));
762 return 0;
765 /**************************************************************************
766 * AddMRUStringA [COMCTL32.153]
768 INT WINAPI
769 AddMRUStringA(HANDLE hList, LPCSTR lpszString)
771 FIXME("(%p, %s) empty stub!\n", hList, debugstr_a(lpszString));
773 return 0;
776 /**************************************************************************
777 * DelMRUString [COMCTL32.156]
779 * Removes item from either string or binary list (despite its name)
781 * PARAMS
782 * hList [I] list handle
783 * nItemPos [I] item position to remove 0 -> MRU
785 * RETURNS
786 * TRUE if successful, FALSE if nItemPos is out of range.
788 BOOL WINAPI
789 DelMRUString(HANDLE hList, INT nItemPos)
791 FIXME("(%p, %d): stub\n", hList, nItemPos);
792 return TRUE;
795 /**************************************************************************
796 * FindMRUStringW [COMCTL32.402]
798 INT WINAPI
799 FindMRUStringW (HANDLE hList, LPCWSTR lpszString, LPINT lpRegNum)
801 FIXME("stub\n");
802 return -1;
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).
812 * PARAMS
813 * hList [I] list handle
814 * lpszString [I] string to find
815 * lpRegNum [O] position in registry (maybe NULL)
817 * RETURNS
818 * Position in list 0 -> MRU. -1 if item not found.
820 INT WINAPI
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));
825 INT ret;
827 MultiByteToWideChar(CP_ACP, 0, lpszString, -1, stringW, len);
828 ret = FindMRUData(hList, stringW, len * sizeof(WCHAR), lpRegNum);
829 Free(stringW);
830 return ret;
833 /*************************************************************************
834 * CreateMRUListLazy_common
836 HANDLE CreateMRUListLazy_common(LPWINEMRULIST mp)
838 UINT i, err;
839 HKEY newkey;
840 DWORD datasize, dwdisp;
841 WCHAR realname[2];
842 LPWINEMRUITEM witem;
843 DWORD type;
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,
859 emptyW,
860 REG_OPTION_NON_VOLATILE,
861 KEY_READ | KEY_WRITE,
863 &newkey,
864 &dwdisp))) {
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);
870 return 0;
873 /* get values from key 'MRUList' */
874 if (newkey) {
875 datasize = mp->extview.nMaxItems + 1;
876 if((err=RegQueryValueExA( newkey, "MRUList", 0, &type, mp->realMRU,
877 &datasize))) {
878 /* not present - set size to 1 (will become 0 later) */
879 datasize = 1;
880 *mp->realMRU = 0;
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 */
889 realname[1] = 0;
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 );
906 else
907 mp->cursize = 0;
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);
913 return (HANDLE)mp;
916 /**************************************************************************
917 * CreateMRUListLazyW [COMCTL32.404]
919 HANDLE WINAPI
920 CreateMRUListLazyW (LPCREATEMRULISTW lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
922 LPWINEMRULIST mp;
924 if (lpcml == NULL)
925 return 0;
927 if (lpcml->cbSize < sizeof(CREATEMRULISTW))
928 return 0;
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]
942 HANDLE WINAPI
943 CreateMRUListLazyA (LPCREATEMRULISTA lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4)
945 LPWINEMRULIST mp;
946 DWORD len;
948 if (lpcml == NULL)
949 return 0;
951 if (lpcml->cbSize < sizeof(CREATEMRULISTA))
952 return 0;
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]
967 * PARAMS
968 * lpcml [I] ptr to CREATEMRULIST structure.
970 * RETURNS
971 * Handle to MRU list.
973 HANDLE WINAPI
974 CreateMRUListW (LPCREATEMRULISTW lpcml)
976 return CreateMRUListLazyW(lpcml, 0, 0, 0);
979 /**************************************************************************
980 * CreateMRUListA [COMCTL32.151]
982 HANDLE WINAPI
983 CreateMRUListA (LPCREATEMRULISTA lpcml)
985 return CreateMRUListLazyA (lpcml, 0, 0, 0);
989 /**************************************************************************
990 * EnumMRUListW [COMCTL32.403]
992 * Enumerate item in a list
994 * PARAMS
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
1000 * RETURNS
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
1005 * the list.
1007 INT WINAPI EnumMRUListW(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
1008 DWORD nBufferSize)
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];
1017 desired -= 'a';
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);
1024 return datasize;
1027 /**************************************************************************
1028 * EnumMRUListA [COMCTL32.154]
1031 INT WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
1032 DWORD nBufferSize)
1034 LPWINEMRULIST mp = (LPWINEMRULIST) hList;
1035 LPWINEMRUITEM witem;
1036 INT desired, datasize;
1037 DWORD lenA;
1039 if (nItemPos >= mp->cursize) return -1;
1040 if ((nItemPos < 0) || !lpBuffer) return mp->cursize;
1041 desired = mp->realMRU[nItemPos];
1042 desired -= 'a';
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);
1048 } else {
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);
1057 return datasize;
1061 /**************************************************************************
1062 * Str_GetPtrA [COMCTL32.233]
1064 * PARAMS
1065 * lpSrc [I]
1066 * lpDest [O]
1067 * nMaxLen [I]
1069 * RETURNS
1072 INT WINAPI
1073 Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1075 INT len;
1077 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
1079 if (!lpDest && lpSrc)
1080 return strlen (lpSrc);
1082 if (nMaxLen == 0)
1083 return 0;
1085 if (lpSrc == NULL) {
1086 lpDest[0] = '\0';
1087 return 0;
1090 len = strlen (lpSrc);
1091 if (len >= nMaxLen)
1092 len = nMaxLen - 1;
1094 RtlMoveMemory (lpDest, lpSrc, len);
1095 lpDest[len] = '\0';
1097 return len;
1101 /**************************************************************************
1102 * Str_SetPtrA [COMCTL32.234]
1104 * PARAMS
1105 * lppDest [O]
1106 * lpSrc [I]
1108 * RETURNS
1111 BOOL WINAPI
1112 Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc)
1114 TRACE("(%p %p)\n", lppDest, lpSrc);
1116 if (lpSrc) {
1117 LPSTR ptr = ReAlloc (*lppDest, strlen (lpSrc) + 1);
1118 if (!ptr)
1119 return FALSE;
1120 strcpy (ptr, lpSrc);
1121 *lppDest = ptr;
1123 else {
1124 if (*lppDest) {
1125 Free (*lppDest);
1126 *lppDest = NULL;
1130 return TRUE;
1134 /**************************************************************************
1135 * Str_GetPtrW [COMCTL32.235]
1137 * PARAMS
1138 * lpSrc [I]
1139 * lpDest [O]
1140 * nMaxLen [I]
1142 * RETURNS
1145 INT WINAPI
1146 Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen)
1148 INT len;
1150 TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen);
1152 if (!lpDest && lpSrc)
1153 return strlenW (lpSrc);
1155 if (nMaxLen == 0)
1156 return 0;
1158 if (lpSrc == NULL) {
1159 lpDest[0] = L'\0';
1160 return 0;
1163 len = strlenW (lpSrc);
1164 if (len >= nMaxLen)
1165 len = nMaxLen - 1;
1167 RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
1168 lpDest[len] = L'\0';
1170 return len;
1174 /**************************************************************************
1175 * Str_SetPtrW [COMCTL32.236]
1177 * PARAMS
1178 * lpDest [O]
1179 * lpSrc [I]
1181 * RETURNS
1184 BOOL WINAPI
1185 Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc)
1187 TRACE("(%p %p)\n", lppDest, lpSrc);
1189 if (lpSrc) {
1190 INT len = strlenW (lpSrc) + 1;
1191 LPWSTR ptr = ReAlloc (*lppDest, len * sizeof(WCHAR));
1192 if (!ptr)
1193 return FALSE;
1194 strcpyW (ptr, lpSrc);
1195 *lppDest = ptr;
1197 else {
1198 if (*lppDest) {
1199 Free (*lppDest);
1200 *lppDest = NULL;
1204 return TRUE;
1208 /**************************************************************************
1209 * Str_GetPtrWtoA [internal]
1211 * Converts a unicode string into a multi byte string
1213 * PARAMS
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
1218 * RETURNS
1219 * Length, in bytes, of the converted string.
1223 Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen)
1225 INT len;
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);
1232 if (nMaxLen == 0)
1233 return 0;
1235 if (lpSrc == NULL) {
1236 lpDest[0] = '\0';
1237 return 0;
1240 len = WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL);
1241 if (len >= nMaxLen)
1242 len = nMaxLen - 1;
1244 WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, lpDest, len, NULL, NULL);
1245 lpDest[len] = '\0';
1247 return len;
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.
1260 * PARAMS
1261 * lppDest [I/O] pointer to a pointer to the destination buffer
1262 * lpSrc [I] pointer to a multi byte string
1264 * RETURNS
1265 * TRUE: conversion successful
1266 * FALSE: error
1269 BOOL
1270 Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc)
1272 TRACE("(%p %s)\n", lppDest, lpSrc);
1274 if (lpSrc) {
1275 INT len = MultiByteToWideChar(CP_ACP,0,lpSrc,-1,NULL,0);
1276 LPWSTR ptr = ReAlloc (*lppDest, len*sizeof(WCHAR));
1278 if (!ptr)
1279 return FALSE;
1280 MultiByteToWideChar(CP_ACP,0,lpSrc,-1,ptr,len);
1281 *lppDest = ptr;
1283 else {
1284 if (*lppDest) {
1285 Free (*lppDest);
1286 *lppDest = NULL;
1290 return TRUE;
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
1303 * PARAMS
1304 * nSize [I] size of the array elements
1305 * nGrow [I] number of elements by which the array grows when it is filled
1307 * RETURNS
1308 * Success: pointer to an array control structure. Use this like a handle.
1309 * Failure: NULL
1312 HDSA WINAPI
1313 DSA_Create (INT nSize, INT nGrow)
1315 HDSA hdsa;
1317 TRACE("(size=%d grow=%d)\n", nSize, nGrow);
1319 hdsa = Alloc (sizeof(*hdsa));
1320 if (hdsa)
1322 hdsa->nItemCount = 0;
1323 hdsa->pData = NULL;
1324 hdsa->nMaxCount = 0;
1325 hdsa->nItemSize = nSize;
1326 hdsa->nGrow = max(1, nGrow);
1329 return hdsa;
1333 /**************************************************************************
1334 * DSA_Destroy [COMCTL32.321] Destroys a dynamic storage array
1336 * PARAMS
1337 * hdsa [I] pointer to the array control structure
1339 * RETURNS
1340 * Success: TRUE
1341 * Failure: FALSE
1344 BOOL WINAPI
1345 DSA_Destroy (const HDSA hdsa)
1347 TRACE("(%p)\n", hdsa);
1349 if (!hdsa)
1350 return FALSE;
1352 if (hdsa->pData && (!Free (hdsa->pData)))
1353 return FALSE;
1355 return Free (hdsa);
1359 /**************************************************************************
1360 * DSA_GetItem [COMCTL32.322]
1362 * PARAMS
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.
1367 * RETURNS
1368 * Success: TRUE
1369 * Failure: FALSE
1372 BOOL WINAPI
1373 DSA_GetItem (const HDSA hdsa, INT nIndex, LPVOID pDest)
1375 LPVOID pSrc;
1377 TRACE("(%p %d %p)\n", hdsa, nIndex, pDest);
1379 if (!hdsa)
1380 return FALSE;
1381 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1382 return FALSE;
1384 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1385 memmove (pDest, pSrc, hdsa->nItemSize);
1387 return TRUE;
1391 /**************************************************************************
1392 * DSA_GetItemPtr [COMCTL32.323]
1394 * Retrieves a pointer to the specified item.
1396 * PARAMS
1397 * hdsa [I] pointer to the array control structure
1398 * nIndex [I] index of the desired item
1400 * RETURNS
1401 * Success: pointer to an item
1402 * Failure: NULL
1405 LPVOID WINAPI
1406 DSA_GetItemPtr (const HDSA hdsa, INT nIndex)
1408 LPVOID pSrc;
1410 TRACE("(%p %d)\n", hdsa, nIndex);
1412 if (!hdsa)
1413 return NULL;
1414 if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
1415 return NULL;
1417 pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
1419 TRACE("-- ret=%p\n", pSrc);
1421 return pSrc;
1425 /**************************************************************************
1426 * DSA_SetItem [COMCTL32.325]
1428 * Sets the contents of an item in the array.
1430 * PARAMS
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
1435 * RETURNS
1436 * Success: TRUE
1437 * Failure: FALSE
1440 BOOL WINAPI
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)
1449 return FALSE;
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;
1457 else {
1458 /* resize the block of memory */
1459 nNewItems =
1460 hdsa->nGrow * ((INT)(((nIndex + 1) - 1) / hdsa->nGrow) + 1);
1461 nSize = hdsa->nItemSize * nNewItems;
1463 lpTemp = ReAlloc (hdsa->pData, nSize);
1464 if (!lpTemp)
1465 return FALSE;
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);
1479 return TRUE;
1483 /**************************************************************************
1484 * DSA_InsertItem [COMCTL32.324]
1486 * PARAMS
1487 * hdsa [I] pointer to the array control structure
1488 * nIndex [I] index for the new item
1489 * pSrc [I] pointer to the element
1491 * RETURNS
1492 * Success: position of the new item
1493 * Failure: -1
1496 INT WINAPI
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)
1505 return -1;
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);
1517 if (!lpTemp)
1518 return -1;
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 */
1535 hdsa->nItemCount++;
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);
1541 return nIndex;
1545 /**************************************************************************
1546 * DSA_DeleteItem [COMCTL32.326]
1548 * PARAMS
1549 * hdsa [I] pointer to the array control structure
1550 * nIndex [I] index for the element to delete
1552 * RETURNS
1553 * Success: number of the deleted element
1554 * Failure: -1
1557 INT WINAPI
1558 DSA_DeleteItem (const HDSA hdsa, INT nIndex)
1560 LPVOID lpDest,lpSrc;
1561 INT nSize;
1563 TRACE("(%p %d)\n", hdsa, nIndex);
1565 if (!hdsa)
1566 return -1;
1567 if (nIndex < 0 || nIndex >= hdsa->nItemCount)
1568 return -1;
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);
1580 hdsa->nItemCount--;
1582 /* free memory ? */
1583 if ((hdsa->nMaxCount - hdsa->nItemCount) >= hdsa->nGrow) {
1584 nSize = hdsa->nItemSize * hdsa->nItemCount;
1586 lpDest = ReAlloc (hdsa->pData, nSize);
1587 if (!lpDest)
1588 return -1;
1590 hdsa->nMaxCount = hdsa->nItemCount;
1591 hdsa->pData = lpDest;
1594 return nIndex;
1598 /**************************************************************************
1599 * DSA_DeleteAllItems [COMCTL32.327]
1601 * Removes all items and reinitializes the array.
1603 * PARAMS
1604 * hdsa [I] pointer to the array control structure
1606 * RETURNS
1607 * Success: TRUE
1608 * Failure: FALSE
1611 BOOL WINAPI
1612 DSA_DeleteAllItems (const HDSA hdsa)
1614 TRACE("(%p)\n", hdsa);
1616 if (!hdsa)
1617 return FALSE;
1618 if (hdsa->pData && (!Free (hdsa->pData)))
1619 return FALSE;
1621 hdsa->nItemCount = 0;
1622 hdsa->pData = NULL;
1623 hdsa->nMaxCount = 0;
1625 return TRUE;
1629 /**************************************************************************
1630 * The DPA-API is a set of functions to create and manipulate arrays of
1631 * pointers.
1634 /**************************************************************************
1635 * DPA_Destroy [COMCTL32.329] Destroys a dynamic pointer array
1637 * PARAMS
1638 * hdpa [I] handle (pointer) to the pointer array
1640 * RETURNS
1641 * Success: TRUE
1642 * Failure: FALSE
1645 BOOL WINAPI
1646 DPA_Destroy (const HDPA hdpa)
1648 TRACE("(%p)\n", hdpa);
1650 if (!hdpa)
1651 return FALSE;
1653 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
1654 return FALSE;
1656 return HeapFree (hdpa->hHeap, 0, hdpa);
1660 /**************************************************************************
1661 * DPA_Grow [COMCTL32.330]
1663 * Sets the growth amount.
1665 * PARAMS
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
1669 * RETURNS
1670 * Success: TRUE
1671 * Failure: FALSE
1674 BOOL WINAPI
1675 DPA_Grow (const HDPA hdpa, INT nGrow)
1677 TRACE("(%p %d)\n", hdpa, nGrow);
1679 if (!hdpa)
1680 return FALSE;
1682 hdpa->nGrow = max(8, nGrow);
1684 return TRUE;
1688 /**************************************************************************
1689 * DPA_Clone [COMCTL32.331]
1691 * Copies a pointer array to an other one or creates a copy
1693 * PARAMS
1694 * hdpa [I] handle (pointer) to the existing (source) pointer array
1695 * hdpaNew [O] handle (pointer) to the destination pointer array
1697 * RETURNS
1698 * Success: pointer to the destination pointer array.
1699 * Failure: NULL
1701 * NOTES
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.
1708 HDPA WINAPI
1709 DPA_Clone (const HDPA hdpa, const HDPA hdpaNew)
1711 INT nNewItems, nSize;
1712 HDPA hdpaTemp;
1714 if (!hdpa)
1715 return NULL;
1717 TRACE("(%p %p)\n", hdpa, hdpaNew);
1719 if (!hdpaNew) {
1720 /* create a new DPA */
1721 hdpaTemp = (HDPA)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
1722 sizeof(*hdpaTemp));
1723 hdpaTemp->hHeap = hdpa->hHeap;
1724 hdpaTemp->nGrow = hdpa->nGrow;
1726 else
1727 hdpaTemp = hdpaNew;
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);
1741 hdpaTemp->ptrs =
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));
1750 return hdpaTemp;
1754 /**************************************************************************
1755 * DPA_GetPtr [COMCTL32.332]
1757 * Retrieves a pointer from a dynamic pointer array
1759 * PARAMS
1760 * hdpa [I] handle (pointer) to the pointer array
1761 * nIndex [I] array index of the desired pointer
1763 * RETURNS
1764 * Success: pointer
1765 * Failure: NULL
1768 LPVOID WINAPI
1769 DPA_GetPtr (const HDPA hdpa, INT nIndex)
1771 TRACE("(%p %d)\n", hdpa, nIndex);
1773 if (!hdpa)
1774 return NULL;
1775 if (!hdpa->ptrs) {
1776 WARN("no pointer array.\n");
1777 return NULL;
1779 if ((nIndex < 0) || (nIndex >= hdpa->nItemCount)) {
1780 WARN("not enough pointers in array (%d vs %d).\n",nIndex,hdpa->nItemCount);
1781 return NULL;
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
1795 * PARAMS
1796 * hdpa [I] handle (pointer) to the pointer array
1797 * p [I] pointer
1799 * RETURNS
1800 * Success: index of the specified pointer
1801 * Failure: -1
1804 INT WINAPI
1805 DPA_GetPtrIndex (const HDPA hdpa, LPVOID p)
1807 INT i;
1809 if (!hdpa || !hdpa->ptrs)
1810 return -1;
1812 for (i = 0; i < hdpa->nItemCount; i++) {
1813 if (hdpa->ptrs[i] == p)
1814 return i;
1817 return -1;
1821 /**************************************************************************
1822 * DPA_InsertPtr [COMCTL32.334]
1824 * Inserts a pointer into a dynamic pointer array
1826 * PARAMS
1827 * hdpa [I] handle (pointer) to the array
1828 * i [I] array index
1829 * p [I] pointer to insert
1831 * RETURNS
1832 * Success: index of the inserted pointer
1833 * Failure: -1
1836 INT WINAPI
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;
1843 if (i >= 0x7fff)
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));
1852 hdpa->ptrs[i] = p;
1853 return i;
1856 /**************************************************************************
1857 * DPA_SetPtr [COMCTL32.335]
1859 * Sets a pointer in the pointer array
1861 * PARAMS
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
1866 * RETURNS
1867 * Success: TRUE
1868 * Failure: FALSE
1871 BOOL WINAPI
1872 DPA_SetPtr (const HDPA hdpa, INT i, LPVOID p)
1874 LPVOID *lpTemp;
1876 TRACE("(%p %d %p)\n", hdpa, i, p);
1878 if (!hdpa || i < 0 || i > 0x7fff)
1879 return FALSE;
1881 if (hdpa->nItemCount <= i) {
1882 /* within the old array */
1883 if (hdpa->nMaxCount <= i) {
1884 /* resize the block of memory */
1885 INT nNewItems =
1886 hdpa->nGrow * ((INT)(((i+1) - 1) / hdpa->nGrow) + 1);
1887 INT nSize = nNewItems * sizeof(LPVOID);
1889 if (hdpa->ptrs)
1890 lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, hdpa->ptrs, nSize);
1891 else
1892 lpTemp = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, nSize);
1894 if (!lpTemp)
1895 return FALSE;
1897 hdpa->nMaxCount = nNewItems;
1898 hdpa->ptrs = lpTemp;
1900 hdpa->nItemCount = i+1;
1903 /* put the new entry in */
1904 hdpa->ptrs[i] = p;
1906 return TRUE;
1910 /**************************************************************************
1911 * DPA_DeletePtr [COMCTL32.336]
1913 * Removes a pointer from the pointer array.
1915 * PARAMS
1916 * hdpa [I] handle (pointer) to the pointer array
1917 * i [I] index of the pointer that will be deleted
1919 * RETURNS
1920 * Success: deleted pointer
1921 * Failure: NULL
1924 LPVOID WINAPI
1925 DPA_DeletePtr (const HDPA hdpa, INT i)
1927 LPVOID *lpDest, *lpSrc, lpTemp = NULL;
1928 INT nSize;
1930 TRACE("(%p %d)\n", hdpa, i);
1932 if ((!hdpa) || i < 0 || i >= hdpa->nItemCount)
1933 return NULL;
1935 lpTemp = hdpa->ptrs[i];
1937 /* do we need to move ?*/
1938 if (i < hdpa->nItemCount - 1) {
1939 lpDest = hdpa->ptrs + i;
1940 lpSrc = lpDest + 1;
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 --;
1949 /* free memory ?*/
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,
1954 hdpa->ptrs, nSize);
1955 if (!lpDest)
1956 return NULL;
1958 hdpa->nMaxCount = nNewItems;
1959 hdpa->ptrs = (LPVOID*)lpDest;
1962 return lpTemp;
1966 /**************************************************************************
1967 * DPA_DeleteAllPtrs [COMCTL32.337]
1969 * Removes all pointers and reinitializes the array.
1971 * PARAMS
1972 * hdpa [I] handle (pointer) to the pointer array
1974 * RETURNS
1975 * Success: TRUE
1976 * Failure: FALSE
1979 BOOL WINAPI
1980 DPA_DeleteAllPtrs (const HDPA hdpa)
1982 TRACE("(%p)\n", hdpa);
1984 if (!hdpa)
1985 return FALSE;
1987 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
1988 return FALSE;
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));
1995 return TRUE;
1999 /**************************************************************************
2000 * DPA_QuickSort [Internal]
2002 * Ordinary quicksort (used by DPA_Sort).
2004 * PARAMS
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)
2011 * RETURNS
2012 * NONE
2015 static VOID
2016 DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r,
2017 PFNDPACOMPARE pfnCompare, LPARAM lParam)
2019 INT m;
2020 LPVOID t;
2022 TRACE("l=%i r=%i\n", l, r);
2024 if (l==r) /* one element is always sorted */
2025 return;
2026 if (r<l) /* oops, got it in the wrong order */
2028 DPA_QuickSort(lpPtrs, r, l, pfnCompare, lParam);
2029 return;
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)
2040 t = lpPtrs[m+1];
2041 memmove(&lpPtrs[l+1],&lpPtrs[l],(m-l+1)*sizeof(lpPtrs[l]));
2042 lpPtrs[l] = t;
2044 m++;
2046 l++;
2051 /**************************************************************************
2052 * DPA_Sort [COMCTL32.338]
2054 * Sorts a pointer array using a user defined compare function
2056 * PARAMS
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)
2061 * RETURNS
2062 * Success: TRUE
2063 * Failure: FALSE
2066 BOOL WINAPI
2067 DPA_Sort (const HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam)
2069 if (!hdpa || !pfnCompare)
2070 return FALSE;
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);
2078 return TRUE;
2082 /**************************************************************************
2083 * DPA_Search [COMCTL32.339]
2085 * Searches a pointer array for a specified pointer
2087 * PARAMS
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
2095 * RETURNS
2096 * Success: index of the pointer in the array.
2097 * Failure: -1
2099 * NOTES
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)
2105 INT WINAPI
2106 DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart,
2107 PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions)
2109 if (!hdpa || !pfnCompare || !pFind)
2110 return -1;
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 */
2117 INT l, r, x, n;
2118 LPVOID *lpPtr;
2120 TRACE("binary search\n");
2122 l = (nStart == -1) ? 0 : nStart;
2123 r = hdpa->nItemCount - 1;
2124 lpPtr = hdpa->ptrs;
2125 while (r >= l) {
2126 x = (l + r) / 2;
2127 n = (pfnCompare)(pFind, lpPtr[x], lParam);
2128 if (n < 0)
2129 r = x - 1;
2130 else
2131 l = x + 1;
2132 if (n == 0) {
2133 TRACE("-- ret=%d\n", n);
2134 return n;
2138 if (uOptions & DPAS_INSERTBEFORE) {
2139 if (r == -1) r = 0;
2140 TRACE("-- ret=%d\n", r);
2141 return r;
2144 if (uOptions & DPAS_INSERTAFTER) {
2145 TRACE("-- ret=%d\n", l);
2146 return l;
2149 else {
2150 /* array is not sorted --> use linear search */
2151 LPVOID *lpPtr;
2152 INT nIndex;
2154 TRACE("linear search\n");
2156 nIndex = (nStart == -1)? 0 : nStart;
2157 lpPtr = hdpa->ptrs;
2158 for (; nIndex < hdpa->nItemCount; nIndex++) {
2159 if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) {
2160 TRACE("-- ret=%d\n", nIndex);
2161 return nIndex;
2166 TRACE("-- not found: ret=-1\n");
2167 return -1;
2171 /**************************************************************************
2172 * DPA_CreateEx [COMCTL32.340]
2174 * Creates a dynamic pointer array using the specified size and heap.
2176 * PARAMS
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
2180 * RETURNS
2181 * Success: handle (pointer) to the pointer array.
2182 * Failure: NULL
2185 HDPA WINAPI
2186 DPA_CreateEx (INT nGrow, HANDLE hHeap)
2188 HDPA hdpa;
2190 TRACE("(%d %p)\n", nGrow, hHeap);
2192 if (hHeap)
2193 hdpa = (HDPA)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(*hdpa));
2194 else
2195 hdpa = Alloc (sizeof(*hdpa));
2197 if (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);
2207 return hdpa;
2211 /**************************************************************************
2212 * DPA_Create [COMCTL32.328] Creates a dynamic pointer array
2214 * PARAMS
2215 * nGrow [I] number of items by which the array grows when it is filled
2217 * RETURNS
2218 * Success: handle (pointer) to the pointer array.
2219 * Failure: NULL
2222 HDPA WINAPI
2223 DPA_Create (INT nGrow)
2225 return DPA_CreateEx( nGrow, 0 );
2229 /**************************************************************************
2230 * Notification functions
2233 typedef struct tagNOTIFYDATA
2235 HWND hwndFrom;
2236 HWND hwndTo;
2237 DWORD dwParam3;
2238 DWORD dwParam4;
2239 DWORD dwParam5;
2240 DWORD dwParam6;
2241 } NOTIFYDATA, *LPNOTIFYDATA;
2244 /**************************************************************************
2245 * DoNotify [Internal]
2248 static LRESULT
2249 DoNotify (LPNOTIFYDATA lpNotify, UINT uCode, LPNMHDR lpHdr)
2251 NMHDR nmhdr;
2252 LPNMHDR lpNmh = NULL;
2253 UINT idFrom = 0;
2255 TRACE("(%p %p %d %p 0x%08lx)\n",
2256 lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr,
2257 lpNotify->dwParam5);
2259 if (!lpNotify->hwndTo)
2260 return 0;
2262 if (lpNotify->hwndFrom == (HWND)-1) {
2263 lpNmh = lpHdr;
2264 idFrom = lpHdr->idFrom;
2266 else {
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]
2284 * PARAMS
2285 * hwndTo [I]
2286 * hwndFrom [I]
2287 * uCode [I]
2288 * lpHdr [I]
2290 * RETURNS
2291 * Success: return value from notification
2292 * Failure: 0
2295 LRESULT WINAPI SendNotify (HWND hwndTo, HWND hwndFrom, UINT uCode, LPNMHDR lpHdr)
2297 NOTIFYDATA notify;
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 (&notify, uCode, lpHdr);
2311 /**************************************************************************
2312 * SendNotifyEx [COMCTL32.342]
2314 * PARAMS
2315 * hwndFrom [I]
2316 * hwndTo [I]
2317 * uCode [I]
2318 * lpHdr [I]
2319 * dwParam5 [I]
2321 * RETURNS
2322 * Success: return value from notification
2323 * Failure: 0
2326 LRESULT WINAPI SendNotifyEx (HWND hwndTo, HWND hwndFrom, UINT uCode,
2327 LPNMHDR lpHdr, DWORD dwParam5)
2329 NOTIFYDATA notify;
2330 HWND hwndNotify;
2332 TRACE("(%p %p %d %p 0x%08lx)\n",
2333 hwndFrom, hwndTo, uCode, lpHdr, dwParam5);
2335 hwndNotify = hwndTo;
2336 if (!hwndTo) {
2337 if (IsWindow (hwndFrom)) {
2338 hwndNotify = GetParent (hwndFrom);
2339 if (!hwndNotify)
2340 return 0;
2344 notify.hwndFrom = hwndFrom;
2345 notify.hwndTo = hwndNotify;
2346 notify.dwParam5 = dwParam5;
2347 notify.dwParam6 = 0;
2349 return DoNotify (&notify, 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)
2370 INT len1, len2, i;
2371 CHAR first;
2373 if (*lpStr2 == 0)
2374 return ((LPSTR)lpStr1);
2375 len1 = 0;
2376 while (lpStr1[len1] != 0) ++len1;
2377 len2 = 0;
2378 while (lpStr2[len2] != 0) ++len2;
2379 if (len2 == 0)
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]))
2386 break;
2387 if (i >= len2)
2388 return ((LPSTR)lpStr1);
2390 ++lpStr1; --len1;
2392 return (NULL);
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)
2410 INT len1, len2, i;
2411 WCHAR first;
2413 if (*lpStr2 == 0)
2414 return ((LPWSTR)lpStr1);
2415 len1 = 0;
2416 while (lpStr1[len1] != 0) ++len1;
2417 len2 = 0;
2418 while (lpStr2[len2] != 0) ++len2;
2419 if (len2 == 0)
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]))
2426 break;
2427 if (i >= len2)
2428 return ((LPWSTR)lpStr1);
2430 ++lpStr1; --len1;
2432 return (NULL);
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.
2450 * PARAMS
2451 * hdpa [I] handle to the dynamic pointer array
2452 * enumProc [I]
2453 * lParam [I]
2455 * RETURNS
2456 * none
2459 VOID WINAPI
2460 DPA_EnumCallback (HDPA hdpa, PFNDPAENUMCALLBACK enumProc, LPVOID lParam)
2462 INT i;
2464 TRACE("(%p %p %p)\n", hdpa, enumProc, lParam);
2466 if (!hdpa)
2467 return;
2468 if (hdpa->nItemCount <= 0)
2469 return;
2471 for (i = 0; i < hdpa->nItemCount; i++) {
2472 if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
2473 return;
2476 return;
2480 /**************************************************************************
2481 * DPA_DestroyCallback [COMCTL32.386]
2483 * Enumerates all items in a dynamic pointer array and destroys it.
2485 * PARAMS
2486 * hdpa [I] handle to the dynamic pointer array
2487 * enumProc [I]
2488 * lParam [I]
2490 * RETURNS
2491 * none
2494 void WINAPI
2495 DPA_DestroyCallback (HDPA hdpa, PFNDPAENUMCALLBACK enumProc, LPVOID lParam)
2497 TRACE("(%p %p %p)\n", hdpa, enumProc, lParam);
2499 DPA_EnumCallback (hdpa, enumProc, lParam);
2500 DPA_Destroy (hdpa);
2504 /**************************************************************************
2505 * DSA_EnumCallback [COMCTL32.387]
2507 * Enumerates all items in a dynamic storage array.
2509 * PARAMS
2510 * hdsa [I] handle to the dynamic storage array
2511 * enumProc [I]
2512 * lParam [I]
2514 * RETURNS
2515 * none
2518 VOID WINAPI
2519 DSA_EnumCallback (HDSA hdsa, PFNDSAENUMCALLBACK enumProc, LPVOID lParam)
2521 INT i;
2523 TRACE("(%p %p %p)\n", hdsa, enumProc, lParam);
2525 if (!hdsa)
2526 return;
2527 if (hdsa->nItemCount <= 0)
2528 return;
2530 for (i = 0; i < hdsa->nItemCount; i++) {
2531 LPVOID lpItem = DSA_GetItemPtr (hdsa, i);
2532 if ((enumProc)(lpItem, lParam) == 0)
2533 return;
2536 return;
2540 /**************************************************************************
2541 * DSA_DestroyCallback [COMCTL32.388]
2543 * Enumerates all items in a dynamic storage array and destroys it.
2545 * PARAMS
2546 * hdsa [I] handle to the dynamic storage array
2547 * enumProc [I]
2548 * lParam [I]
2550 * RETURNS
2551 * none
2554 void WINAPI
2555 DSA_DestroyCallback (HDSA hdsa, PFNDSAENUMCALLBACK enumProc, LPVOID lParam)
2557 TRACE("(%p %p %p)\n", hdsa, enumProc, lParam);
2559 DSA_EnumCallback (hdsa, enumProc, lParam);
2560 DSA_Destroy (hdsa);
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);
2615 return 0;
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;
2635 lpGotIt = lpStart;
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;
2685 /* validate ptr */
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 /**************************************************************************
2698 * @ [COMCTL32.415]
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);
2709 return TRUE;
2712 /**************************************************************************
2713 * @ [COMCTL32.417]
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 /**************************************************************************
2723 * @ [COMCTL32.419]
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);
2733 return TRUE;