| 1 | /* | 
|---|
| 2 | * Undocumented functions from COMCTL32.DLL | 
|---|
| 3 | * | 
|---|
| 4 | * Copyright 1998 Eric Kohl | 
|---|
| 5 | *           1998 Juergen Schmied <j.schmied@metronet.de> | 
|---|
| 6 | *           2000 Eric Kohl for CodeWeavers | 
|---|
| 7 | * | 
|---|
| 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. | 
|---|
| 12 | * | 
|---|
| 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. | 
|---|
| 17 | * | 
|---|
| 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 | 
|---|
| 21 | * | 
|---|
| 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). | 
|---|
| 27 | * | 
|---|
| 28 | * TODO | 
|---|
| 29 | *     - Add more functions. | 
|---|
| 30 | *     - Write some documentation. | 
|---|
| 31 | */ | 
|---|
| 32 | #ifdef __WIN32OS2__ | 
|---|
| 33 | #define WINE_LARGE_INTEGER | 
|---|
| 34 | #endif | 
|---|
| 35 |  | 
|---|
| 36 | #include <string.h> | 
|---|
| 37 | #include <stdlib.h> /* atoi */ | 
|---|
| 38 | #include <ctype.h> | 
|---|
| 39 | #include <limits.h> | 
|---|
| 40 |  | 
|---|
| 41 | #include "commctrl.h" | 
|---|
| 42 | #include "objbase.h" | 
|---|
| 43 | #include "winbase.h" | 
|---|
| 44 | #include "winerror.h" | 
|---|
| 45 | #include "winreg.h" | 
|---|
| 46 |  | 
|---|
| 47 | #include "wine/unicode.h" | 
|---|
| 48 | #include "comctl32.h" | 
|---|
| 49 |  | 
|---|
| 50 | #include "wine/debug.h" | 
|---|
| 51 |  | 
|---|
| 52 | WINE_DEFAULT_DEBUG_CHANNEL(commctrl); | 
|---|
| 53 |  | 
|---|
| 54 |  | 
|---|
| 55 | extern HANDLE COMCTL32_hHeap; /* handle to the private heap */ | 
|---|
| 56 |  | 
|---|
| 57 |  | 
|---|
| 58 | typedef struct _STREAMDATA | 
|---|
| 59 | { | 
|---|
| 60 | DWORD dwSize; | 
|---|
| 61 | DWORD dwData2; | 
|---|
| 62 | DWORD dwItems; | 
|---|
| 63 | } STREAMDATA, *PSTREAMDATA; | 
|---|
| 64 |  | 
|---|
| 65 | typedef struct _LOADDATA | 
|---|
| 66 | { | 
|---|
| 67 | INT   nCount; | 
|---|
| 68 | PVOID ptr; | 
|---|
| 69 | } LOADDATA, *LPLOADDATA; | 
|---|
| 70 |  | 
|---|
| 71 | #ifdef __WIN32OS2__ | 
|---|
| 72 | typedef HRESULT (* CALLBACK DPALOADPROC)(LPLOADDATA,IStream*,LPARAM); | 
|---|
| 73 | #else | 
|---|
| 74 | typedef HRESULT (CALLBACK *DPALOADPROC)(LPLOADDATA,IStream*,LPARAM); | 
|---|
| 75 | #endif | 
|---|
| 76 |  | 
|---|
| 77 | INT __cdecl _wtoi(LPWSTR string); | 
|---|
| 78 |  | 
|---|
| 79 | /************************************************************************** | 
|---|
| 80 | * DPA_LoadStream [COMCTL32.9] | 
|---|
| 81 | * | 
|---|
| 82 | * Loads a dynamic pointer array from a stream | 
|---|
| 83 | * | 
|---|
| 84 | * PARAMS | 
|---|
| 85 | *     phDpa    [O] pointer to a handle to a dynamic pointer array | 
|---|
| 86 | *     loadProc [I] pointer to a callback function | 
|---|
| 87 | *     pStream  [I] pointer to a stream | 
|---|
| 88 | *     lParam   [I] application specific value | 
|---|
| 89 | * | 
|---|
| 90 | * NOTES | 
|---|
| 91 | *     No more information available yet! | 
|---|
| 92 | */ | 
|---|
| 93 |  | 
|---|
| 94 | HRESULT WINAPI | 
|---|
| 95 | DPA_LoadStream (HDPA *phDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam) | 
|---|
| 96 | { | 
|---|
| 97 | HRESULT errCode; | 
|---|
| 98 | LARGE_INTEGER position; | 
|---|
| 99 | ULARGE_INTEGER newPosition; | 
|---|
| 100 | STREAMDATA  streamData; | 
|---|
| 101 | LOADDATA loadData; | 
|---|
| 102 | ULONG ulRead; | 
|---|
| 103 | HDPA hDpa; | 
|---|
| 104 | PVOID *ptr; | 
|---|
| 105 |  | 
|---|
| 106 | FIXME ("phDpa=%p loadProc=%p pStream=%p lParam=%lx\n", | 
|---|
| 107 | phDpa, loadProc, pStream, lParam); | 
|---|
| 108 |  | 
|---|
| 109 | if (!phDpa || !loadProc || !pStream) | 
|---|
| 110 | return E_INVALIDARG; | 
|---|
| 111 |  | 
|---|
| 112 | *phDpa = (HDPA)NULL; | 
|---|
| 113 |  | 
|---|
| 114 | position.s.LowPart = 0; | 
|---|
| 115 | position.s.HighPart = 0; | 
|---|
| 116 |  | 
|---|
| 117 | /* | 
|---|
| 118 | * Zero out our streamData | 
|---|
| 119 | */ | 
|---|
| 120 | memset(&streamData,0,sizeof(STREAMDATA)); | 
|---|
| 121 |  | 
|---|
| 122 | errCode = IStream_Seek (pStream, position, STREAM_SEEK_CUR, &newPosition); | 
|---|
| 123 | if (errCode != S_OK) | 
|---|
| 124 | return errCode; | 
|---|
| 125 |  | 
|---|
| 126 | errCode = IStream_Read (pStream, &streamData, sizeof(STREAMDATA), &ulRead); | 
|---|
| 127 | if (errCode != S_OK) | 
|---|
| 128 | return errCode; | 
|---|
| 129 |  | 
|---|
| 130 | FIXME ("dwSize=%lu dwData2=%lu dwItems=%lu\n", | 
|---|
| 131 | streamData.dwSize, streamData.dwData2, streamData.dwItems); | 
|---|
| 132 |  | 
|---|
| 133 | if ( ulRead < sizeof(STREAMDATA) || | 
|---|
| 134 | lParam < sizeof(STREAMDATA) || | 
|---|
| 135 | streamData.dwSize < sizeof(STREAMDATA) || | 
|---|
| 136 | streamData.dwData2 < 1) { | 
|---|
| 137 | errCode = E_FAIL; | 
|---|
| 138 | } | 
|---|
| 139 |  | 
|---|
| 140 | if (streamData.dwItems > (UINT_MAX / 2 / sizeof(VOID*))) /* 536870911 */ | 
|---|
| 141 | return E_OUTOFMEMORY; | 
|---|
| 142 |  | 
|---|
| 143 | /* create the dpa */ | 
|---|
| 144 | hDpa = DPA_Create (streamData.dwItems); | 
|---|
| 145 | if (!hDpa) | 
|---|
| 146 | return E_OUTOFMEMORY; | 
|---|
| 147 |  | 
|---|
| 148 | if (!DPA_Grow (hDpa, streamData.dwItems)) | 
|---|
| 149 | return E_OUTOFMEMORY; | 
|---|
| 150 |  | 
|---|
| 151 | /* load data from the stream into the dpa */ | 
|---|
| 152 | ptr = hDpa->ptrs; | 
|---|
| 153 | for (loadData.nCount = 0; loadData.nCount < streamData.dwItems; loadData.nCount++) { | 
|---|
| 154 | errCode = (loadProc)(&loadData, pStream, lParam); | 
|---|
| 155 | if (errCode != S_OK) { | 
|---|
| 156 | errCode = S_FALSE; | 
|---|
| 157 | break; | 
|---|
| 158 | } | 
|---|
| 159 |  | 
|---|
| 160 | *ptr = loadData.ptr; | 
|---|
| 161 | ptr++; | 
|---|
| 162 | } | 
|---|
| 163 |  | 
|---|
| 164 | /* set the number of items */ | 
|---|
| 165 | hDpa->nItemCount = loadData.nCount; | 
|---|
| 166 |  | 
|---|
| 167 | /* store the handle to the dpa */ | 
|---|
| 168 | *phDpa = hDpa; | 
|---|
| 169 | FIXME ("new hDpa=%p\n", hDpa); | 
|---|
| 170 |  | 
|---|
| 171 | return errCode; | 
|---|
| 172 | } | 
|---|
| 173 |  | 
|---|
| 174 |  | 
|---|
| 175 | /************************************************************************** | 
|---|
| 176 | * DPA_SaveStream [COMCTL32.10] | 
|---|
| 177 | * | 
|---|
| 178 | * Saves a dynamic pointer array to a stream | 
|---|
| 179 | * | 
|---|
| 180 | * PARAMS | 
|---|
| 181 | *     hDpa     [I] handle to a dynamic pointer array | 
|---|
| 182 | *     loadProc [I] pointer to a callback function | 
|---|
| 183 | *     pStream  [I] pointer to a stream | 
|---|
| 184 | *     lParam   [I] application specific value | 
|---|
| 185 | * | 
|---|
| 186 | * NOTES | 
|---|
| 187 | *     No more information available yet! | 
|---|
| 188 | */ | 
|---|
| 189 |  | 
|---|
| 190 | HRESULT WINAPI | 
|---|
| 191 | DPA_SaveStream (const HDPA hDpa, DPALOADPROC loadProc, IStream *pStream, LPARAM lParam) | 
|---|
| 192 | { | 
|---|
| 193 |  | 
|---|
| 194 | FIXME ("hDpa=%p loadProc=%p pStream=%p lParam=%lx\n", | 
|---|
| 195 | hDpa, loadProc, pStream, lParam); | 
|---|
| 196 |  | 
|---|
| 197 | return E_FAIL; | 
|---|
| 198 | } | 
|---|
| 199 |  | 
|---|
| 200 |  | 
|---|
| 201 | /************************************************************************** | 
|---|
| 202 | * DPA_Merge [COMCTL32.11] | 
|---|
| 203 | * | 
|---|
| 204 | * PARAMS | 
|---|
| 205 | *     hdpa1       [I] handle to a dynamic pointer array | 
|---|
| 206 | *     hdpa2       [I] handle to a dynamic pointer array | 
|---|
| 207 | *     dwFlags     [I] flags | 
|---|
| 208 | *     pfnCompare  [I] pointer to sort function | 
|---|
| 209 | *     pfnMerge    [I] pointer to merge function | 
|---|
| 210 | *     lParam      [I] application specific value | 
|---|
| 211 | * | 
|---|
| 212 | * NOTES | 
|---|
| 213 | *     No more information available yet! | 
|---|
| 214 | */ | 
|---|
| 215 |  | 
|---|
| 216 | BOOL WINAPI | 
|---|
| 217 | DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags, | 
|---|
| 218 | PFNDPACOMPARE pfnCompare, PFNDPAMERGE pfnMerge, LPARAM lParam) | 
|---|
| 219 | { | 
|---|
| 220 | INT nCount; | 
|---|
| 221 | LPVOID *pWork1, *pWork2; | 
|---|
| 222 | INT nResult, i; | 
|---|
| 223 | INT nIndex; | 
|---|
| 224 |  | 
|---|
| 225 | TRACE("%p %p %08lx %p %p %08lx)\n", | 
|---|
| 226 | hdpa1, hdpa2, dwFlags, pfnCompare, pfnMerge, lParam); | 
|---|
| 227 |  | 
|---|
| 228 | if (IsBadWritePtr (hdpa1, sizeof(DPA))) | 
|---|
| 229 | return FALSE; | 
|---|
| 230 |  | 
|---|
| 231 | if (IsBadWritePtr (hdpa2, sizeof(DPA))) | 
|---|
| 232 | return FALSE; | 
|---|
| 233 |  | 
|---|
| 234 | if (IsBadCodePtr ((FARPROC)pfnCompare)) | 
|---|
| 235 | return FALSE; | 
|---|
| 236 |  | 
|---|
| 237 | if (IsBadCodePtr ((FARPROC)pfnMerge)) | 
|---|
| 238 | return FALSE; | 
|---|
| 239 |  | 
|---|
| 240 | if (!(dwFlags & DPAM_NOSORT)) { | 
|---|
| 241 | TRACE("sorting dpa's!\n"); | 
|---|
| 242 | if (hdpa1->nItemCount > 0) | 
|---|
| 243 | DPA_Sort (hdpa1, pfnCompare, lParam); | 
|---|
| 244 | TRACE ("dpa 1 sorted!\n"); | 
|---|
| 245 | if (hdpa2->nItemCount > 0) | 
|---|
| 246 | DPA_Sort (hdpa2, pfnCompare, lParam); | 
|---|
| 247 | TRACE ("dpa 2 sorted!\n"); | 
|---|
| 248 | } | 
|---|
| 249 |  | 
|---|
| 250 | if (hdpa2->nItemCount < 1) | 
|---|
| 251 | return TRUE; | 
|---|
| 252 |  | 
|---|
| 253 | TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n", | 
|---|
| 254 | hdpa1->nItemCount, hdpa2->nItemCount); | 
|---|
| 255 |  | 
|---|
| 256 |  | 
|---|
| 257 | /* working but untrusted implementation */ | 
|---|
| 258 |  | 
|---|
| 259 | pWork1 = &(hdpa1->ptrs[hdpa1->nItemCount - 1]); | 
|---|
| 260 | pWork2 = &(hdpa2->ptrs[hdpa2->nItemCount - 1]); | 
|---|
| 261 |  | 
|---|
| 262 | nIndex = hdpa1->nItemCount - 1; | 
|---|
| 263 | nCount = hdpa2->nItemCount - 1; | 
|---|
| 264 |  | 
|---|
| 265 | do | 
|---|
| 266 | { | 
|---|
| 267 | if (nIndex < 0) { | 
|---|
| 268 | if ((nCount >= 0) && (dwFlags & DPAM_INSERT)) { | 
|---|
| 269 | /* Now insert the remaining new items into DPA 1 */ | 
|---|
| 270 | TRACE("%d items to be inserted at start of DPA 1\n", | 
|---|
| 271 | nCount+1); | 
|---|
| 272 | for (i=nCount; i>=0; i--) { | 
|---|
| 273 | PVOID ptr; | 
|---|
| 274 |  | 
|---|
| 275 | ptr = (pfnMerge)(3, *pWork2, NULL, lParam); | 
|---|
| 276 | if (!ptr) | 
|---|
| 277 | return FALSE; | 
|---|
| 278 | DPA_InsertPtr (hdpa1, 0, ptr); | 
|---|
| 279 | pWork2--; | 
|---|
| 280 | } | 
|---|
| 281 | } | 
|---|
| 282 | break; | 
|---|
| 283 | } | 
|---|
| 284 | nResult = (pfnCompare)(*pWork1, *pWork2, lParam); | 
|---|
| 285 | TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n", | 
|---|
| 286 | nResult, nIndex, nCount); | 
|---|
| 287 |  | 
|---|
| 288 | if (nResult == 0) | 
|---|
| 289 | { | 
|---|
| 290 | PVOID ptr; | 
|---|
| 291 |  | 
|---|
| 292 | ptr = (pfnMerge)(1, *pWork1, *pWork2, lParam); | 
|---|
| 293 | if (!ptr) | 
|---|
| 294 | return FALSE; | 
|---|
| 295 |  | 
|---|
| 296 | nCount--; | 
|---|
| 297 | pWork2--; | 
|---|
| 298 | *pWork1 = ptr; | 
|---|
| 299 | nIndex--; | 
|---|
| 300 | pWork1--; | 
|---|
| 301 | } | 
|---|
| 302 | else if (nResult > 0) | 
|---|
| 303 | { | 
|---|
| 304 | /* item in DPA 1 missing from DPA 2 */ | 
|---|
| 305 | if (dwFlags & DPAM_DELETE) | 
|---|
| 306 | { | 
|---|
| 307 | /* Now delete the extra item in DPA1 */ | 
|---|
| 308 | PVOID ptr; | 
|---|
| 309 |  | 
|---|
| 310 | ptr = DPA_DeletePtr (hdpa1, hdpa1->nItemCount - 1); | 
|---|
| 311 |  | 
|---|
| 312 | (pfnMerge)(2, ptr, NULL, lParam); | 
|---|
| 313 | } | 
|---|
| 314 | nIndex--; | 
|---|
| 315 | pWork1--; | 
|---|
| 316 | } | 
|---|
| 317 | else | 
|---|
| 318 | { | 
|---|
| 319 | /* new item in DPA 2 */ | 
|---|
| 320 | if (dwFlags & DPAM_INSERT) | 
|---|
| 321 | { | 
|---|
| 322 | /* Now insert the new item in DPA 1 */ | 
|---|
| 323 | PVOID ptr; | 
|---|
| 324 |  | 
|---|
| 325 | ptr = (pfnMerge)(3, *pWork2, NULL, lParam); | 
|---|
| 326 | if (!ptr) | 
|---|
| 327 | return FALSE; | 
|---|
| 328 | DPA_InsertPtr (hdpa1, nIndex+1, ptr); | 
|---|
| 329 | } | 
|---|
| 330 | nCount--; | 
|---|
| 331 | pWork2--; | 
|---|
| 332 | } | 
|---|
| 333 |  | 
|---|
| 334 | } | 
|---|
| 335 | while (nCount >= 0); | 
|---|
| 336 |  | 
|---|
| 337 | return TRUE; | 
|---|
| 338 | } | 
|---|
| 339 |  | 
|---|
| 340 |  | 
|---|
| 341 | /************************************************************************** | 
|---|
| 342 | * Alloc [COMCTL32.71] | 
|---|
| 343 | * | 
|---|
| 344 | * Allocates memory block from the dll's private heap | 
|---|
| 345 | * | 
|---|
| 346 | * PARAMS | 
|---|
| 347 | *     dwSize [I] size of the allocated memory block | 
|---|
| 348 | * | 
|---|
| 349 | * RETURNS | 
|---|
| 350 | *     Success: pointer to allocated memory block | 
|---|
| 351 | *     Failure: NULL | 
|---|
| 352 | */ | 
|---|
| 353 |  | 
|---|
| 354 | LPVOID WINAPI | 
|---|
| 355 | COMCTL32_Alloc (DWORD dwSize) | 
|---|
| 356 | { | 
|---|
| 357 | LPVOID lpPtr; | 
|---|
| 358 |  | 
|---|
| 359 | TRACE("(0x%lx)\n", dwSize); | 
|---|
| 360 |  | 
|---|
| 361 | lpPtr = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize); | 
|---|
| 362 |  | 
|---|
| 363 | TRACE("-- ret=%p\n", lpPtr); | 
|---|
| 364 |  | 
|---|
| 365 | return lpPtr; | 
|---|
| 366 | } | 
|---|
| 367 |  | 
|---|
| 368 |  | 
|---|
| 369 | /************************************************************************** | 
|---|
| 370 | * ReAlloc [COMCTL32.72] | 
|---|
| 371 | * | 
|---|
| 372 | * Changes the size of an allocated memory block or allocates a memory | 
|---|
| 373 | * block using the dll's private heap. | 
|---|
| 374 | * | 
|---|
| 375 | * PARAMS | 
|---|
| 376 | *     lpSrc  [I] pointer to memory block which will be resized | 
|---|
| 377 | *     dwSize [I] new size of the memory block. | 
|---|
| 378 | * | 
|---|
| 379 | * RETURNS | 
|---|
| 380 | *     Success: pointer to the resized memory block | 
|---|
| 381 | *     Failure: NULL | 
|---|
| 382 | * | 
|---|
| 383 | * NOTES | 
|---|
| 384 | *     If lpSrc is a NULL-pointer, then COMCTL32_ReAlloc allocates a memory | 
|---|
| 385 | *     block like COMCTL32_Alloc. | 
|---|
| 386 | */ | 
|---|
| 387 |  | 
|---|
| 388 | LPVOID WINAPI | 
|---|
| 389 | COMCTL32_ReAlloc (LPVOID lpSrc, DWORD dwSize) | 
|---|
| 390 | { | 
|---|
| 391 | LPVOID lpDest; | 
|---|
| 392 |  | 
|---|
| 393 | TRACE("(%p 0x%08lx)\n", lpSrc, dwSize); | 
|---|
| 394 |  | 
|---|
| 395 | if (lpSrc) | 
|---|
| 396 | lpDest = HeapReAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, lpSrc, dwSize); | 
|---|
| 397 | else | 
|---|
| 398 | lpDest = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize); | 
|---|
| 399 |  | 
|---|
| 400 | TRACE("-- ret=%p\n", lpDest); | 
|---|
| 401 |  | 
|---|
| 402 | return lpDest; | 
|---|
| 403 | } | 
|---|
| 404 |  | 
|---|
| 405 |  | 
|---|
| 406 | /************************************************************************** | 
|---|
| 407 | * Free [COMCTL32.73] | 
|---|
| 408 | * | 
|---|
| 409 | * Frees an allocated memory block from the dll's private heap. | 
|---|
| 410 | * | 
|---|
| 411 | * PARAMS | 
|---|
| 412 | *     lpMem [I] pointer to memory block which will be freed | 
|---|
| 413 | * | 
|---|
| 414 | * RETURNS | 
|---|
| 415 | *     Success: TRUE | 
|---|
| 416 | *     Failure: FALSE | 
|---|
| 417 | */ | 
|---|
| 418 |  | 
|---|
| 419 | BOOL WINAPI | 
|---|
| 420 | COMCTL32_Free (LPVOID lpMem) | 
|---|
| 421 | { | 
|---|
| 422 | TRACE("(%p)\n", lpMem); | 
|---|
| 423 |  | 
|---|
| 424 | return HeapFree (COMCTL32_hHeap, 0, lpMem); | 
|---|
| 425 | } | 
|---|
| 426 |  | 
|---|
| 427 |  | 
|---|
| 428 | /************************************************************************** | 
|---|
| 429 | * GetSize [COMCTL32.74] | 
|---|
| 430 | * | 
|---|
| 431 | * Retrieves the size of the specified memory block from the dll's | 
|---|
| 432 | * private heap. | 
|---|
| 433 | * | 
|---|
| 434 | * PARAMS | 
|---|
| 435 | *     lpMem [I] pointer to an allocated memory block | 
|---|
| 436 | * | 
|---|
| 437 | * RETURNS | 
|---|
| 438 | *     Success: size of the specified memory block | 
|---|
| 439 | *     Failure: 0 | 
|---|
| 440 | */ | 
|---|
| 441 |  | 
|---|
| 442 | DWORD WINAPI | 
|---|
| 443 | COMCTL32_GetSize (LPVOID lpMem) | 
|---|
| 444 | { | 
|---|
| 445 | TRACE("(%p)\n", lpMem); | 
|---|
| 446 |  | 
|---|
| 447 | return HeapSize (COMCTL32_hHeap, 0, lpMem); | 
|---|
| 448 | } | 
|---|
| 449 |  | 
|---|
| 450 |  | 
|---|
| 451 | /************************************************************************** | 
|---|
| 452 | * The MRU-API is a set of functions to manipulate MRU(Most Recently Used) | 
|---|
| 453 | * lists. | 
|---|
| 454 | * | 
|---|
| 455 | * Stored in the reg. as a set of values under a single key.  Each item in the | 
|---|
| 456 | * list has a value name that is a single char. 'a' - 'z', '{', '|' or '}'. | 
|---|
| 457 | * The order of the list is stored with value name 'MRUList' which is a string | 
|---|
| 458 | * containing the value names (i.e. 'a', 'b', etc.) in the relevant order. | 
|---|
| 459 | */ | 
|---|
| 460 |  | 
|---|
| 461 | typedef struct tagCREATEMRULISTA | 
|---|
| 462 | { | 
|---|
| 463 | DWORD  cbSize;        /* size of struct */ | 
|---|
| 464 | DWORD  nMaxItems;     /* max no. of items in list */ | 
|---|
| 465 | DWORD  dwFlags;       /* see below */ | 
|---|
| 466 | HKEY   hKey;          /* root reg. key under which list is saved */ | 
|---|
| 467 | LPCSTR lpszSubKey;    /* reg. subkey */ | 
|---|
| 468 | PROC   lpfnCompare;   /* item compare proc */ | 
|---|
| 469 | } CREATEMRULISTA, *LPCREATEMRULISTA; | 
|---|
| 470 |  | 
|---|
| 471 | typedef struct tagCREATEMRULISTW | 
|---|
| 472 | { | 
|---|
| 473 | DWORD   cbSize;        /* size of struct */ | 
|---|
| 474 | DWORD   nMaxItems;     /* max no. of items in list */ | 
|---|
| 475 | DWORD   dwFlags;       /* see below */ | 
|---|
| 476 | HKEY    hKey;          /* root reg. key under which list is saved */ | 
|---|
| 477 | LPCWSTR lpszSubKey;    /* reg. subkey */ | 
|---|
| 478 | PROC    lpfnCompare;   /* item compare proc */ | 
|---|
| 479 | } CREATEMRULISTW, *LPCREATEMRULISTW; | 
|---|
| 480 |  | 
|---|
| 481 | /* dwFlags */ | 
|---|
| 482 | #define MRUF_STRING_LIST  0 /* list will contain strings */ | 
|---|
| 483 | #define MRUF_BINARY_LIST  1 /* list will contain binary data */ | 
|---|
| 484 | #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */ | 
|---|
| 485 |  | 
|---|
| 486 | /* If list is a string list lpfnCompare has the following prototype | 
|---|
| 487 | * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2) | 
|---|
| 488 | * for binary lists the prototype is | 
|---|
| 489 | * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData) | 
|---|
| 490 | * where cbData is the no. of bytes to compare. | 
|---|
| 491 | * Need to check what return value means identical - 0? | 
|---|
| 492 | */ | 
|---|
| 493 |  | 
|---|
| 494 | typedef struct tagWINEMRUITEM | 
|---|
| 495 | { | 
|---|
| 496 | DWORD          size;        /* size of data stored               */ | 
|---|
| 497 | DWORD          itemFlag;    /* flags                             */ | 
|---|
| 498 | BYTE           datastart; | 
|---|
| 499 | } WINEMRUITEM, *LPWINEMRUITEM; | 
|---|
| 500 |  | 
|---|
| 501 | /* itemFlag */ | 
|---|
| 502 | #define WMRUIF_CHANGED   0x0001 /* this dataitem changed             */ | 
|---|
| 503 |  | 
|---|
| 504 | typedef struct tagWINEMRULIST | 
|---|
| 505 | { | 
|---|
| 506 | CREATEMRULISTW extview;     /* original create information       */ | 
|---|
| 507 | BOOL           isUnicode;   /* is compare fn Unicode */ | 
|---|
| 508 | DWORD          wineFlags;   /* internal flags                    */ | 
|---|
| 509 | DWORD          cursize;     /* current size of realMRU           */ | 
|---|
| 510 | LPSTR          realMRU;     /* pointer to string of index names  */ | 
|---|
| 511 | LPWINEMRUITEM  *array;      /* array of pointers to data         */ | 
|---|
| 512 | /* in 'a' to 'z' order               */ | 
|---|
| 513 | } WINEMRULIST, *LPWINEMRULIST; | 
|---|
| 514 |  | 
|---|
| 515 | /* wineFlags */ | 
|---|
| 516 | #define WMRUF_CHANGED  0x0001   /* MRU list has changed              */ | 
|---|
| 517 |  | 
|---|
| 518 | /************************************************************************** | 
|---|
| 519 | *              MRU_SaveChanged - Localize MRU saving code | 
|---|
| 520 | * | 
|---|
| 521 | */ | 
|---|
| 522 | VOID MRU_SaveChanged( LPWINEMRULIST mp ) | 
|---|
| 523 | { | 
|---|
| 524 | INT i, err; | 
|---|
| 525 | HKEY newkey; | 
|---|
| 526 | WCHAR realname[2]; | 
|---|
| 527 | LPWINEMRUITEM witem; | 
|---|
| 528 | WCHAR emptyW[] = {'\0'}; | 
|---|
| 529 |  | 
|---|
| 530 | /* or should we do the following instead of RegOpenKeyEx: | 
|---|
| 531 | */ | 
|---|
| 532 |  | 
|---|
| 533 | /* open the sub key */ | 
|---|
| 534 | if ((err = RegOpenKeyExW( mp->extview.hKey, mp->extview.lpszSubKey, | 
|---|
| 535 | 0, KEY_WRITE, &newkey))) { | 
|---|
| 536 | /* not present - what to do ??? */ | 
|---|
| 537 | ERR("Can not open key, error=%d, attempting to create\n", | 
|---|
| 538 | err); | 
|---|
| 539 | if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey, | 
|---|
| 540 | 0, | 
|---|
| 541 | emptyW, | 
|---|
| 542 | REG_OPTION_NON_VOLATILE, | 
|---|
| 543 | KEY_READ | KEY_WRITE, | 
|---|
| 544 | 0, | 
|---|
| 545 | &newkey, | 
|---|
| 546 | 0))) { | 
|---|
| 547 | ERR("failed to create key /%s/, err=%d\n", | 
|---|
| 548 | debugstr_w(mp->extview.lpszSubKey), err); | 
|---|
| 549 | return; | 
|---|
| 550 | } | 
|---|
| 551 | } | 
|---|
| 552 | if (mp->wineFlags & WMRUF_CHANGED) { | 
|---|
| 553 | mp->wineFlags &= ~WMRUF_CHANGED; | 
|---|
| 554 | err = RegSetValueExA(newkey, "MRUList", 0, REG_SZ, | 
|---|
| 555 | mp->realMRU, strlen(mp->realMRU) + 1); | 
|---|
| 556 | if (err) { | 
|---|
| 557 | ERR("error saving MRUList, err=%d\n", err); | 
|---|
| 558 | } | 
|---|
| 559 | TRACE("saving MRUList=/%s/\n", mp->realMRU); | 
|---|
| 560 | } | 
|---|
| 561 | realname[1] = 0; | 
|---|
| 562 | for(i=0; i<mp->cursize; i++) { | 
|---|
| 563 | witem = mp->array[i]; | 
|---|
| 564 | if (witem->itemFlag & WMRUIF_CHANGED) { | 
|---|
| 565 | witem->itemFlag &= ~WMRUIF_CHANGED; | 
|---|
| 566 | realname[0] = 'a' + i; | 
|---|
| 567 | err = RegSetValueExW(newkey, realname, 0, | 
|---|
| 568 | (mp->extview.dwFlags & MRUF_BINARY_LIST) ? | 
|---|
| 569 | REG_BINARY : REG_SZ, | 
|---|
| 570 | &witem->datastart, witem->size); | 
|---|
| 571 | if (err) { | 
|---|
| 572 | ERR("error saving /%s/, err=%d\n", debugstr_w(realname), err); | 
|---|
| 573 | } | 
|---|
| 574 | TRACE("saving value for name /%s/ size=%ld\n", | 
|---|
| 575 | debugstr_w(realname), witem->size); | 
|---|
| 576 | } | 
|---|
| 577 | } | 
|---|
| 578 | RegCloseKey( newkey ); | 
|---|
| 579 | } | 
|---|
| 580 |  | 
|---|
| 581 | /************************************************************************** | 
|---|
| 582 | *              FreeMRUList [COMCTL32.152] | 
|---|
| 583 | * | 
|---|
| 584 | * PARAMS | 
|---|
| 585 | *     hMRUList [I] Handle to list. | 
|---|
| 586 | * | 
|---|
| 587 | */ | 
|---|
| 588 | DWORD WINAPI | 
|---|
| 589 | FreeMRUList (HANDLE hMRUList) | 
|---|
| 590 | { | 
|---|
| 591 | LPWINEMRULIST mp = (LPWINEMRULIST)hMRUList; | 
|---|
| 592 | INT i; | 
|---|
| 593 |  | 
|---|
| 594 | TRACE("\n"); | 
|---|
| 595 | if (mp->wineFlags & WMRUF_CHANGED) { | 
|---|
| 596 | /* need to open key and then save the info */ | 
|---|
| 597 | MRU_SaveChanged( mp ); | 
|---|
| 598 | } | 
|---|
| 599 |  | 
|---|
| 600 | for(i=0; i<mp->extview.nMaxItems; i++) { | 
|---|
| 601 | if (mp->array[i]) | 
|---|
| 602 | COMCTL32_Free(mp->array[i]); | 
|---|
| 603 | } | 
|---|
| 604 | COMCTL32_Free(mp->realMRU); | 
|---|
| 605 | COMCTL32_Free(mp->array); | 
|---|
| 606 | COMCTL32_Free((LPWSTR)mp->extview.lpszSubKey); | 
|---|
| 607 | return COMCTL32_Free(mp); | 
|---|
| 608 | } | 
|---|
| 609 |  | 
|---|
| 610 |  | 
|---|
| 611 | /************************************************************************** | 
|---|
| 612 | *                  FindMRUData [COMCTL32.169] | 
|---|
| 613 | * | 
|---|
| 614 | * Searches binary list for item that matches lpData of length cbData. | 
|---|
| 615 | * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value | 
|---|
| 616 | * corresponding to item's reg. name will be stored in it ('a' -> 0). | 
|---|
| 617 | * | 
|---|
| 618 | * PARAMS | 
|---|
| 619 | *    hList [I] list handle | 
|---|
| 620 | *    lpData [I] data to find | 
|---|
| 621 | *    cbData [I] length of data | 
|---|
| 622 | *    lpRegNum [O] position in registry (maybe NULL) | 
|---|
| 623 | * | 
|---|
| 624 | * RETURNS | 
|---|
| 625 | *    Position in list 0 -> MRU.  -1 if item not found. | 
|---|
| 626 | */ | 
|---|
| 627 | INT WINAPI | 
|---|
| 628 | FindMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum) | 
|---|
| 629 | { | 
|---|
| 630 | LPWINEMRULIST mp = (LPWINEMRULIST)hList; | 
|---|
| 631 | INT i, ret; | 
|---|
| 632 | LPSTR dataA = NULL; | 
|---|
| 633 |  | 
|---|
| 634 | if (!mp->extview.lpfnCompare) { | 
|---|
| 635 | ERR("MRU list not properly created. No compare procedure.\n"); | 
|---|
| 636 | return -1; | 
|---|
| 637 | } | 
|---|
| 638 |  | 
|---|
| 639 | if(!(mp->extview.dwFlags & MRUF_BINARY_LIST) && !mp->isUnicode) { | 
|---|
| 640 | DWORD len = WideCharToMultiByte(CP_ACP, 0, lpData, -1, | 
|---|
| 641 | NULL, 0, NULL, NULL); | 
|---|
| 642 | dataA = COMCTL32_Alloc(len); | 
|---|
| 643 | WideCharToMultiByte(CP_ACP, 0, lpData, -1, dataA, len, NULL, NULL); | 
|---|
| 644 | } | 
|---|
| 645 |  | 
|---|
| 646 | for(i=0; i<mp->cursize; i++) { | 
|---|
| 647 | if (mp->extview.dwFlags & MRUF_BINARY_LIST) { | 
|---|
| 648 | if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart, | 
|---|
| 649 | cbData)) | 
|---|
| 650 | break; | 
|---|
| 651 | } | 
|---|
| 652 | else { | 
|---|
| 653 | if(mp->isUnicode) { | 
|---|
| 654 | if (!mp->extview.lpfnCompare(lpData, &mp->array[i]->datastart)) | 
|---|
| 655 | break; | 
|---|
| 656 | } else { | 
|---|
| 657 | DWORD len = WideCharToMultiByte(CP_ACP, 0, | 
|---|
| 658 | (LPWSTR)&mp->array[i]->datastart, -1, | 
|---|
| 659 | NULL, 0, NULL, NULL); | 
|---|
| 660 | LPSTR itemA = COMCTL32_Alloc(len); | 
|---|
| 661 | INT cmp; | 
|---|
| 662 | WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&mp->array[i]->datastart, -1, | 
|---|
| 663 | itemA, len, NULL, NULL); | 
|---|
| 664 |  | 
|---|
| 665 | cmp = mp->extview.lpfnCompare(dataA, itemA); | 
|---|
| 666 | COMCTL32_Free(itemA); | 
|---|
| 667 | if(!cmp) | 
|---|
| 668 | break; | 
|---|
| 669 | } | 
|---|
| 670 | } | 
|---|
| 671 | } | 
|---|
| 672 | if(dataA) | 
|---|
| 673 | COMCTL32_Free(dataA); | 
|---|
| 674 | if (i < mp->cursize) | 
|---|
| 675 | ret = i; | 
|---|
| 676 | else | 
|---|
| 677 | ret = -1; | 
|---|
| 678 | if (lpRegNum && (ret != -1)) | 
|---|
| 679 | *lpRegNum = 'a' + i; | 
|---|
| 680 |  | 
|---|
| 681 | TRACE("(%08x, %p, %ld, %p) returning %d\n", | 
|---|
| 682 | hList, lpData, cbData, lpRegNum, ret); | 
|---|
| 683 |  | 
|---|
| 684 | return ret; | 
|---|
| 685 | } | 
|---|
| 686 |  | 
|---|
| 687 |  | 
|---|
| 688 | /************************************************************************** | 
|---|
| 689 | *              AddMRUData [COMCTL32.167] | 
|---|
| 690 | * | 
|---|
| 691 | * Add item to MRU binary list.  If item already exists in list then it is | 
|---|
| 692 | * simply moved up to the top of the list and not added again.  If list is | 
|---|
| 693 | * full then the least recently used item is removed to make room. | 
|---|
| 694 | * | 
|---|
| 695 | * PARAMS | 
|---|
| 696 | *     hList [I] Handle to list. | 
|---|
| 697 | *     lpData [I] ptr to data to add. | 
|---|
| 698 | *     cbData [I] no. of bytes of data. | 
|---|
| 699 | * | 
|---|
| 700 | * RETURNS | 
|---|
| 701 | *     No. corresponding to registry name where value is stored 'a' -> 0 etc. | 
|---|
| 702 | *     -1 on error. | 
|---|
| 703 | */ | 
|---|
| 704 | INT WINAPI | 
|---|
| 705 | AddMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData) | 
|---|
| 706 | { | 
|---|
| 707 | LPWINEMRULIST mp = (LPWINEMRULIST)hList; | 
|---|
| 708 | LPWINEMRUITEM witem; | 
|---|
| 709 | INT i, replace, ret; | 
|---|
| 710 |  | 
|---|
| 711 | if ((replace = FindMRUData (hList, lpData, cbData, NULL)) < 0) { | 
|---|
| 712 | /* either add a new entry or replace oldest */ | 
|---|
| 713 | if (mp->cursize < mp->extview.nMaxItems) { | 
|---|
| 714 | /* Add in a new item */ | 
|---|
| 715 | replace = mp->cursize; | 
|---|
| 716 | mp->cursize++; | 
|---|
| 717 | } | 
|---|
| 718 | else { | 
|---|
| 719 | /* get the oldest entry and replace data */ | 
|---|
| 720 | replace = mp->realMRU[mp->cursize - 1] - 'a'; | 
|---|
| 721 | COMCTL32_Free(mp->array[replace]); | 
|---|
| 722 | } | 
|---|
| 723 | } | 
|---|
| 724 | else { | 
|---|
| 725 | /* free up the old data */ | 
|---|
| 726 | COMCTL32_Free(mp->array[replace]); | 
|---|
| 727 | } | 
|---|
| 728 |  | 
|---|
| 729 | /* Allocate space for new item and move in the data */ | 
|---|
| 730 | mp->array[replace] = witem = (LPWINEMRUITEM)COMCTL32_Alloc(cbData + | 
|---|
| 731 | sizeof(WINEMRUITEM)); | 
|---|
| 732 | witem->itemFlag |= WMRUIF_CHANGED; | 
|---|
| 733 | witem->size = cbData; | 
|---|
| 734 | memcpy( &witem->datastart, lpData, cbData); | 
|---|
| 735 |  | 
|---|
| 736 | /* now rotate MRU list */ | 
|---|
| 737 | mp->wineFlags |= WMRUF_CHANGED; | 
|---|
| 738 | for(i=mp->cursize-1; i>=1; i--) { | 
|---|
| 739 | mp->realMRU[i] = mp->realMRU[i-1]; | 
|---|
| 740 | } | 
|---|
| 741 | mp->realMRU[0] = replace + 'a'; | 
|---|
| 742 | TRACE("(%08x, %p, %ld) adding data, /%c/ now most current\n", | 
|---|
| 743 | hList, lpData, cbData, replace+'a'); | 
|---|
| 744 | ret = replace; | 
|---|
| 745 |  | 
|---|
| 746 | if (!(mp->extview.dwFlags & MRUF_DELAYED_SAVE)) { | 
|---|
| 747 | /* save changed stuff right now */ | 
|---|
| 748 | MRU_SaveChanged( mp ); | 
|---|
| 749 | } | 
|---|
| 750 |  | 
|---|
| 751 | return ret; | 
|---|
| 752 | } | 
|---|
| 753 |  | 
|---|
| 754 | /************************************************************************** | 
|---|
| 755 | *              AddMRUStringW [COMCTL32.401] | 
|---|
| 756 | * | 
|---|
| 757 | * Add item to MRU string list.  If item already exists in list them it is | 
|---|
| 758 | * simply moved up to the top of the list and not added again.  If list is | 
|---|
| 759 | * full then the least recently used item is removed to make room. | 
|---|
| 760 | * | 
|---|
| 761 | * PARAMS | 
|---|
| 762 | *     hList [I] Handle to list. | 
|---|
| 763 | *     lpszString [I] ptr to string to add. | 
|---|
| 764 | * | 
|---|
| 765 | * RETURNS | 
|---|
| 766 | *     No. corresponding to registry name where value is stored 'a' -> 0 etc. | 
|---|
| 767 | *     -1 on error. | 
|---|
| 768 | */ | 
|---|
| 769 | INT WINAPI | 
|---|
| 770 | AddMRUStringW(HANDLE hList, LPCWSTR lpszString) | 
|---|
| 771 | { | 
|---|
| 772 | FIXME("(%08x, %s) empty stub!\n", hList, debugstr_w(lpszString)); | 
|---|
| 773 |  | 
|---|
| 774 | return 0; | 
|---|
| 775 | } | 
|---|
| 776 |  | 
|---|
| 777 | /************************************************************************** | 
|---|
| 778 | *              AddMRUStringA [COMCTL32.153] | 
|---|
| 779 | */ | 
|---|
| 780 | INT WINAPI | 
|---|
| 781 | AddMRUStringA(HANDLE hList, LPCSTR lpszString) | 
|---|
| 782 | { | 
|---|
| 783 | FIXME("(%08x, %s) empty stub!\n", hList, debugstr_a(lpszString)); | 
|---|
| 784 |  | 
|---|
| 785 | return 0; | 
|---|
| 786 | } | 
|---|
| 787 |  | 
|---|
| 788 | /************************************************************************** | 
|---|
| 789 | *              DelMRUString [COMCTL32.156] | 
|---|
| 790 | * | 
|---|
| 791 | * Removes item from either string or binary list (despite its name) | 
|---|
| 792 | * | 
|---|
| 793 | * PARAMS | 
|---|
| 794 | *    hList [I] list handle | 
|---|
| 795 | *    nItemPos [I] item position to remove 0 -> MRU | 
|---|
| 796 | * | 
|---|
| 797 | * RETURNS | 
|---|
| 798 | *    TRUE if successful, FALSE if nItemPos is out of range. | 
|---|
| 799 | */ | 
|---|
| 800 | BOOL WINAPI | 
|---|
| 801 | DelMRUString(HANDLE hList, INT nItemPos) | 
|---|
| 802 | { | 
|---|
| 803 | FIXME("(%08x, %d): stub\n", hList, nItemPos); | 
|---|
| 804 | return TRUE; | 
|---|
| 805 | } | 
|---|
| 806 |  | 
|---|
| 807 | /************************************************************************** | 
|---|
| 808 | *                  FindMRUStringW [COMCTL32.402] | 
|---|
| 809 | */ | 
|---|
| 810 | INT WINAPI | 
|---|
| 811 | FindMRUStringW (HANDLE hList, LPCWSTR lpszString, LPINT lpRegNum) | 
|---|
| 812 | { | 
|---|
| 813 | FIXME("stub\n"); | 
|---|
| 814 | return -1; | 
|---|
| 815 | } | 
|---|
| 816 |  | 
|---|
| 817 | /************************************************************************** | 
|---|
| 818 | *                  FindMRUStringA [COMCTL32.155] | 
|---|
| 819 | * | 
|---|
| 820 | * Searches string list for item that matches lpszString. | 
|---|
| 821 | * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value | 
|---|
| 822 | * corresponding to item's reg. name will be stored in it ('a' -> 0). | 
|---|
| 823 | * | 
|---|
| 824 | * PARAMS | 
|---|
| 825 | *    hList [I] list handle | 
|---|
| 826 | *    lpszString [I] string to find | 
|---|
| 827 | *    lpRegNum [O] position in registry (maybe NULL) | 
|---|
| 828 | * | 
|---|
| 829 | * RETURNS | 
|---|
| 830 | *    Position in list 0 -> MRU.  -1 if item not found. | 
|---|
| 831 | */ | 
|---|
| 832 | INT WINAPI | 
|---|
| 833 | FindMRUStringA (HANDLE hList, LPCSTR lpszString, LPINT lpRegNum) | 
|---|
| 834 | { | 
|---|
| 835 | DWORD len = MultiByteToWideChar(CP_ACP, 0, lpszString, -1, NULL, 0); | 
|---|
| 836 | LPWSTR stringW = COMCTL32_Alloc(len * sizeof(WCHAR)); | 
|---|
| 837 | INT ret; | 
|---|
| 838 |  | 
|---|
| 839 | MultiByteToWideChar(CP_ACP, 0, lpszString, -1, stringW, len); | 
|---|
| 840 | ret = FindMRUData(hList, stringW, len * sizeof(WCHAR), lpRegNum); | 
|---|
| 841 | COMCTL32_Free(stringW); | 
|---|
| 842 | return ret; | 
|---|
| 843 | } | 
|---|
| 844 |  | 
|---|
| 845 | /************************************************************************* | 
|---|
| 846 | *                 CreateMRUListLazy_common | 
|---|
| 847 | */ | 
|---|
| 848 | HANDLE CreateMRUListLazy_common(LPWINEMRULIST mp) | 
|---|
| 849 | { | 
|---|
| 850 | INT i, err; | 
|---|
| 851 | HKEY newkey; | 
|---|
| 852 | DWORD datasize, dwdisp; | 
|---|
| 853 | WCHAR realname[2]; | 
|---|
| 854 | LPWINEMRUITEM witem; | 
|---|
| 855 | DWORD type; | 
|---|
| 856 | WCHAR emptyW[] = {'\0'}; | 
|---|
| 857 |  | 
|---|
| 858 | /* get space to save indices that will turn into names | 
|---|
| 859 | * but in order of most to least recently used | 
|---|
| 860 | */ | 
|---|
| 861 | mp->realMRU = (LPSTR) COMCTL32_Alloc(mp->extview.nMaxItems + 2); | 
|---|
| 862 |  | 
|---|
| 863 | /* get space to save pointers to actual data in order of | 
|---|
| 864 | * 'a' to 'z' (0 to n). | 
|---|
| 865 | */ | 
|---|
| 866 | mp->array = (LPVOID) COMCTL32_Alloc(mp->extview.nMaxItems * | 
|---|
| 867 | sizeof(LPVOID)); | 
|---|
| 868 |  | 
|---|
| 869 | /* open the sub key */ | 
|---|
| 870 | if ((err = RegCreateKeyExW( mp->extview.hKey, mp->extview.lpszSubKey, | 
|---|
| 871 | 0, | 
|---|
| 872 | emptyW, | 
|---|
| 873 | REG_OPTION_NON_VOLATILE, | 
|---|
| 874 | KEY_READ | KEY_WRITE, | 
|---|
| 875 | 0, | 
|---|
| 876 | &newkey, | 
|---|
| 877 | &dwdisp))) { | 
|---|
| 878 | /* error - what to do ??? */ | 
|---|
| 879 | ERR("(%lu %lu %lx %lx \"%s\" %p): Can not open key, error=%d\n", | 
|---|
| 880 | mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags, | 
|---|
| 881 | (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey), | 
|---|
| 882 | mp->extview.lpfnCompare, err); | 
|---|
| 883 | return 0; | 
|---|
| 884 | } | 
|---|
| 885 |  | 
|---|
| 886 | /* get values from key 'MRUList' */ | 
|---|
| 887 | if (newkey) { | 
|---|
| 888 | datasize = mp->extview.nMaxItems + 1; | 
|---|
| 889 | if((err=RegQueryValueExA( newkey, "MRUList", 0, &type, mp->realMRU, | 
|---|
| 890 | &datasize))) { | 
|---|
| 891 | /* not present - set size to 1 (will become 0 later) */ | 
|---|
| 892 | datasize = 1; | 
|---|
| 893 | *mp->realMRU = 0; | 
|---|
| 894 | } | 
|---|
| 895 |  | 
|---|
| 896 | TRACE("MRU list = %s\n", mp->realMRU); | 
|---|
| 897 |  | 
|---|
| 898 | mp->cursize = datasize - 1; | 
|---|
| 899 | /* datasize now has number of items in the MRUList */ | 
|---|
| 900 |  | 
|---|
| 901 | /* get actual values for each entry */ | 
|---|
| 902 | realname[1] = 0; | 
|---|
| 903 | for(i=0; i<mp->cursize; i++) { | 
|---|
| 904 | realname[0] = 'a' + i; | 
|---|
| 905 | if(RegQueryValueExW( newkey, realname, 0, &type, 0, &datasize)) { | 
|---|
| 906 | /* not present - what to do ??? */ | 
|---|
| 907 | ERR("Key %s not found 1\n", debugstr_w(realname)); | 
|---|
| 908 | } | 
|---|
| 909 | mp->array[i] = witem = (LPWINEMRUITEM)COMCTL32_Alloc(datasize + | 
|---|
| 910 | sizeof(WINEMRUITEM)); | 
|---|
| 911 | witem->size = datasize; | 
|---|
| 912 | if(RegQueryValueExW( newkey, realname, 0, &type, | 
|---|
| 913 | &witem->datastart, &datasize)) { | 
|---|
| 914 | /* not present - what to do ??? */ | 
|---|
| 915 | ERR("Key %s not found 2\n", debugstr_w(realname)); | 
|---|
| 916 | } | 
|---|
| 917 | } | 
|---|
| 918 | RegCloseKey( newkey ); | 
|---|
| 919 | } | 
|---|
| 920 | else | 
|---|
| 921 | mp->cursize = 0; | 
|---|
| 922 |  | 
|---|
| 923 | TRACE("(%lu %lu %lx %lx \"%s\" %p): Current Size = %ld\n", | 
|---|
| 924 | mp->extview.cbSize, mp->extview.nMaxItems, mp->extview.dwFlags, | 
|---|
| 925 | (DWORD)mp->extview.hKey, debugstr_w(mp->extview.lpszSubKey), | 
|---|
| 926 | mp->extview.lpfnCompare, mp->cursize); | 
|---|
| 927 | return (HANDLE)mp; | 
|---|
| 928 | } | 
|---|
| 929 |  | 
|---|
| 930 | /************************************************************************** | 
|---|
| 931 | *                  CreateMRUListLazyW [COMCTL32.404] | 
|---|
| 932 | */ | 
|---|
| 933 | HANDLE WINAPI | 
|---|
| 934 | CreateMRUListLazyW (LPCREATEMRULISTW lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4) | 
|---|
| 935 | { | 
|---|
| 936 | LPWINEMRULIST mp; | 
|---|
| 937 |  | 
|---|
| 938 | if (lpcml == NULL) | 
|---|
| 939 | return 0; | 
|---|
| 940 |  | 
|---|
| 941 | if (lpcml->cbSize < sizeof(CREATEMRULISTW)) | 
|---|
| 942 | return 0; | 
|---|
| 943 |  | 
|---|
| 944 | mp = (LPWINEMRULIST) COMCTL32_Alloc(sizeof(WINEMRULIST)); | 
|---|
| 945 | memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW)); | 
|---|
| 946 | mp->extview.lpszSubKey = COMCTL32_Alloc((strlenW(lpcml->lpszSubKey) + 1) * | 
|---|
| 947 | sizeof(WCHAR)); | 
|---|
| 948 | strcpyW((LPWSTR)mp->extview.lpszSubKey, lpcml->lpszSubKey); | 
|---|
| 949 | mp->isUnicode = TRUE; | 
|---|
| 950 |  | 
|---|
| 951 | return CreateMRUListLazy_common(mp); | 
|---|
| 952 | } | 
|---|
| 953 |  | 
|---|
| 954 | /************************************************************************** | 
|---|
| 955 | *                  CreateMRUListLazyA [COMCTL32.157] | 
|---|
| 956 | */ | 
|---|
| 957 | HANDLE WINAPI | 
|---|
| 958 | CreateMRUListLazyA (LPCREATEMRULISTA lpcml, DWORD dwParam2, DWORD dwParam3, DWORD dwParam4) | 
|---|
| 959 | { | 
|---|
| 960 | LPWINEMRULIST mp; | 
|---|
| 961 | DWORD len; | 
|---|
| 962 |  | 
|---|
| 963 | if (lpcml == NULL) | 
|---|
| 964 | return 0; | 
|---|
| 965 |  | 
|---|
| 966 | if (lpcml->cbSize < sizeof(CREATEMRULISTA)) | 
|---|
| 967 | return 0; | 
|---|
| 968 |  | 
|---|
| 969 | mp = (LPWINEMRULIST) COMCTL32_Alloc(sizeof(WINEMRULIST)); | 
|---|
| 970 | memcpy(&mp->extview, lpcml, sizeof(CREATEMRULISTW)); | 
|---|
| 971 | len = MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1, NULL, 0); | 
|---|
| 972 | mp->extview.lpszSubKey = COMCTL32_Alloc(len * sizeof(WCHAR)); | 
|---|
| 973 | MultiByteToWideChar(CP_ACP, 0, lpcml->lpszSubKey, -1, | 
|---|
| 974 | (LPWSTR)mp->extview.lpszSubKey, len); | 
|---|
| 975 | mp->isUnicode = FALSE; | 
|---|
| 976 | return CreateMRUListLazy_common(mp); | 
|---|
| 977 | } | 
|---|
| 978 |  | 
|---|
| 979 | /************************************************************************** | 
|---|
| 980 | *              CreateMRUListW [COMCTL32.400] | 
|---|
| 981 | * | 
|---|
| 982 | * PARAMS | 
|---|
| 983 | *     lpcml [I] ptr to CREATEMRULIST structure. | 
|---|
| 984 | * | 
|---|
| 985 | * RETURNS | 
|---|
| 986 | *     Handle to MRU list. | 
|---|
| 987 | */ | 
|---|
| 988 | HANDLE WINAPI | 
|---|
| 989 | CreateMRUListW (LPCREATEMRULISTW lpcml) | 
|---|
| 990 | { | 
|---|
| 991 | return CreateMRUListLazyW(lpcml, 0, 0, 0); | 
|---|
| 992 | } | 
|---|
| 993 |  | 
|---|
| 994 | /************************************************************************** | 
|---|
| 995 | *              CreateMRUListA [COMCTL32.151] | 
|---|
| 996 | */ | 
|---|
| 997 | HANDLE WINAPI | 
|---|
| 998 | CreateMRUListA (LPCREATEMRULISTA lpcml) | 
|---|
| 999 | { | 
|---|
| 1000 | return CreateMRUListLazyA (lpcml, 0, 0, 0); | 
|---|
| 1001 | } | 
|---|
| 1002 |  | 
|---|
| 1003 |  | 
|---|
| 1004 | /************************************************************************** | 
|---|
| 1005 | *                EnumMRUListW [COMCTL32.403] | 
|---|
| 1006 | * | 
|---|
| 1007 | * Enumerate item in a list | 
|---|
| 1008 | * | 
|---|
| 1009 | * PARAMS | 
|---|
| 1010 | *    hList [I] list handle | 
|---|
| 1011 | *    nItemPos [I] item position to enumerate | 
|---|
| 1012 | *    lpBuffer [O] buffer to receive item | 
|---|
| 1013 | *    nBufferSize [I] size of buffer | 
|---|
| 1014 | * | 
|---|
| 1015 | * RETURNS | 
|---|
| 1016 | *    For binary lists specifies how many bytes were copied to buffer, for | 
|---|
| 1017 | *    string lists specifies full length of string.  Enumerating past the end | 
|---|
| 1018 | *    of list returns -1. | 
|---|
| 1019 | *    If lpBuffer == NULL or nItemPos is -ve return value is no. of items in | 
|---|
| 1020 | *    the list. | 
|---|
| 1021 | */ | 
|---|
| 1022 | INT WINAPI EnumMRUListW(HANDLE hList, INT nItemPos, LPVOID lpBuffer, | 
|---|
| 1023 | DWORD nBufferSize) | 
|---|
| 1024 | { | 
|---|
| 1025 | LPWINEMRULIST mp = (LPWINEMRULIST) hList; | 
|---|
| 1026 | LPWINEMRUITEM witem; | 
|---|
| 1027 | INT desired, datasize; | 
|---|
| 1028 |  | 
|---|
| 1029 | if (nItemPos >= mp->cursize) return -1; | 
|---|
| 1030 | if ((nItemPos < 0) || !lpBuffer) return mp->cursize; | 
|---|
| 1031 | desired = mp->realMRU[nItemPos]; | 
|---|
| 1032 | desired -= 'a'; | 
|---|
| 1033 | TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired); | 
|---|
| 1034 | witem = mp->array[desired]; | 
|---|
| 1035 | datasize = min( witem->size, nBufferSize ); | 
|---|
| 1036 | memcpy( lpBuffer, &witem->datastart, datasize); | 
|---|
| 1037 | TRACE("(%08x, %d, %p, %ld): returning len=%d\n", | 
|---|
| 1038 | hList, nItemPos, lpBuffer, nBufferSize, datasize); | 
|---|
| 1039 | return datasize; | 
|---|
| 1040 | } | 
|---|
| 1041 |  | 
|---|
| 1042 | /************************************************************************** | 
|---|
| 1043 | *                EnumMRUListA [COMCTL32.154] | 
|---|
| 1044 | * | 
|---|
| 1045 | */ | 
|---|
| 1046 | INT WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer, | 
|---|
| 1047 | DWORD nBufferSize) | 
|---|
| 1048 | { | 
|---|
| 1049 | LPWINEMRULIST mp = (LPWINEMRULIST) hList; | 
|---|
| 1050 | LPWINEMRUITEM witem; | 
|---|
| 1051 | INT desired, datasize; | 
|---|
| 1052 | DWORD lenA; | 
|---|
| 1053 |  | 
|---|
| 1054 | if (nItemPos >= mp->cursize) return -1; | 
|---|
| 1055 | if ((nItemPos < 0) || !lpBuffer) return mp->cursize; | 
|---|
| 1056 | desired = mp->realMRU[nItemPos]; | 
|---|
| 1057 | desired -= 'a'; | 
|---|
| 1058 | TRACE("nItemPos=%d, desired=%d\n", nItemPos, desired); | 
|---|
| 1059 | witem = mp->array[desired]; | 
|---|
| 1060 | if(mp->extview.dwFlags & MRUF_BINARY_LIST) { | 
|---|
| 1061 | datasize = min( witem->size, nBufferSize ); | 
|---|
| 1062 | memcpy( lpBuffer, &witem->datastart, datasize); | 
|---|
| 1063 | } else { | 
|---|
| 1064 | lenA = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1, | 
|---|
| 1065 | NULL, 0, NULL, NULL); | 
|---|
| 1066 | datasize = min( witem->size, nBufferSize ); | 
|---|
| 1067 | WideCharToMultiByte(CP_ACP, 0, (LPWSTR)&witem->datastart, -1, | 
|---|
| 1068 | lpBuffer, datasize, NULL, NULL); | 
|---|
| 1069 | } | 
|---|
| 1070 | TRACE("(%08x, %d, %p, %ld): returning len=%d\n", | 
|---|
| 1071 | hList, nItemPos, lpBuffer, nBufferSize, datasize); | 
|---|
| 1072 | return datasize; | 
|---|
| 1073 | } | 
|---|
| 1074 |  | 
|---|
| 1075 |  | 
|---|
| 1076 | /************************************************************************** | 
|---|
| 1077 | * Str_GetPtrA [COMCTL32.233] | 
|---|
| 1078 | * | 
|---|
| 1079 | * PARAMS | 
|---|
| 1080 | *     lpSrc   [I] | 
|---|
| 1081 | *     lpDest  [O] | 
|---|
| 1082 | *     nMaxLen [I] | 
|---|
| 1083 | * | 
|---|
| 1084 | * RETURNS | 
|---|
| 1085 | */ | 
|---|
| 1086 |  | 
|---|
| 1087 | INT WINAPI | 
|---|
| 1088 | Str_GetPtrA (LPCSTR lpSrc, LPSTR lpDest, INT nMaxLen) | 
|---|
| 1089 | { | 
|---|
| 1090 | INT len; | 
|---|
| 1091 |  | 
|---|
| 1092 | TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen); | 
|---|
| 1093 |  | 
|---|
| 1094 | if (!lpDest && lpSrc) | 
|---|
| 1095 | return strlen (lpSrc); | 
|---|
| 1096 |  | 
|---|
| 1097 | if (nMaxLen == 0) | 
|---|
| 1098 | return 0; | 
|---|
| 1099 |  | 
|---|
| 1100 | if (lpSrc == NULL) { | 
|---|
| 1101 | lpDest[0] = '\0'; | 
|---|
| 1102 | return 0; | 
|---|
| 1103 | } | 
|---|
| 1104 |  | 
|---|
| 1105 | len = strlen (lpSrc); | 
|---|
| 1106 | if (len >= nMaxLen) | 
|---|
| 1107 | len = nMaxLen - 1; | 
|---|
| 1108 |  | 
|---|
| 1109 | RtlMoveMemory (lpDest, lpSrc, len); | 
|---|
| 1110 | lpDest[len] = '\0'; | 
|---|
| 1111 |  | 
|---|
| 1112 | return len; | 
|---|
| 1113 | } | 
|---|
| 1114 |  | 
|---|
| 1115 |  | 
|---|
| 1116 | /************************************************************************** | 
|---|
| 1117 | * Str_SetPtrA [COMCTL32.234] | 
|---|
| 1118 | * | 
|---|
| 1119 | * PARAMS | 
|---|
| 1120 | *     lppDest [O] | 
|---|
| 1121 | *     lpSrc   [I] | 
|---|
| 1122 | * | 
|---|
| 1123 | * RETURNS | 
|---|
| 1124 | */ | 
|---|
| 1125 |  | 
|---|
| 1126 | BOOL WINAPI | 
|---|
| 1127 | Str_SetPtrA (LPSTR *lppDest, LPCSTR lpSrc) | 
|---|
| 1128 | { | 
|---|
| 1129 | TRACE("(%p %p)\n", lppDest, lpSrc); | 
|---|
| 1130 |  | 
|---|
| 1131 | if (lpSrc) { | 
|---|
| 1132 | LPSTR ptr = COMCTL32_ReAlloc (*lppDest, strlen (lpSrc) + 1); | 
|---|
| 1133 | if (!ptr) | 
|---|
| 1134 | return FALSE; | 
|---|
| 1135 | strcpy (ptr, lpSrc); | 
|---|
| 1136 | *lppDest = ptr; | 
|---|
| 1137 | } | 
|---|
| 1138 | else { | 
|---|
| 1139 | if (*lppDest) { | 
|---|
| 1140 | COMCTL32_Free (*lppDest); | 
|---|
| 1141 | *lppDest = NULL; | 
|---|
| 1142 | } | 
|---|
| 1143 | } | 
|---|
| 1144 |  | 
|---|
| 1145 | return TRUE; | 
|---|
| 1146 | } | 
|---|
| 1147 |  | 
|---|
| 1148 |  | 
|---|
| 1149 | /************************************************************************** | 
|---|
| 1150 | * Str_GetPtrW [COMCTL32.235] | 
|---|
| 1151 | * | 
|---|
| 1152 | * PARAMS | 
|---|
| 1153 | *     lpSrc   [I] | 
|---|
| 1154 | *     lpDest  [O] | 
|---|
| 1155 | *     nMaxLen [I] | 
|---|
| 1156 | * | 
|---|
| 1157 | * RETURNS | 
|---|
| 1158 | */ | 
|---|
| 1159 |  | 
|---|
| 1160 | INT WINAPI | 
|---|
| 1161 | Str_GetPtrW (LPCWSTR lpSrc, LPWSTR lpDest, INT nMaxLen) | 
|---|
| 1162 | { | 
|---|
| 1163 | INT len; | 
|---|
| 1164 |  | 
|---|
| 1165 | TRACE("(%p %p %d)\n", lpSrc, lpDest, nMaxLen); | 
|---|
| 1166 |  | 
|---|
| 1167 | if (!lpDest && lpSrc) | 
|---|
| 1168 | return strlenW (lpSrc); | 
|---|
| 1169 |  | 
|---|
| 1170 | if (nMaxLen == 0) | 
|---|
| 1171 | return 0; | 
|---|
| 1172 |  | 
|---|
| 1173 | if (lpSrc == NULL) { | 
|---|
| 1174 | lpDest[0] = L'\0'; | 
|---|
| 1175 | return 0; | 
|---|
| 1176 | } | 
|---|
| 1177 |  | 
|---|
| 1178 | len = strlenW (lpSrc); | 
|---|
| 1179 | if (len >= nMaxLen) | 
|---|
| 1180 | len = nMaxLen - 1; | 
|---|
| 1181 |  | 
|---|
| 1182 | RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR)); | 
|---|
| 1183 | lpDest[len] = L'\0'; | 
|---|
| 1184 |  | 
|---|
| 1185 | return len; | 
|---|
| 1186 | } | 
|---|
| 1187 |  | 
|---|
| 1188 |  | 
|---|
| 1189 | /************************************************************************** | 
|---|
| 1190 | * Str_SetPtrW [COMCTL32.236] | 
|---|
| 1191 | * | 
|---|
| 1192 | * PARAMS | 
|---|
| 1193 | *     lpDest [O] | 
|---|
| 1194 | *     lpSrc  [I] | 
|---|
| 1195 | * | 
|---|
| 1196 | * RETURNS | 
|---|
| 1197 | */ | 
|---|
| 1198 |  | 
|---|
| 1199 | BOOL WINAPI | 
|---|
| 1200 | Str_SetPtrW (LPWSTR *lppDest, LPCWSTR lpSrc) | 
|---|
| 1201 | { | 
|---|
| 1202 | TRACE("(%p %p)\n", lppDest, lpSrc); | 
|---|
| 1203 |  | 
|---|
| 1204 | if (lpSrc) { | 
|---|
| 1205 | INT len = strlenW (lpSrc) + 1; | 
|---|
| 1206 | LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len * sizeof(WCHAR)); | 
|---|
| 1207 | if (!ptr) | 
|---|
| 1208 | return FALSE; | 
|---|
| 1209 | strcpyW (ptr, lpSrc); | 
|---|
| 1210 | *lppDest = ptr; | 
|---|
| 1211 | } | 
|---|
| 1212 | else { | 
|---|
| 1213 | if (*lppDest) { | 
|---|
| 1214 | COMCTL32_Free (*lppDest); | 
|---|
| 1215 | *lppDest = NULL; | 
|---|
| 1216 | } | 
|---|
| 1217 | } | 
|---|
| 1218 |  | 
|---|
| 1219 | return TRUE; | 
|---|
| 1220 | } | 
|---|
| 1221 |  | 
|---|
| 1222 |  | 
|---|
| 1223 | /************************************************************************** | 
|---|
| 1224 | * Str_GetPtrWtoA [internal] | 
|---|
| 1225 | * | 
|---|
| 1226 | * Converts a unicode string into a multi byte string | 
|---|
| 1227 | * | 
|---|
| 1228 | * PARAMS | 
|---|
| 1229 | *     lpSrc   [I] Pointer to the unicode source string | 
|---|
| 1230 | *     lpDest  [O] Pointer to caller supplied storage for the multi byte string | 
|---|
| 1231 | *     nMaxLen [I] Size, in bytes, of the destination buffer | 
|---|
| 1232 | * | 
|---|
| 1233 | * RETURNS | 
|---|
| 1234 | *     Length, in bytes, of the converted string. | 
|---|
| 1235 | */ | 
|---|
| 1236 |  | 
|---|
| 1237 | INT | 
|---|
| 1238 | Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen) | 
|---|
| 1239 | { | 
|---|
| 1240 | INT len; | 
|---|
| 1241 |  | 
|---|
| 1242 | TRACE("(%s %p %d)\n", debugstr_w(lpSrc), lpDest, nMaxLen); | 
|---|
| 1243 |  | 
|---|
| 1244 | if (!lpDest && lpSrc) | 
|---|
| 1245 | return WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL); | 
|---|
| 1246 |  | 
|---|
| 1247 | if (nMaxLen == 0) | 
|---|
| 1248 | return 0; | 
|---|
| 1249 |  | 
|---|
| 1250 | if (lpSrc == NULL) { | 
|---|
| 1251 | lpDest[0] = '\0'; | 
|---|
| 1252 | return 0; | 
|---|
| 1253 | } | 
|---|
| 1254 |  | 
|---|
| 1255 | len = WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, 0, 0, NULL, NULL); | 
|---|
| 1256 | if (len >= nMaxLen) | 
|---|
| 1257 | len = nMaxLen - 1; | 
|---|
| 1258 |  | 
|---|
| 1259 | WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, lpDest, len, NULL, NULL); | 
|---|
| 1260 | lpDest[len] = '\0'; | 
|---|
| 1261 |  | 
|---|
| 1262 | return len; | 
|---|
| 1263 | } | 
|---|
| 1264 |  | 
|---|
| 1265 |  | 
|---|
| 1266 | /************************************************************************** | 
|---|
| 1267 | * Str_SetPtrAtoW [internal] | 
|---|
| 1268 | * | 
|---|
| 1269 | * Converts a multi byte string to a unicode string. | 
|---|
| 1270 | * If the pointer to the destination buffer is NULL a buffer is allocated. | 
|---|
| 1271 | * If the destination buffer is too small to keep the converted multi byte | 
|---|
| 1272 | * string the destination buffer is reallocated. If the source pointer is | 
|---|
| 1273 | * NULL, the destination buffer is freed. | 
|---|
| 1274 | * | 
|---|
| 1275 | * PARAMS | 
|---|
| 1276 | *     lppDest [I/O] pointer to a pointer to the destination buffer | 
|---|
| 1277 | *     lpSrc   [I] pointer to a multi byte string | 
|---|
| 1278 | * | 
|---|
| 1279 | * RETURNS | 
|---|
| 1280 | *     TRUE: conversion successful | 
|---|
| 1281 | *     FALSE: error | 
|---|
| 1282 | */ | 
|---|
| 1283 |  | 
|---|
| 1284 | BOOL | 
|---|
| 1285 | Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc) | 
|---|
| 1286 | { | 
|---|
| 1287 | TRACE("(%p %s)\n", lppDest, lpSrc); | 
|---|
| 1288 |  | 
|---|
| 1289 | if (lpSrc) { | 
|---|
| 1290 | INT len = MultiByteToWideChar(CP_ACP,0,lpSrc,-1,NULL,0); | 
|---|
| 1291 | LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len*sizeof(WCHAR)); | 
|---|
| 1292 |  | 
|---|
| 1293 | if (!ptr) | 
|---|
| 1294 | return FALSE; | 
|---|
| 1295 | MultiByteToWideChar(CP_ACP,0,lpSrc,-1,ptr,len); | 
|---|
| 1296 | *lppDest = ptr; | 
|---|
| 1297 | } | 
|---|
| 1298 | else { | 
|---|
| 1299 | if (*lppDest) { | 
|---|
| 1300 | COMCTL32_Free (*lppDest); | 
|---|
| 1301 | *lppDest = NULL; | 
|---|
| 1302 | } | 
|---|
| 1303 | } | 
|---|
| 1304 |  | 
|---|
| 1305 | return TRUE; | 
|---|
| 1306 | } | 
|---|
| 1307 |  | 
|---|
| 1308 |  | 
|---|
| 1309 | /************************************************************************** | 
|---|
| 1310 | * The DSA-API is a set of functions to create and manipulate arrays of | 
|---|
| 1311 | * fixed-size memory blocks. These arrays can store any kind of data | 
|---|
| 1312 | * (strings, icons...). | 
|---|
| 1313 | */ | 
|---|
| 1314 |  | 
|---|
| 1315 | /************************************************************************** | 
|---|
| 1316 | * DSA_Create [COMCTL32.320] Creates a dynamic storage array | 
|---|
| 1317 | * | 
|---|
| 1318 | * PARAMS | 
|---|
| 1319 | *     nSize [I] size of the array elements | 
|---|
| 1320 | *     nGrow [I] number of elements by which the array grows when it is filled | 
|---|
| 1321 | * | 
|---|
| 1322 | * RETURNS | 
|---|
| 1323 | *     Success: pointer to an array control structure. Use this like a handle. | 
|---|
| 1324 | *     Failure: NULL | 
|---|
| 1325 | */ | 
|---|
| 1326 |  | 
|---|
| 1327 | HDSA WINAPI | 
|---|
| 1328 | DSA_Create (INT nSize, INT nGrow) | 
|---|
| 1329 | { | 
|---|
| 1330 | HDSA hdsa; | 
|---|
| 1331 |  | 
|---|
| 1332 | TRACE("(size=%d grow=%d)\n", nSize, nGrow); | 
|---|
| 1333 |  | 
|---|
| 1334 | hdsa = (HDSA)COMCTL32_Alloc (sizeof(DSA)); | 
|---|
| 1335 | if (hdsa) | 
|---|
| 1336 | { | 
|---|
| 1337 | hdsa->nItemCount = 0; | 
|---|
| 1338 | hdsa->pData = NULL; | 
|---|
| 1339 | hdsa->nMaxCount = 0; | 
|---|
| 1340 | hdsa->nItemSize = nSize; | 
|---|
| 1341 | hdsa->nGrow = max(1, nGrow); | 
|---|
| 1342 | } | 
|---|
| 1343 |  | 
|---|
| 1344 | return hdsa; | 
|---|
| 1345 | } | 
|---|
| 1346 |  | 
|---|
| 1347 |  | 
|---|
| 1348 | /************************************************************************** | 
|---|
| 1349 | * DSA_Destroy [COMCTL32.321] Destroys a dynamic storage array | 
|---|
| 1350 | * | 
|---|
| 1351 | * PARAMS | 
|---|
| 1352 | *     hdsa [I] pointer to the array control structure | 
|---|
| 1353 | * | 
|---|
| 1354 | * RETURNS | 
|---|
| 1355 | *     Success: TRUE | 
|---|
| 1356 | *     Failure: FALSE | 
|---|
| 1357 | */ | 
|---|
| 1358 |  | 
|---|
| 1359 | BOOL WINAPI | 
|---|
| 1360 | DSA_Destroy (const HDSA hdsa) | 
|---|
| 1361 | { | 
|---|
| 1362 | TRACE("(%p)\n", hdsa); | 
|---|
| 1363 |  | 
|---|
| 1364 | if (!hdsa) | 
|---|
| 1365 | return FALSE; | 
|---|
| 1366 |  | 
|---|
| 1367 | if (hdsa->pData && (!COMCTL32_Free (hdsa->pData))) | 
|---|
| 1368 | return FALSE; | 
|---|
| 1369 |  | 
|---|
| 1370 | return COMCTL32_Free (hdsa); | 
|---|
| 1371 | } | 
|---|
| 1372 |  | 
|---|
| 1373 |  | 
|---|
| 1374 | /************************************************************************** | 
|---|
| 1375 | * DSA_GetItem [COMCTL32.322] | 
|---|
| 1376 | * | 
|---|
| 1377 | * PARAMS | 
|---|
| 1378 | *     hdsa   [I] pointer to the array control structure | 
|---|
| 1379 | *     nIndex [I] number of the Item to get | 
|---|
| 1380 | *     pDest  [O] destination buffer. Has to be >= dwElementSize. | 
|---|
| 1381 | * | 
|---|
| 1382 | * RETURNS | 
|---|
| 1383 | *     Success: TRUE | 
|---|
| 1384 | *     Failure: FALSE | 
|---|
| 1385 | */ | 
|---|
| 1386 |  | 
|---|
| 1387 | BOOL WINAPI | 
|---|
| 1388 | DSA_GetItem (const HDSA hdsa, INT nIndex, LPVOID pDest) | 
|---|
| 1389 | { | 
|---|
| 1390 | LPVOID pSrc; | 
|---|
| 1391 |  | 
|---|
| 1392 | TRACE("(%p %d %p)\n", hdsa, nIndex, pDest); | 
|---|
| 1393 |  | 
|---|
| 1394 | if (!hdsa) | 
|---|
| 1395 | return FALSE; | 
|---|
| 1396 | if ((nIndex < 0) || (nIndex >= hdsa->nItemCount)) | 
|---|
| 1397 | return FALSE; | 
|---|
| 1398 |  | 
|---|
| 1399 | pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex); | 
|---|
| 1400 | memmove (pDest, pSrc, hdsa->nItemSize); | 
|---|
| 1401 |  | 
|---|
| 1402 | return TRUE; | 
|---|
| 1403 | } | 
|---|
| 1404 |  | 
|---|
| 1405 |  | 
|---|
| 1406 | /************************************************************************** | 
|---|
| 1407 | * DSA_GetItemPtr [COMCTL32.323] | 
|---|
| 1408 | * | 
|---|
| 1409 | * Retrieves a pointer to the specified item. | 
|---|
| 1410 | * | 
|---|
| 1411 | * PARAMS | 
|---|
| 1412 | *     hdsa   [I] pointer to the array control structure | 
|---|
| 1413 | *     nIndex [I] index of the desired item | 
|---|
| 1414 | * | 
|---|
| 1415 | * RETURNS | 
|---|
| 1416 | *     Success: pointer to an item | 
|---|
| 1417 | *     Failure: NULL | 
|---|
| 1418 | */ | 
|---|
| 1419 |  | 
|---|
| 1420 | LPVOID WINAPI | 
|---|
| 1421 | DSA_GetItemPtr (const HDSA hdsa, INT nIndex) | 
|---|
| 1422 | { | 
|---|
| 1423 | LPVOID pSrc; | 
|---|
| 1424 |  | 
|---|
| 1425 | TRACE("(%p %d)\n", hdsa, nIndex); | 
|---|
| 1426 |  | 
|---|
| 1427 | if (!hdsa) | 
|---|
| 1428 | return NULL; | 
|---|
| 1429 | if ((nIndex < 0) || (nIndex >= hdsa->nItemCount)) | 
|---|
| 1430 | return NULL; | 
|---|
| 1431 |  | 
|---|
| 1432 | pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex); | 
|---|
| 1433 |  | 
|---|
| 1434 | TRACE("-- ret=%p\n", pSrc); | 
|---|
| 1435 |  | 
|---|
| 1436 | return pSrc; | 
|---|
| 1437 | } | 
|---|
| 1438 |  | 
|---|
| 1439 |  | 
|---|
| 1440 | /************************************************************************** | 
|---|
| 1441 | * DSA_SetItem [COMCTL32.325] | 
|---|
| 1442 | * | 
|---|
| 1443 | * Sets the contents of an item in the array. | 
|---|
| 1444 | * | 
|---|
| 1445 | * PARAMS | 
|---|
| 1446 | *     hdsa   [I] pointer to the array control structure | 
|---|
| 1447 | *     nIndex [I] index for the item | 
|---|
| 1448 | *     pSrc   [I] pointer to the new item data | 
|---|
| 1449 | * | 
|---|
| 1450 | * RETURNS | 
|---|
| 1451 | *     Success: TRUE | 
|---|
| 1452 | *     Failure: FALSE | 
|---|
| 1453 | */ | 
|---|
| 1454 |  | 
|---|
| 1455 | BOOL WINAPI | 
|---|
| 1456 | DSA_SetItem (const HDSA hdsa, INT nIndex, LPVOID pSrc) | 
|---|
| 1457 | { | 
|---|
| 1458 | INT  nSize, nNewItems; | 
|---|
| 1459 | LPVOID pDest, lpTemp; | 
|---|
| 1460 |  | 
|---|
| 1461 | TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc); | 
|---|
| 1462 |  | 
|---|
| 1463 | if ((!hdsa) || nIndex < 0) | 
|---|
| 1464 | return FALSE; | 
|---|
| 1465 |  | 
|---|
| 1466 | if (hdsa->nItemCount <= nIndex) { | 
|---|
| 1467 | /* within the old array */ | 
|---|
| 1468 | if (hdsa->nMaxCount > nIndex) { | 
|---|
| 1469 | /* within the allocated space, set a new boundary */ | 
|---|
| 1470 | hdsa->nItemCount = nIndex + 1; | 
|---|
| 1471 | } | 
|---|
| 1472 | else { | 
|---|
| 1473 | /* resize the block of memory */ | 
|---|
| 1474 | nNewItems = | 
|---|
| 1475 | hdsa->nGrow * ((INT)(((nIndex + 1) - 1) / hdsa->nGrow) + 1); | 
|---|
| 1476 | nSize = hdsa->nItemSize * nNewItems; | 
|---|
| 1477 |  | 
|---|
| 1478 | lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize); | 
|---|
| 1479 | if (!lpTemp) | 
|---|
| 1480 | return FALSE; | 
|---|
| 1481 |  | 
|---|
| 1482 | hdsa->nMaxCount = nNewItems; | 
|---|
| 1483 | hdsa->nItemCount = nIndex + 1; | 
|---|
| 1484 | hdsa->pData = lpTemp; | 
|---|
| 1485 | } | 
|---|
| 1486 | } | 
|---|
| 1487 |  | 
|---|
| 1488 | /* put the new entry in */ | 
|---|
| 1489 | pDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex); | 
|---|
| 1490 | TRACE("-- move dest=%p src=%p size=%d\n", | 
|---|
| 1491 | pDest, pSrc, hdsa->nItemSize); | 
|---|
| 1492 | memmove (pDest, pSrc, hdsa->nItemSize); | 
|---|
| 1493 |  | 
|---|
| 1494 | return TRUE; | 
|---|
| 1495 | } | 
|---|
| 1496 |  | 
|---|
| 1497 |  | 
|---|
| 1498 | /************************************************************************** | 
|---|
| 1499 | * DSA_InsertItem [COMCTL32.324] | 
|---|
| 1500 | * | 
|---|
| 1501 | * PARAMS | 
|---|
| 1502 | *     hdsa   [I] pointer to the array control structure | 
|---|
| 1503 | *     nIndex [I] index for the new item | 
|---|
| 1504 | *     pSrc   [I] pointer to the element | 
|---|
| 1505 | * | 
|---|
| 1506 | * RETURNS | 
|---|
| 1507 | *     Success: position of the new item | 
|---|
| 1508 | *     Failure: -1 | 
|---|
| 1509 | */ | 
|---|
| 1510 |  | 
|---|
| 1511 | INT WINAPI | 
|---|
| 1512 | DSA_InsertItem (const HDSA hdsa, INT nIndex, LPVOID pSrc) | 
|---|
| 1513 | { | 
|---|
| 1514 | INT   nNewItems, nSize; | 
|---|
| 1515 | LPVOID  lpTemp, lpDest; | 
|---|
| 1516 |  | 
|---|
| 1517 | TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc); | 
|---|
| 1518 |  | 
|---|
| 1519 | if ((!hdsa) || nIndex < 0) | 
|---|
| 1520 | return -1; | 
|---|
| 1521 |  | 
|---|
| 1522 | /* when nIndex >= nItemCount then append */ | 
|---|
| 1523 | if (nIndex >= hdsa->nItemCount) | 
|---|
| 1524 | nIndex = hdsa->nItemCount; | 
|---|
| 1525 |  | 
|---|
| 1526 | /* do we need to resize ? */ | 
|---|
| 1527 | if (hdsa->nItemCount >= hdsa->nMaxCount) { | 
|---|
| 1528 | nNewItems = hdsa->nMaxCount + hdsa->nGrow; | 
|---|
| 1529 | nSize = hdsa->nItemSize * nNewItems; | 
|---|
| 1530 |  | 
|---|
| 1531 | lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize); | 
|---|
| 1532 | if (!lpTemp) | 
|---|
| 1533 | return -1; | 
|---|
| 1534 |  | 
|---|
| 1535 | hdsa->nMaxCount = nNewItems; | 
|---|
| 1536 | hdsa->pData = lpTemp; | 
|---|
| 1537 | } | 
|---|
| 1538 |  | 
|---|
| 1539 | /* do we need to move elements ? */ | 
|---|
| 1540 | if (nIndex < hdsa->nItemCount) { | 
|---|
| 1541 | lpTemp = (char *) hdsa->pData + (hdsa->nItemSize * nIndex); | 
|---|
| 1542 | lpDest = (char *) lpTemp + hdsa->nItemSize; | 
|---|
| 1543 | nSize = (hdsa->nItemCount - nIndex) * hdsa->nItemSize; | 
|---|
| 1544 | TRACE("-- move dest=%p src=%p size=%d\n", | 
|---|
| 1545 | lpDest, lpTemp, nSize); | 
|---|
| 1546 | memmove (lpDest, lpTemp, nSize); | 
|---|
| 1547 | } | 
|---|
| 1548 |  | 
|---|
| 1549 | /* ok, we can put the new Item in */ | 
|---|
| 1550 | hdsa->nItemCount++; | 
|---|
| 1551 | lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex); | 
|---|
| 1552 | TRACE("-- move dest=%p src=%p size=%d\n", | 
|---|
| 1553 | lpDest, pSrc, hdsa->nItemSize); | 
|---|
| 1554 | memmove (lpDest, pSrc, hdsa->nItemSize); | 
|---|
| 1555 |  | 
|---|
| 1556 | return nIndex; | 
|---|
| 1557 | } | 
|---|
| 1558 |  | 
|---|
| 1559 |  | 
|---|
| 1560 | /************************************************************************** | 
|---|
| 1561 | * DSA_DeleteItem [COMCTL32.326] | 
|---|
| 1562 | * | 
|---|
| 1563 | * PARAMS | 
|---|
| 1564 | *     hdsa   [I] pointer to the array control structure | 
|---|
| 1565 | *     nIndex [I] index for the element to delete | 
|---|
| 1566 | * | 
|---|
| 1567 | * RETURNS | 
|---|
| 1568 | *     Success: number of the deleted element | 
|---|
| 1569 | *     Failure: -1 | 
|---|
| 1570 | */ | 
|---|
| 1571 |  | 
|---|
| 1572 | INT WINAPI | 
|---|
| 1573 | DSA_DeleteItem (const HDSA hdsa, INT nIndex) | 
|---|
| 1574 | { | 
|---|
| 1575 | LPVOID lpDest,lpSrc; | 
|---|
| 1576 | INT  nSize; | 
|---|
| 1577 |  | 
|---|
| 1578 | TRACE("(%p %d)\n", hdsa, nIndex); | 
|---|
| 1579 |  | 
|---|
| 1580 | if (!hdsa) | 
|---|
| 1581 | return -1; | 
|---|
| 1582 | if (nIndex < 0 || nIndex >= hdsa->nItemCount) | 
|---|
| 1583 | return -1; | 
|---|
| 1584 |  | 
|---|
| 1585 | /* do we need to move ? */ | 
|---|
| 1586 | if (nIndex < hdsa->nItemCount - 1) { | 
|---|
| 1587 | lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex); | 
|---|
| 1588 | lpSrc = (char *) lpDest + hdsa->nItemSize; | 
|---|
| 1589 | nSize = hdsa->nItemSize * (hdsa->nItemCount - nIndex - 1); | 
|---|
| 1590 | TRACE("-- move dest=%p src=%p size=%d\n", | 
|---|
| 1591 | lpDest, lpSrc, nSize); | 
|---|
| 1592 | memmove (lpDest, lpSrc, nSize); | 
|---|
| 1593 | } | 
|---|
| 1594 |  | 
|---|
| 1595 | hdsa->nItemCount--; | 
|---|
| 1596 |  | 
|---|
| 1597 | /* free memory ? */ | 
|---|
| 1598 | if ((hdsa->nMaxCount - hdsa->nItemCount) >= hdsa->nGrow) { | 
|---|
| 1599 | nSize = hdsa->nItemSize * hdsa->nItemCount; | 
|---|
| 1600 |  | 
|---|
| 1601 | lpDest = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize); | 
|---|
| 1602 | if (!lpDest) | 
|---|
| 1603 | return -1; | 
|---|
| 1604 |  | 
|---|
| 1605 | hdsa->nMaxCount = hdsa->nItemCount; | 
|---|
| 1606 | hdsa->pData = lpDest; | 
|---|
| 1607 | } | 
|---|
| 1608 |  | 
|---|
| 1609 | return nIndex; | 
|---|
| 1610 | } | 
|---|
| 1611 |  | 
|---|
| 1612 |  | 
|---|
| 1613 | /************************************************************************** | 
|---|
| 1614 | * DSA_DeleteAllItems [COMCTL32.327] | 
|---|
| 1615 | * | 
|---|
| 1616 | * Removes all items and reinitializes the array. | 
|---|
| 1617 | * | 
|---|
| 1618 | * PARAMS | 
|---|
| 1619 | *     hdsa [I] pointer to the array control structure | 
|---|
| 1620 | * | 
|---|
| 1621 | * RETURNS | 
|---|
| 1622 | *     Success: TRUE | 
|---|
| 1623 | *     Failure: FALSE | 
|---|
| 1624 | */ | 
|---|
| 1625 |  | 
|---|
| 1626 | BOOL WINAPI | 
|---|
| 1627 | DSA_DeleteAllItems (const HDSA hdsa) | 
|---|
| 1628 | { | 
|---|
| 1629 | TRACE("(%p)\n", hdsa); | 
|---|
| 1630 |  | 
|---|
| 1631 | if (!hdsa) | 
|---|
| 1632 | return FALSE; | 
|---|
| 1633 | if (hdsa->pData && (!COMCTL32_Free (hdsa->pData))) | 
|---|
| 1634 | return FALSE; | 
|---|
| 1635 |  | 
|---|
| 1636 | hdsa->nItemCount = 0; | 
|---|
| 1637 | hdsa->pData = NULL; | 
|---|
| 1638 | hdsa->nMaxCount = 0; | 
|---|
| 1639 |  | 
|---|
| 1640 | return TRUE; | 
|---|
| 1641 | } | 
|---|
| 1642 |  | 
|---|
| 1643 |  | 
|---|
| 1644 | /************************************************************************** | 
|---|
| 1645 | * The DPA-API is a set of functions to create and manipulate arrays of | 
|---|
| 1646 | * pointers. | 
|---|
| 1647 | */ | 
|---|
| 1648 |  | 
|---|
| 1649 | /************************************************************************** | 
|---|
| 1650 | * DPA_Create [COMCTL32.328] Creates a dynamic pointer array | 
|---|
| 1651 | * | 
|---|
| 1652 | * PARAMS | 
|---|
| 1653 | *     nGrow [I] number of items by which the array grows when it is filled | 
|---|
| 1654 | * | 
|---|
| 1655 | * RETURNS | 
|---|
| 1656 | *     Success: handle (pointer) to the pointer array. | 
|---|
| 1657 | *     Failure: NULL | 
|---|
| 1658 | */ | 
|---|
| 1659 |  | 
|---|
| 1660 | HDPA WINAPI | 
|---|
| 1661 | DPA_Create (INT nGrow) | 
|---|
| 1662 | { | 
|---|
| 1663 | HDPA hdpa; | 
|---|
| 1664 |  | 
|---|
| 1665 | TRACE("(%d)\n", nGrow); | 
|---|
| 1666 |  | 
|---|
| 1667 | hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA)); | 
|---|
| 1668 | if (hdpa) { | 
|---|
| 1669 | hdpa->nGrow = max(8, nGrow); | 
|---|
| 1670 | hdpa->hHeap = COMCTL32_hHeap; | 
|---|
| 1671 | hdpa->nMaxCount = hdpa->nGrow * 2; | 
|---|
| 1672 | hdpa->ptrs = | 
|---|
| 1673 | (LPVOID*)COMCTL32_Alloc (hdpa->nMaxCount * sizeof(LPVOID)); | 
|---|
| 1674 | } | 
|---|
| 1675 |  | 
|---|
| 1676 | TRACE("-- %p\n", hdpa); | 
|---|
| 1677 |  | 
|---|
| 1678 | return hdpa; | 
|---|
| 1679 | } | 
|---|
| 1680 |  | 
|---|
| 1681 |  | 
|---|
| 1682 | /************************************************************************** | 
|---|
| 1683 | * DPA_Destroy [COMCTL32.329] Destroys a dynamic pointer array | 
|---|
| 1684 | * | 
|---|
| 1685 | * PARAMS | 
|---|
| 1686 | *     hdpa [I] handle (pointer) to the pointer array | 
|---|
| 1687 | * | 
|---|
| 1688 | * RETURNS | 
|---|
| 1689 | *     Success: TRUE | 
|---|
| 1690 | *     Failure: FALSE | 
|---|
| 1691 | */ | 
|---|
| 1692 |  | 
|---|
| 1693 | BOOL WINAPI | 
|---|
| 1694 | DPA_Destroy (const HDPA hdpa) | 
|---|
| 1695 | { | 
|---|
| 1696 | TRACE("(%p)\n", hdpa); | 
|---|
| 1697 |  | 
|---|
| 1698 | if (!hdpa) | 
|---|
| 1699 | return FALSE; | 
|---|
| 1700 |  | 
|---|
| 1701 | if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs))) | 
|---|
| 1702 | return FALSE; | 
|---|
| 1703 |  | 
|---|
| 1704 | return HeapFree (hdpa->hHeap, 0, hdpa); | 
|---|
| 1705 | } | 
|---|
| 1706 |  | 
|---|
| 1707 |  | 
|---|
| 1708 | /************************************************************************** | 
|---|
| 1709 | * DPA_Grow [COMCTL32.330] | 
|---|
| 1710 | * | 
|---|
| 1711 | * Sets the growth amount. | 
|---|
| 1712 | * | 
|---|
| 1713 | * PARAMS | 
|---|
| 1714 | *     hdpa  [I] handle (pointer) to the existing (source) pointer array | 
|---|
| 1715 | *     nGrow [I] number of items by which the array grows when it's too small | 
|---|
| 1716 | * | 
|---|
| 1717 | * RETURNS | 
|---|
| 1718 | *     Success: TRUE | 
|---|
| 1719 | *     Failure: FALSE | 
|---|
| 1720 | */ | 
|---|
| 1721 |  | 
|---|
| 1722 | BOOL WINAPI | 
|---|
| 1723 | DPA_Grow (const HDPA hdpa, INT nGrow) | 
|---|
| 1724 | { | 
|---|
| 1725 | TRACE("(%p %d)\n", hdpa, nGrow); | 
|---|
| 1726 |  | 
|---|
| 1727 | if (!hdpa) | 
|---|
| 1728 | return FALSE; | 
|---|
| 1729 |  | 
|---|
| 1730 | hdpa->nGrow = max(8, nGrow); | 
|---|
| 1731 |  | 
|---|
| 1732 | return TRUE; | 
|---|
| 1733 | } | 
|---|
| 1734 |  | 
|---|
| 1735 |  | 
|---|
| 1736 | /************************************************************************** | 
|---|
| 1737 | * DPA_Clone [COMCTL32.331] | 
|---|
| 1738 | * | 
|---|
| 1739 | * Copies a pointer array to an other one or creates a copy | 
|---|
| 1740 | * | 
|---|
| 1741 | * PARAMS | 
|---|
| 1742 | *     hdpa    [I] handle (pointer) to the existing (source) pointer array | 
|---|
| 1743 | *     hdpaNew [O] handle (pointer) to the destination pointer array | 
|---|
| 1744 | * | 
|---|
| 1745 | * RETURNS | 
|---|
| 1746 | *     Success: pointer to the destination pointer array. | 
|---|
| 1747 | *     Failure: NULL | 
|---|
| 1748 | * | 
|---|
| 1749 | * NOTES | 
|---|
| 1750 | *     - If the 'hdpaNew' is a NULL-Pointer, a copy of the source pointer | 
|---|
| 1751 | *       array will be created and it's handle (pointer) is returned. | 
|---|
| 1752 | *     - If 'hdpa' is a NULL-Pointer, the original implementation crashes, | 
|---|
| 1753 | *       this implementation just returns NULL. | 
|---|
| 1754 | */ | 
|---|
| 1755 |  | 
|---|
| 1756 | HDPA WINAPI | 
|---|
| 1757 | DPA_Clone (const HDPA hdpa, const HDPA hdpaNew) | 
|---|
| 1758 | { | 
|---|
| 1759 | INT nNewItems, nSize; | 
|---|
| 1760 | HDPA hdpaTemp; | 
|---|
| 1761 |  | 
|---|
| 1762 | if (!hdpa) | 
|---|
| 1763 | return NULL; | 
|---|
| 1764 |  | 
|---|
| 1765 | TRACE("(%p %p)\n", hdpa, hdpaNew); | 
|---|
| 1766 |  | 
|---|
| 1767 | if (!hdpaNew) { | 
|---|
| 1768 | /* create a new DPA */ | 
|---|
| 1769 | hdpaTemp = (HDPA)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, | 
|---|
| 1770 | sizeof(DPA)); | 
|---|
| 1771 | hdpaTemp->hHeap = hdpa->hHeap; | 
|---|
| 1772 | hdpaTemp->nGrow = hdpa->nGrow; | 
|---|
| 1773 | } | 
|---|
| 1774 | else | 
|---|
| 1775 | hdpaTemp = hdpaNew; | 
|---|
| 1776 |  | 
|---|
| 1777 | if (hdpaTemp->ptrs) { | 
|---|
| 1778 | /* remove old pointer array */ | 
|---|
| 1779 | HeapFree (hdpaTemp->hHeap, 0, hdpaTemp->ptrs); | 
|---|
| 1780 | hdpaTemp->ptrs = NULL; | 
|---|
| 1781 | hdpaTemp->nItemCount = 0; | 
|---|
| 1782 | hdpaTemp->nMaxCount = 0; | 
|---|
| 1783 | } | 
|---|
| 1784 |  | 
|---|
| 1785 | /* create a new pointer array */ | 
|---|
| 1786 | nNewItems = hdpaTemp->nGrow * | 
|---|
| 1787 | ((INT)((hdpa->nItemCount - 1) / hdpaTemp->nGrow) + 1); | 
|---|
| 1788 | nSize = nNewItems * sizeof(LPVOID); | 
|---|
| 1789 | hdpaTemp->ptrs = | 
|---|
| 1790 | (LPVOID*)HeapAlloc (hdpaTemp->hHeap, HEAP_ZERO_MEMORY, nSize); | 
|---|
| 1791 | hdpaTemp->nMaxCount = nNewItems; | 
|---|
| 1792 |  | 
|---|
| 1793 | /* clone the pointer array */ | 
|---|
| 1794 | hdpaTemp->nItemCount = hdpa->nItemCount; | 
|---|
| 1795 | memmove (hdpaTemp->ptrs, hdpa->ptrs, | 
|---|
| 1796 | hdpaTemp->nItemCount * sizeof(LPVOID)); | 
|---|
| 1797 |  | 
|---|
| 1798 | return hdpaTemp; | 
|---|
| 1799 | } | 
|---|
| 1800 |  | 
|---|
| 1801 |  | 
|---|
| 1802 | /************************************************************************** | 
|---|
| 1803 | * DPA_GetPtr [COMCTL32.332] | 
|---|
| 1804 | * | 
|---|
| 1805 | * Retrieves a pointer from a dynamic pointer array | 
|---|
| 1806 | * | 
|---|
| 1807 | * PARAMS | 
|---|
| 1808 | *     hdpa   [I] handle (pointer) to the pointer array | 
|---|
| 1809 | *     nIndex [I] array index of the desired pointer | 
|---|
| 1810 | * | 
|---|
| 1811 | * RETURNS | 
|---|
| 1812 | *     Success: pointer | 
|---|
| 1813 | *     Failure: NULL | 
|---|
| 1814 | */ | 
|---|
| 1815 |  | 
|---|
| 1816 | LPVOID WINAPI | 
|---|
| 1817 | DPA_GetPtr (const HDPA hdpa, INT i) | 
|---|
| 1818 | { | 
|---|
| 1819 | TRACE("(%p %d)\n", hdpa, i); | 
|---|
| 1820 |  | 
|---|
| 1821 | if (!hdpa) | 
|---|
| 1822 | return NULL; | 
|---|
| 1823 | if (!hdpa->ptrs) { | 
|---|
| 1824 | WARN("no pointer array.\n"); | 
|---|
| 1825 | return NULL; | 
|---|
| 1826 | } | 
|---|
| 1827 | if ((i < 0) || (i >= hdpa->nItemCount)) { | 
|---|
| 1828 | WARN("not enough pointers in array (%d vs %d).\n",i,hdpa->nItemCount); | 
|---|
| 1829 | return NULL; | 
|---|
| 1830 | } | 
|---|
| 1831 |  | 
|---|
| 1832 | TRACE("-- %p\n", hdpa->ptrs[i]); | 
|---|
| 1833 |  | 
|---|
| 1834 | return hdpa->ptrs[i]; | 
|---|
| 1835 | } | 
|---|
| 1836 |  | 
|---|
| 1837 |  | 
|---|
| 1838 | /************************************************************************** | 
|---|
| 1839 | * DPA_GetPtrIndex [COMCTL32.333] | 
|---|
| 1840 | * | 
|---|
| 1841 | * Retrieves the index of the specified pointer | 
|---|
| 1842 | * | 
|---|
| 1843 | * PARAMS | 
|---|
| 1844 | *     hdpa   [I] handle (pointer) to the pointer array | 
|---|
| 1845 | *     p      [I] pointer | 
|---|
| 1846 | * | 
|---|
| 1847 | * RETURNS | 
|---|
| 1848 | *     Success: index of the specified pointer | 
|---|
| 1849 | *     Failure: -1 | 
|---|
| 1850 | */ | 
|---|
| 1851 |  | 
|---|
| 1852 | INT WINAPI | 
|---|
| 1853 | DPA_GetPtrIndex (const HDPA hdpa, LPVOID p) | 
|---|
| 1854 | { | 
|---|
| 1855 | INT i; | 
|---|
| 1856 |  | 
|---|
| 1857 | if (!hdpa->ptrs) | 
|---|
| 1858 | return -1; | 
|---|
| 1859 |  | 
|---|
| 1860 | for (i = 0; i < hdpa->nItemCount; i++) { | 
|---|
| 1861 | if (hdpa->ptrs[i] == p) | 
|---|
| 1862 | return i; | 
|---|
| 1863 | } | 
|---|
| 1864 |  | 
|---|
| 1865 | return -1; | 
|---|
| 1866 | } | 
|---|
| 1867 |  | 
|---|
| 1868 |  | 
|---|
| 1869 | /************************************************************************** | 
|---|
| 1870 | * DPA_InsertPtr [COMCTL32.334] | 
|---|
| 1871 | * | 
|---|
| 1872 | * Inserts a pointer into a dynamic pointer array | 
|---|
| 1873 | * | 
|---|
| 1874 | * PARAMS | 
|---|
| 1875 | *     hdpa [I] handle (pointer) to the array | 
|---|
| 1876 | *     i    [I] array index | 
|---|
| 1877 | *     p    [I] pointer to insert | 
|---|
| 1878 | * | 
|---|
| 1879 | * RETURNS | 
|---|
| 1880 | *     Success: index of the inserted pointer | 
|---|
| 1881 | *     Failure: -1 | 
|---|
| 1882 | */ | 
|---|
| 1883 |  | 
|---|
| 1884 | INT WINAPI | 
|---|
| 1885 | DPA_InsertPtr (const HDPA hdpa, INT i, LPVOID p) | 
|---|
| 1886 | { | 
|---|
| 1887 | INT   nNewItems, nSize, nIndex = 0; | 
|---|
| 1888 | LPVOID  *lpTemp, *lpDest; | 
|---|
| 1889 |  | 
|---|
| 1890 | TRACE("(%p %d %p)\n", hdpa, i, p); | 
|---|
| 1891 |  | 
|---|
| 1892 | if ((!hdpa) || (i < 0)) | 
|---|
| 1893 | return -1; | 
|---|
| 1894 |  | 
|---|
| 1895 | if (!hdpa->ptrs) { | 
|---|
| 1896 | hdpa->ptrs = | 
|---|
| 1897 | (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, | 
|---|
| 1898 | 2 * hdpa->nGrow * sizeof(LPVOID)); | 
|---|
| 1899 | if (!hdpa->ptrs) | 
|---|
| 1900 | return -1; | 
|---|
| 1901 | hdpa->nMaxCount = hdpa->nGrow * 2; | 
|---|
| 1902 | nIndex = 0; | 
|---|
| 1903 | } | 
|---|
| 1904 | else { | 
|---|
| 1905 | if (hdpa->nItemCount >= hdpa->nMaxCount) { | 
|---|
| 1906 | TRACE("-- resizing\n"); | 
|---|
| 1907 | nNewItems = hdpa->nMaxCount + hdpa->nGrow; | 
|---|
| 1908 | nSize = nNewItems * sizeof(LPVOID); | 
|---|
| 1909 |  | 
|---|
| 1910 | lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, | 
|---|
| 1911 | hdpa->ptrs, nSize); | 
|---|
| 1912 | if (!lpTemp) | 
|---|
| 1913 | return -1; | 
|---|
| 1914 | hdpa->nMaxCount = nNewItems; | 
|---|
| 1915 | hdpa->ptrs = lpTemp; | 
|---|
| 1916 | } | 
|---|
| 1917 |  | 
|---|
| 1918 | if (i >= hdpa->nItemCount) { | 
|---|
| 1919 | nIndex = hdpa->nItemCount; | 
|---|
| 1920 | TRACE("-- appending at %d\n", nIndex); | 
|---|
| 1921 | } | 
|---|
| 1922 | else { | 
|---|
| 1923 | TRACE("-- inserting at %d\n", i); | 
|---|
| 1924 | lpTemp = hdpa->ptrs + i; | 
|---|
| 1925 | lpDest = lpTemp + 1; | 
|---|
| 1926 | nSize  = (hdpa->nItemCount - i) * sizeof(LPVOID); | 
|---|
| 1927 | TRACE("-- move dest=%p src=%p size=%x\n", | 
|---|
| 1928 | lpDest, lpTemp, nSize); | 
|---|
| 1929 | memmove (lpDest, lpTemp, nSize); | 
|---|
| 1930 | nIndex = i; | 
|---|
| 1931 | } | 
|---|
| 1932 | } | 
|---|
| 1933 |  | 
|---|
| 1934 | /* insert item */ | 
|---|
| 1935 | hdpa->nItemCount++; | 
|---|
| 1936 | hdpa->ptrs[nIndex] = p; | 
|---|
| 1937 |  | 
|---|
| 1938 | return nIndex; | 
|---|
| 1939 | } | 
|---|
| 1940 |  | 
|---|
| 1941 |  | 
|---|
| 1942 | /************************************************************************** | 
|---|
| 1943 | * DPA_SetPtr [COMCTL32.335] | 
|---|
| 1944 | * | 
|---|
| 1945 | * Sets a pointer in the pointer array | 
|---|
| 1946 | * | 
|---|
| 1947 | * PARAMS | 
|---|
| 1948 | *     hdpa [I] handle (pointer) to the pointer array | 
|---|
| 1949 | *     i    [I] index of the pointer that will be set | 
|---|
| 1950 | *     p    [I] pointer to be set | 
|---|
| 1951 | * | 
|---|
| 1952 | * RETURNS | 
|---|
| 1953 | *     Success: TRUE | 
|---|
| 1954 | *     Failure: FALSE | 
|---|
| 1955 | */ | 
|---|
| 1956 |  | 
|---|
| 1957 | BOOL WINAPI | 
|---|
| 1958 | DPA_SetPtr (const HDPA hdpa, INT i, LPVOID p) | 
|---|
| 1959 | { | 
|---|
| 1960 | LPVOID *lpTemp; | 
|---|
| 1961 |  | 
|---|
| 1962 | TRACE("(%p %d %p)\n", hdpa, i, p); | 
|---|
| 1963 |  | 
|---|
| 1964 | if ((!hdpa) || i < 0) | 
|---|
| 1965 | return FALSE; | 
|---|
| 1966 |  | 
|---|
| 1967 | if (hdpa->nItemCount <= i) { | 
|---|
| 1968 | /* within the old array */ | 
|---|
| 1969 | if (hdpa->nMaxCount > i) { | 
|---|
| 1970 | /* within the allocated space, set a new boundary */ | 
|---|
| 1971 | hdpa->nItemCount = i+1; | 
|---|
| 1972 | } | 
|---|
| 1973 | else { | 
|---|
| 1974 | /* resize the block of memory */ | 
|---|
| 1975 | INT nNewItems = | 
|---|
| 1976 | hdpa->nGrow * ((INT)(((i+1) - 1) / hdpa->nGrow) + 1); | 
|---|
| 1977 | INT nSize = nNewItems * sizeof(LPVOID); | 
|---|
| 1978 |  | 
|---|
| 1979 | lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, | 
|---|
| 1980 | hdpa->ptrs, nSize); | 
|---|
| 1981 | if (!lpTemp) | 
|---|
| 1982 | return FALSE; | 
|---|
| 1983 |  | 
|---|
| 1984 | hdpa->nItemCount = nNewItems; | 
|---|
| 1985 | hdpa->ptrs = lpTemp; | 
|---|
| 1986 | } | 
|---|
| 1987 | } | 
|---|
| 1988 |  | 
|---|
| 1989 | /* put the new entry in */ | 
|---|
| 1990 | hdpa->ptrs[i] = p; | 
|---|
| 1991 |  | 
|---|
| 1992 | return TRUE; | 
|---|
| 1993 | } | 
|---|
| 1994 |  | 
|---|
| 1995 |  | 
|---|
| 1996 | /************************************************************************** | 
|---|
| 1997 | * DPA_DeletePtr [COMCTL32.336] | 
|---|
| 1998 | * | 
|---|
| 1999 | * Removes a pointer from the pointer array. | 
|---|
| 2000 | * | 
|---|
| 2001 | * PARAMS | 
|---|
| 2002 | *     hdpa [I] handle (pointer) to the pointer array | 
|---|
| 2003 | *     i    [I] index of the pointer that will be deleted | 
|---|
| 2004 | * | 
|---|
| 2005 | * RETURNS | 
|---|
| 2006 | *     Success: deleted pointer | 
|---|
| 2007 | *     Failure: NULL | 
|---|
| 2008 | */ | 
|---|
| 2009 |  | 
|---|
| 2010 | LPVOID WINAPI | 
|---|
| 2011 | DPA_DeletePtr (const HDPA hdpa, INT i) | 
|---|
| 2012 | { | 
|---|
| 2013 | LPVOID *lpDest, *lpSrc, lpTemp = NULL; | 
|---|
| 2014 | INT  nSize; | 
|---|
| 2015 |  | 
|---|
| 2016 | TRACE("(%p %d)\n", hdpa, i); | 
|---|
| 2017 |  | 
|---|
| 2018 | if ((!hdpa) || i < 0 || i >= hdpa->nItemCount) | 
|---|
| 2019 | return NULL; | 
|---|
| 2020 |  | 
|---|
| 2021 | lpTemp = hdpa->ptrs[i]; | 
|---|
| 2022 |  | 
|---|
| 2023 | /* do we need to move ?*/ | 
|---|
| 2024 | if (i < hdpa->nItemCount - 1) { | 
|---|
| 2025 | lpDest = hdpa->ptrs + i; | 
|---|
| 2026 | lpSrc = lpDest + 1; | 
|---|
| 2027 | nSize = (hdpa->nItemCount - i - 1) * sizeof(LPVOID); | 
|---|
| 2028 | TRACE("-- move dest=%p src=%p size=%x\n", | 
|---|
| 2029 | lpDest, lpSrc, nSize); | 
|---|
| 2030 | memmove (lpDest, lpSrc, nSize); | 
|---|
| 2031 | } | 
|---|
| 2032 |  | 
|---|
| 2033 | hdpa->nItemCount --; | 
|---|
| 2034 |  | 
|---|
| 2035 | /* free memory ?*/ | 
|---|
| 2036 | if ((hdpa->nMaxCount - hdpa->nItemCount) >= hdpa->nGrow) { | 
|---|
| 2037 | INT nNewItems = max(hdpa->nGrow * 2, hdpa->nItemCount); | 
|---|
| 2038 | nSize = nNewItems * sizeof(LPVOID); | 
|---|
| 2039 | lpDest = (LPVOID)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, | 
|---|
| 2040 | hdpa->ptrs, nSize); | 
|---|
| 2041 | if (!lpDest) | 
|---|
| 2042 | return NULL; | 
|---|
| 2043 |  | 
|---|
| 2044 | hdpa->nMaxCount = nNewItems; | 
|---|
| 2045 | hdpa->ptrs = (LPVOID*)lpDest; | 
|---|
| 2046 | } | 
|---|
| 2047 |  | 
|---|
| 2048 | return lpTemp; | 
|---|
| 2049 | } | 
|---|
| 2050 |  | 
|---|
| 2051 |  | 
|---|
| 2052 | /************************************************************************** | 
|---|
| 2053 | * DPA_DeleteAllPtrs [COMCTL32.337] | 
|---|
| 2054 | * | 
|---|
| 2055 | * Removes all pointers and reinitializes the array. | 
|---|
| 2056 | * | 
|---|
| 2057 | * PARAMS | 
|---|
| 2058 | *     hdpa [I] handle (pointer) to the pointer array | 
|---|
| 2059 | * | 
|---|
| 2060 | * RETURNS | 
|---|
| 2061 | *     Success: TRUE | 
|---|
| 2062 | *     Failure: FALSE | 
|---|
| 2063 | */ | 
|---|
| 2064 |  | 
|---|
| 2065 | BOOL WINAPI | 
|---|
| 2066 | DPA_DeleteAllPtrs (const HDPA hdpa) | 
|---|
| 2067 | { | 
|---|
| 2068 | TRACE("(%p)\n", hdpa); | 
|---|
| 2069 |  | 
|---|
| 2070 | if (!hdpa) | 
|---|
| 2071 | return FALSE; | 
|---|
| 2072 |  | 
|---|
| 2073 | if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs))) | 
|---|
| 2074 | return FALSE; | 
|---|
| 2075 |  | 
|---|
| 2076 | hdpa->nItemCount = 0; | 
|---|
| 2077 | hdpa->nMaxCount = hdpa->nGrow * 2; | 
|---|
| 2078 | hdpa->ptrs = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, | 
|---|
| 2079 | hdpa->nMaxCount * sizeof(LPVOID)); | 
|---|
| 2080 |  | 
|---|
| 2081 | return TRUE; | 
|---|
| 2082 | } | 
|---|
| 2083 |  | 
|---|
| 2084 |  | 
|---|
| 2085 | /************************************************************************** | 
|---|
| 2086 | * DPA_QuickSort [Internal] | 
|---|
| 2087 | * | 
|---|
| 2088 | * Ordinary quicksort (used by DPA_Sort). | 
|---|
| 2089 | * | 
|---|
| 2090 | * PARAMS | 
|---|
| 2091 | *     lpPtrs     [I] pointer to the pointer array | 
|---|
| 2092 | *     l          [I] index of the "left border" of the partition | 
|---|
| 2093 | *     r          [I] index of the "right border" of the partition | 
|---|
| 2094 | *     pfnCompare [I] pointer to the compare function | 
|---|
| 2095 | *     lParam     [I] user defined value (3rd parameter in compare function) | 
|---|
| 2096 | * | 
|---|
| 2097 | * RETURNS | 
|---|
| 2098 | *     NONE | 
|---|
| 2099 | */ | 
|---|
| 2100 |  | 
|---|
| 2101 | static VOID | 
|---|
| 2102 | DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r, | 
|---|
| 2103 | PFNDPACOMPARE pfnCompare, LPARAM lParam) | 
|---|
| 2104 | { | 
|---|
| 2105 | INT m; | 
|---|
| 2106 | LPVOID t; | 
|---|
| 2107 |  | 
|---|
| 2108 | TRACE("l=%i r=%i\n", l, r); | 
|---|
| 2109 |  | 
|---|
| 2110 | if (l==r)    /* one element is always sorted */ | 
|---|
| 2111 | return; | 
|---|
| 2112 | if (r<l)     /* oops, got it in the wrong order */ | 
|---|
| 2113 | { | 
|---|
| 2114 | DPA_QuickSort(lpPtrs, r, l, pfnCompare, lParam); | 
|---|
| 2115 | return; | 
|---|
| 2116 | } | 
|---|
| 2117 | m = (l+r)/2; /* divide by two */ | 
|---|
| 2118 | DPA_QuickSort(lpPtrs, l, m, pfnCompare, lParam); | 
|---|
| 2119 | DPA_QuickSort(lpPtrs, m+1, r, pfnCompare, lParam); | 
|---|
| 2120 |  | 
|---|
| 2121 | /* join the two sides */ | 
|---|
| 2122 | while( (l<=m) && (m<r) ) | 
|---|
| 2123 | { | 
|---|
| 2124 | if(pfnCompare(lpPtrs[l],lpPtrs[m+1],lParam)>0) | 
|---|
| 2125 | { | 
|---|
| 2126 | t = lpPtrs[m+1]; | 
|---|
| 2127 | memmove(&lpPtrs[l+1],&lpPtrs[l],(m-l+1)*sizeof lpPtrs[l]); | 
|---|
| 2128 | lpPtrs[l] = t; | 
|---|
| 2129 |  | 
|---|
| 2130 | m++; | 
|---|
| 2131 | } | 
|---|
| 2132 | l++; | 
|---|
| 2133 | } | 
|---|
| 2134 | } | 
|---|
| 2135 |  | 
|---|
| 2136 |  | 
|---|
| 2137 | /************************************************************************** | 
|---|
| 2138 | * DPA_Sort [COMCTL32.338] | 
|---|
| 2139 | * | 
|---|
| 2140 | * Sorts a pointer array using a user defined compare function | 
|---|
| 2141 | * | 
|---|
| 2142 | * PARAMS | 
|---|
| 2143 | *     hdpa       [I] handle (pointer) to the pointer array | 
|---|
| 2144 | *     pfnCompare [I] pointer to the compare function | 
|---|
| 2145 | *     lParam     [I] user defined value (3rd parameter of compare function) | 
|---|
| 2146 | * | 
|---|
| 2147 | * RETURNS | 
|---|
| 2148 | *     Success: TRUE | 
|---|
| 2149 | *     Failure: FALSE | 
|---|
| 2150 | */ | 
|---|
| 2151 |  | 
|---|
| 2152 | BOOL WINAPI | 
|---|
| 2153 | DPA_Sort (const HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam) | 
|---|
| 2154 | { | 
|---|
| 2155 | if (!hdpa || !pfnCompare) | 
|---|
| 2156 | return FALSE; | 
|---|
| 2157 |  | 
|---|
| 2158 | TRACE("(%p %p 0x%lx)\n", hdpa, pfnCompare, lParam); | 
|---|
| 2159 |  | 
|---|
| 2160 | if ((hdpa->nItemCount > 1) && (hdpa->ptrs)) | 
|---|
| 2161 | DPA_QuickSort (hdpa->ptrs, 0, hdpa->nItemCount - 1, | 
|---|
| 2162 | pfnCompare, lParam); | 
|---|
| 2163 |  | 
|---|
| 2164 | return TRUE; | 
|---|
| 2165 | } | 
|---|
| 2166 |  | 
|---|
| 2167 |  | 
|---|
| 2168 | /************************************************************************** | 
|---|
| 2169 | * DPA_Search [COMCTL32.339] | 
|---|
| 2170 | * | 
|---|
| 2171 | * Searches a pointer array for a specified pointer | 
|---|
| 2172 | * | 
|---|
| 2173 | * PARAMS | 
|---|
| 2174 | *     hdpa       [I] handle (pointer) to the pointer array | 
|---|
| 2175 | *     pFind      [I] pointer to search for | 
|---|
| 2176 | *     nStart     [I] start index | 
|---|
| 2177 | *     pfnCompare [I] pointer to the compare function | 
|---|
| 2178 | *     lParam     [I] user defined value (3rd parameter of compare function) | 
|---|
| 2179 | *     uOptions   [I] search options | 
|---|
| 2180 | * | 
|---|
| 2181 | * RETURNS | 
|---|
| 2182 | *     Success: index of the pointer in the array. | 
|---|
| 2183 | *     Failure: -1 | 
|---|
| 2184 | * | 
|---|
| 2185 | * NOTES | 
|---|
| 2186 | *     Binary search taken from R.Sedgewick "Algorithms in C"! | 
|---|
| 2187 | *     Function is NOT tested! | 
|---|
| 2188 | *     If something goes wrong, blame HIM not ME! (Eric Kohl) | 
|---|
| 2189 | */ | 
|---|
| 2190 |  | 
|---|
| 2191 | INT WINAPI | 
|---|
| 2192 | DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart, | 
|---|
| 2193 | PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions) | 
|---|
| 2194 | { | 
|---|
| 2195 | if (!hdpa || !pfnCompare || !pFind) | 
|---|
| 2196 | return -1; | 
|---|
| 2197 |  | 
|---|
| 2198 | TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n", | 
|---|
| 2199 | hdpa, pFind, nStart, pfnCompare, lParam, uOptions); | 
|---|
| 2200 |  | 
|---|
| 2201 | if (uOptions & DPAS_SORTED) { | 
|---|
| 2202 | /* array is sorted --> use binary search */ | 
|---|
| 2203 | INT l, r, x, n; | 
|---|
| 2204 | LPVOID *lpPtr; | 
|---|
| 2205 |  | 
|---|
| 2206 | TRACE("binary search\n"); | 
|---|
| 2207 |  | 
|---|
| 2208 | l = (nStart == -1) ? 0 : nStart; | 
|---|
| 2209 | r = hdpa->nItemCount - 1; | 
|---|
| 2210 | lpPtr = hdpa->ptrs; | 
|---|
| 2211 | while (r >= l) { | 
|---|
| 2212 | x = (l + r) / 2; | 
|---|
| 2213 | n = (pfnCompare)(pFind, lpPtr[x], lParam); | 
|---|
| 2214 | if (n < 0) | 
|---|
| 2215 | r = x - 1; | 
|---|
| 2216 | else | 
|---|
| 2217 | l = x + 1; | 
|---|
| 2218 | if (n == 0) { | 
|---|
| 2219 | TRACE("-- ret=%d\n", n); | 
|---|
| 2220 | return n; | 
|---|
| 2221 | } | 
|---|
| 2222 | } | 
|---|
| 2223 |  | 
|---|
| 2224 | if (uOptions & DPAS_INSERTBEFORE) { | 
|---|
| 2225 | TRACE("-- ret=%d\n", r); | 
|---|
| 2226 | return r; | 
|---|
| 2227 | } | 
|---|
| 2228 |  | 
|---|
| 2229 | if (uOptions & DPAS_INSERTAFTER) { | 
|---|
| 2230 | TRACE("-- ret=%d\n", l); | 
|---|
| 2231 | return l; | 
|---|
| 2232 | } | 
|---|
| 2233 | } | 
|---|
| 2234 | else { | 
|---|
| 2235 | /* array is not sorted --> use linear search */ | 
|---|
| 2236 | LPVOID *lpPtr; | 
|---|
| 2237 | INT  nIndex; | 
|---|
| 2238 |  | 
|---|
| 2239 | TRACE("linear search\n"); | 
|---|
| 2240 |  | 
|---|
| 2241 | nIndex = (nStart == -1)? 0 : nStart; | 
|---|
| 2242 | lpPtr = hdpa->ptrs; | 
|---|
| 2243 | for (; nIndex < hdpa->nItemCount; nIndex++) { | 
|---|
| 2244 | if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) { | 
|---|
| 2245 | TRACE("-- ret=%d\n", nIndex); | 
|---|
| 2246 | return nIndex; | 
|---|
| 2247 | } | 
|---|
| 2248 | } | 
|---|
| 2249 | } | 
|---|
| 2250 |  | 
|---|
| 2251 | TRACE("-- not found: ret=-1\n"); | 
|---|
| 2252 | return -1; | 
|---|
| 2253 | } | 
|---|
| 2254 |  | 
|---|
| 2255 |  | 
|---|
| 2256 | /************************************************************************** | 
|---|
| 2257 | * DPA_CreateEx [COMCTL32.340] | 
|---|
| 2258 | * | 
|---|
| 2259 | * Creates a dynamic pointer array using the specified size and heap. | 
|---|
| 2260 | * | 
|---|
| 2261 | * PARAMS | 
|---|
| 2262 | *     nGrow [I] number of items by which the array grows when it is filled | 
|---|
| 2263 | *     hHeap [I] handle to the heap where the array is stored | 
|---|
| 2264 | * | 
|---|
| 2265 | * RETURNS | 
|---|
| 2266 | *     Success: handle (pointer) to the pointer array. | 
|---|
| 2267 | *     Failure: NULL | 
|---|
| 2268 | */ | 
|---|
| 2269 |  | 
|---|
| 2270 | HDPA WINAPI | 
|---|
| 2271 | DPA_CreateEx (INT nGrow, HANDLE hHeap) | 
|---|
| 2272 | { | 
|---|
| 2273 | HDPA hdpa; | 
|---|
| 2274 |  | 
|---|
| 2275 | TRACE("(%d 0x%x)\n", nGrow, hHeap); | 
|---|
| 2276 |  | 
|---|
| 2277 | if (hHeap) | 
|---|
| 2278 | hdpa = (HDPA)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(DPA)); | 
|---|
| 2279 | else | 
|---|
| 2280 | hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA)); | 
|---|
| 2281 |  | 
|---|
| 2282 | if (hdpa) { | 
|---|
| 2283 | hdpa->nGrow = min(8, nGrow); | 
|---|
| 2284 | hdpa->hHeap = hHeap ? hHeap : COMCTL32_hHeap; | 
|---|
| 2285 | hdpa->nMaxCount = hdpa->nGrow * 2; | 
|---|
| 2286 | hdpa->ptrs = | 
|---|
| 2287 | (LPVOID*)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, | 
|---|
| 2288 | hdpa->nMaxCount * sizeof(LPVOID)); | 
|---|
| 2289 | } | 
|---|
| 2290 |  | 
|---|
| 2291 | TRACE("-- %p\n", hdpa); | 
|---|
| 2292 |  | 
|---|
| 2293 | return hdpa; | 
|---|
| 2294 | } | 
|---|
| 2295 |  | 
|---|
| 2296 |  | 
|---|
| 2297 | /************************************************************************** | 
|---|
| 2298 | * Notification functions | 
|---|
| 2299 | */ | 
|---|
| 2300 |  | 
|---|
| 2301 | typedef struct tagNOTIFYDATA | 
|---|
| 2302 | { | 
|---|
| 2303 | HWND hwndFrom; | 
|---|
| 2304 | HWND hwndTo; | 
|---|
| 2305 | DWORD  dwParam3; | 
|---|
| 2306 | DWORD  dwParam4; | 
|---|
| 2307 | DWORD  dwParam5; | 
|---|
| 2308 | DWORD  dwParam6; | 
|---|
| 2309 | } NOTIFYDATA, *LPNOTIFYDATA; | 
|---|
| 2310 |  | 
|---|
| 2311 |  | 
|---|
| 2312 | /************************************************************************** | 
|---|
| 2313 | * DoNotify [Internal] | 
|---|
| 2314 | */ | 
|---|
| 2315 |  | 
|---|
| 2316 | static LRESULT | 
|---|
| 2317 | DoNotify (LPNOTIFYDATA lpNotify, UINT uCode, LPNMHDR lpHdr) | 
|---|
| 2318 | { | 
|---|
| 2319 | NMHDR nmhdr; | 
|---|
| 2320 | LPNMHDR lpNmh = NULL; | 
|---|
| 2321 | UINT idFrom = 0; | 
|---|
| 2322 |  | 
|---|
| 2323 | TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n", | 
|---|
| 2324 | lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr, | 
|---|
| 2325 | lpNotify->dwParam5); | 
|---|
| 2326 |  | 
|---|
| 2327 | if (!lpNotify->hwndTo) | 
|---|
| 2328 | return 0; | 
|---|
| 2329 |  | 
|---|
| 2330 | if (lpNotify->hwndFrom == -1) { | 
|---|
| 2331 | lpNmh = lpHdr; | 
|---|
| 2332 | idFrom = lpHdr->idFrom; | 
|---|
| 2333 | } | 
|---|
| 2334 | else { | 
|---|
| 2335 | if (lpNotify->hwndFrom) { | 
|---|
| 2336 | HWND hwndParent = GetParent (lpNotify->hwndFrom); | 
|---|
| 2337 | if (hwndParent) { | 
|---|
| 2338 | hwndParent = GetWindow (lpNotify->hwndFrom, GW_OWNER); | 
|---|
| 2339 | /* the following is done even if the return from above | 
|---|
| 2340 | * is zero.  GLA 12/2001 */ | 
|---|
| 2341 | idFrom = GetDlgCtrlID (lpNotify->hwndFrom); | 
|---|
| 2342 | } | 
|---|
| 2343 | } | 
|---|
| 2344 |  | 
|---|
| 2345 | lpNmh = (lpHdr) ? lpHdr : &nmhdr; | 
|---|
| 2346 |  | 
|---|
| 2347 | lpNmh->hwndFrom = lpNotify->hwndFrom; | 
|---|
| 2348 | lpNmh->idFrom = idFrom; | 
|---|
| 2349 | lpNmh->code = uCode; | 
|---|
| 2350 | } | 
|---|
| 2351 |  | 
|---|
| 2352 | return SendMessageA (lpNotify->hwndTo, WM_NOTIFY, idFrom, (LPARAM)lpNmh); | 
|---|
| 2353 | } | 
|---|
| 2354 |  | 
|---|
| 2355 |  | 
|---|
| 2356 | /************************************************************************** | 
|---|
| 2357 | * SendNotify [COMCTL32.341] | 
|---|
| 2358 | * | 
|---|
| 2359 | * PARAMS | 
|---|
| 2360 | *     hwndTo   [I] | 
|---|
| 2361 | *     hwndFrom [I] | 
|---|
| 2362 | *     uCode    [I] | 
|---|
| 2363 | *     lpHdr    [I] | 
|---|
| 2364 | * | 
|---|
| 2365 | * RETURNS | 
|---|
| 2366 | *     Success: return value from notification | 
|---|
| 2367 | *     Failure: 0 | 
|---|
| 2368 | */ | 
|---|
| 2369 |  | 
|---|
| 2370 | LRESULT WINAPI | 
|---|
| 2371 | COMCTL32_SendNotify (HWND hwndTo, HWND hwndFrom, | 
|---|
| 2372 | UINT uCode, LPNMHDR lpHdr) | 
|---|
| 2373 | { | 
|---|
| 2374 | NOTIFYDATA notify; | 
|---|
| 2375 |  | 
|---|
| 2376 | TRACE("(0x%04x 0x%04x %d %p)\n", | 
|---|
| 2377 | hwndTo, hwndFrom, uCode, lpHdr); | 
|---|
| 2378 |  | 
|---|
| 2379 | notify.hwndFrom = hwndFrom; | 
|---|
| 2380 | notify.hwndTo   = hwndTo; | 
|---|
| 2381 | notify.dwParam5 = 0; | 
|---|
| 2382 | notify.dwParam6 = 0; | 
|---|
| 2383 |  | 
|---|
| 2384 | return DoNotify (¬ify, uCode, lpHdr); | 
|---|
| 2385 | } | 
|---|
| 2386 |  | 
|---|
| 2387 |  | 
|---|
| 2388 | /************************************************************************** | 
|---|
| 2389 | * SendNotifyEx [COMCTL32.342] | 
|---|
| 2390 | * | 
|---|
| 2391 | * PARAMS | 
|---|
| 2392 | *     hwndFrom [I] | 
|---|
| 2393 | *     hwndTo   [I] | 
|---|
| 2394 | *     uCode    [I] | 
|---|
| 2395 | *     lpHdr    [I] | 
|---|
| 2396 | *     dwParam5 [I] | 
|---|
| 2397 | * | 
|---|
| 2398 | * RETURNS | 
|---|
| 2399 | *     Success: return value from notification | 
|---|
| 2400 | *     Failure: 0 | 
|---|
| 2401 | */ | 
|---|
| 2402 |  | 
|---|
| 2403 | LRESULT WINAPI | 
|---|
| 2404 | COMCTL32_SendNotifyEx (HWND hwndTo, HWND hwndFrom, UINT uCode, | 
|---|
| 2405 | LPNMHDR lpHdr, DWORD dwParam5) | 
|---|
| 2406 | { | 
|---|
| 2407 | NOTIFYDATA notify; | 
|---|
| 2408 | HWND hwndNotify; | 
|---|
| 2409 |  | 
|---|
| 2410 | TRACE("(0x%04x 0x%04x %d %p 0x%08lx)\n", | 
|---|
| 2411 | hwndFrom, hwndTo, uCode, lpHdr, dwParam5); | 
|---|
| 2412 |  | 
|---|
| 2413 | hwndNotify = hwndTo; | 
|---|
| 2414 | if (!hwndTo) { | 
|---|
| 2415 | if (IsWindow (hwndFrom)) { | 
|---|
| 2416 | hwndNotify = GetParent (hwndFrom); | 
|---|
| 2417 | if (!hwndNotify) | 
|---|
| 2418 | return 0; | 
|---|
| 2419 | } | 
|---|
| 2420 | } | 
|---|
| 2421 |  | 
|---|
| 2422 | notify.hwndFrom = hwndFrom; | 
|---|
| 2423 | notify.hwndTo   = hwndNotify; | 
|---|
| 2424 | notify.dwParam5 = dwParam5; | 
|---|
| 2425 | notify.dwParam6 = 0; | 
|---|
| 2426 |  | 
|---|
| 2427 | return DoNotify (¬ify, uCode, lpHdr); | 
|---|
| 2428 | } | 
|---|
| 2429 |  | 
|---|
| 2430 |  | 
|---|
| 2431 | /************************************************************************** | 
|---|
| 2432 | * StrChrA [COMCTL32.350] | 
|---|
| 2433 | * | 
|---|
| 2434 | */ | 
|---|
| 2435 |  | 
|---|
| 2436 | LPSTR WINAPI | 
|---|
| 2437 | COMCTL32_StrChrA (LPCSTR lpString, CHAR cChar) | 
|---|
| 2438 | { | 
|---|
| 2439 | return strchr (lpString, cChar); | 
|---|
| 2440 | } | 
|---|
| 2441 |  | 
|---|
| 2442 |  | 
|---|
| 2443 | /************************************************************************** | 
|---|
| 2444 | * StrStrIA [COMCTL32.355] | 
|---|
| 2445 | */ | 
|---|
| 2446 |  | 
|---|
| 2447 | LPSTR WINAPI | 
|---|
| 2448 | COMCTL32_StrStrIA (LPCSTR lpStr1, LPCSTR lpStr2) | 
|---|
| 2449 | { | 
|---|
| 2450 | INT len1, len2, i; | 
|---|
| 2451 | CHAR  first; | 
|---|
| 2452 |  | 
|---|
| 2453 | if (*lpStr2 == 0) | 
|---|
| 2454 | return ((LPSTR)lpStr1); | 
|---|
| 2455 | len1 = 0; | 
|---|
| 2456 | while (lpStr1[len1] != 0) ++len1; | 
|---|
| 2457 | len2 = 0; | 
|---|
| 2458 | while (lpStr2[len2] != 0) ++len2; | 
|---|
| 2459 | if (len2 == 0) | 
|---|
| 2460 | return ((LPSTR)(lpStr1 + len1)); | 
|---|
| 2461 | first = tolower (*lpStr2); | 
|---|
| 2462 | while (len1 >= len2) { | 
|---|
| 2463 | if (tolower(*lpStr1) == first) { | 
|---|
| 2464 | for (i = 1; i < len2; ++i) | 
|---|
| 2465 | if (tolower (lpStr1[i]) != tolower(lpStr2[i])) | 
|---|
| 2466 | break; | 
|---|
| 2467 | if (i >= len2) | 
|---|
| 2468 | return ((LPSTR)lpStr1); | 
|---|
| 2469 | } | 
|---|
| 2470 | ++lpStr1; --len1; | 
|---|
| 2471 | } | 
|---|
| 2472 | return (NULL); | 
|---|
| 2473 | } | 
|---|
| 2474 |  | 
|---|
| 2475 |  | 
|---|
| 2476 | /************************************************************************** | 
|---|
| 2477 | * StrToIntA [COMCTL32.357] Converts a string to a signed integer. | 
|---|
| 2478 | */ | 
|---|
| 2479 |  | 
|---|
| 2480 | INT WINAPI | 
|---|
| 2481 | COMCTL32_StrToIntA (LPSTR lpString) | 
|---|
| 2482 | { | 
|---|
| 2483 | return atoi(lpString); | 
|---|
| 2484 | } | 
|---|
| 2485 |  | 
|---|
| 2486 | /************************************************************************** | 
|---|
| 2487 | * StrToIntW [COMCTL32.365] Converts a wide char string to a signed integer. | 
|---|
| 2488 | */ | 
|---|
| 2489 |  | 
|---|
| 2490 | INT WINAPI | 
|---|
| 2491 | COMCTL32_StrToIntW (LPWSTR lpString) | 
|---|
| 2492 | { | 
|---|
| 2493 | return _wtoi(lpString); | 
|---|
| 2494 | } | 
|---|
| 2495 |  | 
|---|
| 2496 |  | 
|---|
| 2497 | /************************************************************************** | 
|---|
| 2498 | * DPA_EnumCallback [COMCTL32.385] | 
|---|
| 2499 | * | 
|---|
| 2500 | * Enumerates all items in a dynamic pointer array. | 
|---|
| 2501 | * | 
|---|
| 2502 | * PARAMS | 
|---|
| 2503 | *     hdpa     [I] handle to the dynamic pointer array | 
|---|
| 2504 | *     enumProc [I] | 
|---|
| 2505 | *     lParam   [I] | 
|---|
| 2506 | * | 
|---|
| 2507 | * RETURNS | 
|---|
| 2508 | *     none | 
|---|
| 2509 | */ | 
|---|
| 2510 |  | 
|---|
| 2511 | VOID WINAPI | 
|---|
| 2512 | DPA_EnumCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam) | 
|---|
| 2513 | { | 
|---|
| 2514 | INT i; | 
|---|
| 2515 |  | 
|---|
| 2516 | TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam); | 
|---|
| 2517 |  | 
|---|
| 2518 | if (!hdpa) | 
|---|
| 2519 | return; | 
|---|
| 2520 | if (hdpa->nItemCount <= 0) | 
|---|
| 2521 | return; | 
|---|
| 2522 |  | 
|---|
| 2523 | for (i = 0; i < hdpa->nItemCount; i++) { | 
|---|
| 2524 | if ((enumProc)(hdpa->ptrs[i], lParam) == 0) | 
|---|
| 2525 | return; | 
|---|
| 2526 | } | 
|---|
| 2527 |  | 
|---|
| 2528 | return; | 
|---|
| 2529 | } | 
|---|
| 2530 |  | 
|---|
| 2531 |  | 
|---|
| 2532 | /************************************************************************** | 
|---|
| 2533 | * DPA_DestroyCallback [COMCTL32.386] | 
|---|
| 2534 | * | 
|---|
| 2535 | * Enumerates all items in a dynamic pointer array and destroys it. | 
|---|
| 2536 | * | 
|---|
| 2537 | * PARAMS | 
|---|
| 2538 | *     hdpa     [I] handle to the dynamic pointer array | 
|---|
| 2539 | *     enumProc [I] | 
|---|
| 2540 | *     lParam   [I] | 
|---|
| 2541 | * | 
|---|
| 2542 | * RETURNS | 
|---|
| 2543 | *     Success: TRUE | 
|---|
| 2544 | *     Failure: FALSE | 
|---|
| 2545 | */ | 
|---|
| 2546 |  | 
|---|
| 2547 | BOOL WINAPI | 
|---|
| 2548 | DPA_DestroyCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam) | 
|---|
| 2549 | { | 
|---|
| 2550 | TRACE("(%p %p %08lx)\n", hdpa, enumProc, lParam); | 
|---|
| 2551 |  | 
|---|
| 2552 | DPA_EnumCallback (hdpa, enumProc, lParam); | 
|---|
| 2553 |  | 
|---|
| 2554 | return DPA_Destroy (hdpa); | 
|---|
| 2555 | } | 
|---|
| 2556 |  | 
|---|
| 2557 |  | 
|---|
| 2558 | /************************************************************************** | 
|---|
| 2559 | * DSA_EnumCallback [COMCTL32.387] | 
|---|
| 2560 | * | 
|---|
| 2561 | * Enumerates all items in a dynamic storage array. | 
|---|
| 2562 | * | 
|---|
| 2563 | * PARAMS | 
|---|
| 2564 | *     hdsa     [I] handle to the dynamic storage array | 
|---|
| 2565 | *     enumProc [I] | 
|---|
| 2566 | *     lParam   [I] | 
|---|
| 2567 | * | 
|---|
| 2568 | * RETURNS | 
|---|
| 2569 | *     none | 
|---|
| 2570 | */ | 
|---|
| 2571 |  | 
|---|
| 2572 | VOID WINAPI | 
|---|
| 2573 | DSA_EnumCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam) | 
|---|
| 2574 | { | 
|---|
| 2575 | INT i; | 
|---|
| 2576 |  | 
|---|
| 2577 | TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam); | 
|---|
| 2578 |  | 
|---|
| 2579 | if (!hdsa) | 
|---|
| 2580 | return; | 
|---|
| 2581 | if (hdsa->nItemCount <= 0) | 
|---|
| 2582 | return; | 
|---|
| 2583 |  | 
|---|
| 2584 | for (i = 0; i < hdsa->nItemCount; i++) { | 
|---|
| 2585 | LPVOID lpItem = DSA_GetItemPtr (hdsa, i); | 
|---|
| 2586 | if ((enumProc)(lpItem, lParam) == 0) | 
|---|
| 2587 | return; | 
|---|
| 2588 | } | 
|---|
| 2589 |  | 
|---|
| 2590 | return; | 
|---|
| 2591 | } | 
|---|
| 2592 |  | 
|---|
| 2593 |  | 
|---|
| 2594 | /************************************************************************** | 
|---|
| 2595 | * DSA_DestroyCallback [COMCTL32.388] | 
|---|
| 2596 | * | 
|---|
| 2597 | * Enumerates all items in a dynamic storage array and destroys it. | 
|---|
| 2598 | * | 
|---|
| 2599 | * PARAMS | 
|---|
| 2600 | *     hdsa     [I] handle to the dynamic storage array | 
|---|
| 2601 | *     enumProc [I] | 
|---|
| 2602 | *     lParam   [I] | 
|---|
| 2603 | * | 
|---|
| 2604 | * RETURNS | 
|---|
| 2605 | *     Success: TRUE | 
|---|
| 2606 | *     Failure: FALSE | 
|---|
| 2607 | */ | 
|---|
| 2608 |  | 
|---|
| 2609 | BOOL WINAPI | 
|---|
| 2610 | DSA_DestroyCallback (const HDSA hdsa, DSAENUMPROC enumProc, LPARAM lParam) | 
|---|
| 2611 | { | 
|---|
| 2612 | TRACE("(%p %p %08lx)\n", hdsa, enumProc, lParam); | 
|---|
| 2613 |  | 
|---|
| 2614 | DSA_EnumCallback (hdsa, enumProc, lParam); | 
|---|
| 2615 |  | 
|---|
| 2616 | return DSA_Destroy (hdsa); | 
|---|
| 2617 | } | 
|---|
| 2618 |  | 
|---|
| 2619 | /************************************************************************** | 
|---|
| 2620 | * StrCSpnA [COMCTL32.356] | 
|---|
| 2621 | * | 
|---|
| 2622 | */ | 
|---|
| 2623 | INT WINAPI COMCTL32_StrCSpnA( LPCSTR lpStr, LPCSTR lpSet) { | 
|---|
| 2624 | return strcspn(lpStr, lpSet); | 
|---|
| 2625 | } | 
|---|
| 2626 |  | 
|---|
| 2627 | /************************************************************************** | 
|---|
| 2628 | * StrChrW [COMCTL32.358] | 
|---|
| 2629 | * | 
|---|
| 2630 | */ | 
|---|
| 2631 | LPWSTR WINAPI COMCTL32_StrChrW( LPCWSTR lpStart, WORD wMatch) { | 
|---|
| 2632 | return strchrW(lpStart, wMatch); | 
|---|
| 2633 | } | 
|---|
| 2634 |  | 
|---|
| 2635 | /************************************************************************** | 
|---|
| 2636 | * StrCmpNA [COMCTL32.352] | 
|---|
| 2637 | * | 
|---|
| 2638 | */ | 
|---|
| 2639 | INT WINAPI COMCTL32_StrCmpNA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) { | 
|---|
| 2640 | return strncmp(lpStr1, lpStr2, nChar); | 
|---|
| 2641 | } | 
|---|
| 2642 |  | 
|---|
| 2643 | /************************************************************************** | 
|---|
| 2644 | * StrCmpNIA [COMCTL32.353] | 
|---|
| 2645 | * | 
|---|
| 2646 | */ | 
|---|
| 2647 | INT WINAPI COMCTL32_StrCmpNIA( LPCSTR lpStr1, LPCSTR lpStr2, int nChar) { | 
|---|
| 2648 | return strncasecmp(lpStr1, lpStr2, nChar); | 
|---|
| 2649 | } | 
|---|
| 2650 |  | 
|---|
| 2651 | /************************************************************************** | 
|---|
| 2652 | * StrCmpNW [COMCTL32.360] | 
|---|
| 2653 | * | 
|---|
| 2654 | */ | 
|---|
| 2655 | INT WINAPI COMCTL32_StrCmpNW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) { | 
|---|
| 2656 | return strncmpW(lpStr1, lpStr2, nChar); | 
|---|
| 2657 | } | 
|---|
| 2658 |  | 
|---|
| 2659 | /************************************************************************** | 
|---|
| 2660 | * StrCmpNIW [COMCTL32.361] | 
|---|
| 2661 | * | 
|---|
| 2662 | */ | 
|---|
| 2663 | INT WINAPI COMCTL32_StrCmpNIW( LPCWSTR lpStr1, LPCWSTR lpStr2, int nChar) { | 
|---|
| 2664 | FIXME("(%s, %s, %i): stub\n", debugstr_w(lpStr1), debugstr_w(lpStr2), nChar); | 
|---|
| 2665 | return 0; | 
|---|
| 2666 | } | 
|---|
| 2667 |  | 
|---|
| 2668 | /************************************************************************** | 
|---|
| 2669 | * StrRChrA [COMCTL32.351] | 
|---|
| 2670 | * | 
|---|
| 2671 | */ | 
|---|
| 2672 | LPSTR WINAPI COMCTL32_StrRChrA( LPCSTR lpStart, LPCSTR lpEnd, WORD wMatch ) | 
|---|
| 2673 | { | 
|---|
| 2674 | LPCSTR lpGotIt = NULL; | 
|---|
| 2675 | BOOL dbcs = IsDBCSLeadByte( LOBYTE(wMatch) ); | 
|---|
| 2676 |  | 
|---|
| 2677 | TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch); | 
|---|
| 2678 |  | 
|---|
| 2679 | if (!lpEnd) lpEnd = lpStart + strlen(lpStart); | 
|---|
| 2680 |  | 
|---|
| 2681 | for(; lpStart < lpEnd; lpStart = CharNextA(lpStart)) | 
|---|
| 2682 | { | 
|---|
| 2683 | if (*lpStart != LOBYTE(wMatch)) continue; | 
|---|
| 2684 | if (dbcs && lpStart[1] != HIBYTE(wMatch)) continue; | 
|---|
| 2685 | lpGotIt = lpStart; | 
|---|
| 2686 | } | 
|---|
| 2687 | return (LPSTR)lpGotIt; | 
|---|
| 2688 | } | 
|---|
| 2689 |  | 
|---|
| 2690 |  | 
|---|
| 2691 | /************************************************************************** | 
|---|
| 2692 | * StrRChrW [COMCTL32.359] | 
|---|
| 2693 | * | 
|---|
| 2694 | */ | 
|---|
| 2695 | LPWSTR WINAPI COMCTL32_StrRChrW( LPCWSTR lpStart, LPCWSTR lpEnd, WORD wMatch) | 
|---|
| 2696 | { | 
|---|
| 2697 | LPCWSTR lpGotIt = NULL; | 
|---|
| 2698 |  | 
|---|
| 2699 | TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch); | 
|---|
| 2700 | if (!lpEnd) lpEnd = lpStart + strlenW(lpStart); | 
|---|
| 2701 |  | 
|---|
| 2702 | for(; lpStart < lpEnd; lpStart = CharNextW(lpStart)) | 
|---|
| 2703 | if (*lpStart == wMatch) lpGotIt = lpStart; | 
|---|
| 2704 |  | 
|---|
| 2705 | return (LPWSTR)lpGotIt; | 
|---|
| 2706 | } | 
|---|
| 2707 |  | 
|---|
| 2708 |  | 
|---|
| 2709 | /************************************************************************** | 
|---|
| 2710 | * StrStrA [COMCTL32.354] | 
|---|
| 2711 | * | 
|---|
| 2712 | */ | 
|---|
| 2713 | LPSTR WINAPI COMCTL32_StrStrA( LPCSTR lpFirst, LPCSTR lpSrch) { | 
|---|
| 2714 | return strstr(lpFirst, lpSrch); | 
|---|
| 2715 | } | 
|---|
| 2716 |  | 
|---|
| 2717 | /************************************************************************** | 
|---|
| 2718 | * StrStrW [COMCTL32.362] | 
|---|
| 2719 | * | 
|---|
| 2720 | */ | 
|---|
| 2721 | LPWSTR WINAPI COMCTL32_StrStrW( LPCWSTR lpFirst, LPCWSTR lpSrch) { | 
|---|
| 2722 | return strstrW(lpFirst, lpSrch); | 
|---|
| 2723 | } | 
|---|
| 2724 |  | 
|---|
| 2725 | /************************************************************************** | 
|---|
| 2726 | * StrSpnW [COMCTL32.364] | 
|---|
| 2727 | * | 
|---|
| 2728 | */ | 
|---|
| 2729 | INT WINAPI COMCTL32_StrSpnW( LPWSTR lpStr, LPWSTR lpSet) { | 
|---|
| 2730 | LPWSTR lpLoop = lpStr; | 
|---|
| 2731 |  | 
|---|
| 2732 | /* validate ptr */ | 
|---|
| 2733 | if ((lpStr == 0) || (lpSet == 0)) return 0; | 
|---|
| 2734 |  | 
|---|
| 2735 | /* while(*lpLoop) { if lpLoop++; } */ | 
|---|
| 2736 |  | 
|---|
| 2737 | for(; (*lpLoop != 0); lpLoop++) | 
|---|
| 2738 | if( strchrW(lpSet, *(WORD*)lpLoop)) | 
|---|
| 2739 | return (INT)(lpLoop-lpStr); | 
|---|
| 2740 |  | 
|---|
| 2741 | return (INT)(lpLoop-lpStr); | 
|---|
| 2742 | } | 
|---|
| 2743 |  | 
|---|
| 2744 | /************************************************************************** | 
|---|
| 2745 | * @ [COMCTL32.410] | 
|---|
| 2746 | * | 
|---|
| 2747 | * FIXME: What's this supposed to do? | 
|---|
| 2748 | *        Parameter 1 is an HWND, you're on your own for the rest. | 
|---|
| 2749 | */ | 
|---|
| 2750 |  | 
|---|
| 2751 | BOOL WINAPI COMCTL32_410( HWND hw, DWORD b, DWORD c, DWORD d) { | 
|---|
| 2752 |  | 
|---|
| 2753 | FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d); | 
|---|
| 2754 |  | 
|---|
| 2755 | return TRUE; | 
|---|
| 2756 | } | 
|---|
| 2757 |  | 
|---|
| 2758 | /************************************************************************** | 
|---|
| 2759 | * @ [COMCTL32.411] | 
|---|
| 2760 | * | 
|---|
| 2761 | * FIXME: What's this supposed to do? | 
|---|
| 2762 | *        Parameter 1 is an HWND, you're on your own for the rest. | 
|---|
| 2763 | */ | 
|---|
| 2764 |  | 
|---|
| 2765 | BOOL WINAPI COMCTL32_411( HWND hw, DWORD b, DWORD c) { | 
|---|
| 2766 |  | 
|---|
| 2767 | FIXME("(%x, %lx, %lx): stub!\n", hw, b, c); | 
|---|
| 2768 |  | 
|---|
| 2769 | return TRUE; | 
|---|
| 2770 | } | 
|---|
| 2771 |  | 
|---|
| 2772 | /************************************************************************** | 
|---|
| 2773 | * @ [COMCTL32.412] | 
|---|
| 2774 | * | 
|---|
| 2775 | * FIXME: What's this supposed to do? | 
|---|
| 2776 | *        Parameter 1 is an HWND, you're on your own for the rest. | 
|---|
| 2777 | */ | 
|---|
| 2778 |  | 
|---|
| 2779 | BOOL WINAPI COMCTL32_412( HWND hwnd, DWORD b, DWORD c) | 
|---|
| 2780 | { | 
|---|
| 2781 | FIXME("(%x, %lx, %lx): stub!\n", hwnd, b, c); | 
|---|
| 2782 |  | 
|---|
| 2783 | if (IsWindow (hwnd) == FALSE) | 
|---|
| 2784 | return FALSE; | 
|---|
| 2785 |  | 
|---|
| 2786 | if (b == 0) | 
|---|
| 2787 | return FALSE; | 
|---|
| 2788 |  | 
|---|
| 2789 |  | 
|---|
| 2790 | return TRUE; | 
|---|
| 2791 | } | 
|---|
| 2792 |  | 
|---|
| 2793 | /************************************************************************** | 
|---|
| 2794 | * @ [COMCTL32.413] | 
|---|
| 2795 | * | 
|---|
| 2796 | * FIXME: What's this supposed to do? | 
|---|
| 2797 | *        Parameter 1 is an HWND, you're on your own for the rest. | 
|---|
| 2798 | */ | 
|---|
| 2799 |  | 
|---|
| 2800 | BOOL WINAPI COMCTL32_413( HWND hw, DWORD b, DWORD c, DWORD d) { | 
|---|
| 2801 |  | 
|---|
| 2802 | FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d); | 
|---|
| 2803 |  | 
|---|
| 2804 | return TRUE; | 
|---|
| 2805 | } | 
|---|
| 2806 |  | 
|---|
| 2807 |  | 
|---|
| 2808 | /************************************************************************** | 
|---|
| 2809 | * @ [COMCTL32.415] | 
|---|
| 2810 | * | 
|---|
| 2811 | * FIXME: What's this supposed to do? | 
|---|
| 2812 | *        Parameter 1 is an HWND, you're on your own for the rest. | 
|---|
| 2813 | */ | 
|---|
| 2814 |  | 
|---|
| 2815 | BOOL WINAPI COMCTL32_415( HWND hwnd, DWORD b, DWORD c, DWORD d, DWORD e) | 
|---|
| 2816 | { | 
|---|
| 2817 |  | 
|---|
| 2818 | FIXME("(%x, %lx, %lx, %lx, %lx): stub!\n", hwnd, b, c, d, e); | 
|---|
| 2819 |  | 
|---|
| 2820 | return TRUE; | 
|---|
| 2821 | } | 
|---|
| 2822 |  | 
|---|
| 2823 | /************************************************************************** | 
|---|
| 2824 | * @ [COMCTL32.419] | 
|---|
| 2825 | * | 
|---|
| 2826 | * FIXME: What's this supposed to do? | 
|---|
| 2827 | */ | 
|---|
| 2828 |  | 
|---|
| 2829 | BOOL WINAPI COMCTL32_419( DWORD a, DWORD b, DWORD c, DWORD d) | 
|---|
| 2830 | { | 
|---|
| 2831 |  | 
|---|
| 2832 | FIXME("(%lx, %lx, %lx, %lx): stub!\n", a, b, c, d); | 
|---|
| 2833 |  | 
|---|
| 2834 | return TRUE; | 
|---|
| 2835 | } | 
|---|