Index: trunk/src/comctl32/comctl32undoc.c
===================================================================
--- trunk/src/comctl32/comctl32undoc.c	(revision 293)
+++ trunk/src/comctl32/comctl32undoc.c	(revision 295)
@@ -1,3 +1,3 @@
-/* $Id: comctl32undoc.c,v 1.7 1999-06-23 19:45:00 achimha Exp $ */
+/* $Id: comctl32undoc.c,v 1.8 1999-07-12 15:58:46 cbratschi Exp $ */
 /*
  * Undocumented functions from COMCTL32.DLL
@@ -11,4 +11,10 @@
  *
  */
+
+/* CB: todo
+  - porting/implementing string functions
+  - DPA_LoadStream
+  - DPA_SaveStream
+*/
 
 #include "comctl32.h"
@@ -28,5 +34,5 @@
  *     dwFlags  [I] flags
  *     pfnSort  [I] pointer to sort function
- *     dwParam5 [I]
+ *     pfnMerge [I] pointer to merge function
  *     lParam   [I] application specific value
  *
@@ -37,59 +43,104 @@
 BOOL WINAPI
 DPA_Merge (const HDPA hdpa1, const HDPA hdpa2, DWORD dwFlags,
-	   PFNDPACOMPARE pfnCompare, LPVOID pfnParam5, LPARAM lParam)
-{
-    /* LPVOID *pWork1, *pWork2; */
-    INT  nCount1, nCount2;
+           PFNDPACOMPARE pfnCompare, PFNDPAMERGE pfnMerge, LPARAM lParam)
+{
+    LPVOID pWork1, pWork2;
+    INT nResult;
+    INT nCount, nIndex;
+    INT nNewItems;
 
 //    TRACE (commctrl, "(%p %p %08lx %p %p %08lx): stub!\n",
-//	   hdpa1, hdpa2, dwFlags, pfnCompare, pfnParam5, lParam);
+//         hdpa1, hdpa2, dwFlags, pfnCompare, pfnParam5, lParam);
 
     if (IsBadWritePtr (hdpa1, sizeof(DPA)))
-	return FALSE;
+        return FALSE;
 
     if (IsBadWritePtr (hdpa2, sizeof(DPA)))
-	return FALSE;
+        return FALSE;
 
     if (IsBadCodePtr ((FARPROC)pfnCompare))
-	return FALSE;
-
-    if (IsBadCodePtr ((FARPROC)pfnParam5))
-	return FALSE;
+        return FALSE;
+
+    if (IsBadCodePtr ((FARPROC)pfnMerge))
+        return FALSE;
 
     if (dwFlags & DPAM_SORT) {
-//	TRACE (commctrl, "sorting dpa's!\n");
-	DPA_Sort (hdpa1, pfnCompare, lParam);
-	DPA_Sort (hdpa2, pfnCompare, lParam);
-    }
-
-    if (hdpa2->nItemCount <= 0)
-	return TRUE;
-
-    nCount1 = hdpa1->nItemCount - 1;
-
-    nCount2 = hdpa2->nItemCount - 1;
-
-//    FIXME (commctrl, "nCount1=%d nCount2=%d\n", nCount1, nCount2);
-//    FIXME (commctrl, "semi stub!\n");
+//        TRACE("sorting dpa's!\n");
+        if (hdpa1->nItemCount > 0)
+        DPA_Sort (hdpa1, pfnCompare, lParam);
+//        TRACE ("dpa 1 sorted!\n");
+        if (hdpa2->nItemCount > 0)
+        DPA_Sort (hdpa2, pfnCompare, lParam);
+//        TRACE ("dpa 2 sorted!\n");
+    }
+
+    if (hdpa2->nItemCount < 1)
+        return TRUE;
+
+//    TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
+//           hdpa1->nItemCount, hdpa2->nItemCount);
+
+
+    /* preliminary hack - simply append the pointer list hdpa2 to hdpa1*/
+    for (nCount = 0; nCount < hdpa2->nItemCount; nCount++)
+        DPA_InsertPtr (hdpa1, hdpa1->nItemCount + 1, hdpa2->ptrs[nCount]);
+
 #if 0
-
-    do {
-
-
-	if (nResult == 0) {
-
-	}
-	else if (nResult > 0) {
-
-	}
-	else {
-
-	}
-
-    }
-    while (nCount2 >= 0);
-
+    /* incomplete implementation */
+
+    pWork1 = &(hdpa1->ptrs[hdpa1->nItemCount - 1]);
+    pWork2 = &(hdpa2->ptrs[hdpa2->nItemCount - 1]);
+
+    nIndex = hdpa1->nItemCount - 1;
+    nCount = hdpa2->nItemCount - 1;
+
+    do
+    {
+        nResult = (pfnCompare)(pWork1, pWork2, lParam);
+
+        if (nResult == 0)
+        {
+            PVOID ptr;
+
+            ptr = (pfnMerge)(1, pWork1, pWork2, lParam);
+            if (!ptr)
+                return FALSE;
+
+            nCount--;
+            pWork2--;
+            pWork1 = ptr;
+        }
+        else if (nResult < 0)
+        {
+            if (!dwFlags & 8)
+            {
+                PVOID ptr;
+
+                ptr = DPA_DeletePtr (hdpa1, hdpa1->nItemCount - 1);
+
+                (pfnMerge)(2, ptr, NULL, lParam);
+            }
+        }
+        else
+        {
+            if (!dwFlags & 4)
+            {
+                PVOID ptr;
+
+                ptr = (pfnMerge)(3, pWork2, NULL, lParam);
+                if (!ptr)
+                    return FALSE;
+                DPA_InsertPtr (hdpa1, nIndex, ptr);
+    }
+            nCount--;
+            pWork2--;
+        }
+
+        nIndex--;
+        pWork1--;
+
+    }
+    while (nCount >= 0);
 #endif
-
 
     return TRUE;
@@ -145,7 +196,7 @@
 
     if (lpSrc)
-	lpDest = HeapReAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, lpSrc, dwSize);
+        lpDest = HeapReAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, lpSrc, dwSize);
     else
-	lpDest = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
+        lpDest = HeapAlloc (COMCTL32_hHeap, HEAP_ZERO_MEMORY, dwSize);
 
     return lpDest;
@@ -210,5 +261,5 @@
 } MRUINFO, *LPMRUINFO;
 
- 
+
 typedef struct tagMRU
 {
@@ -223,5 +274,5 @@
 LPVOID WINAPI
 CreateMRUListLazyA (LPMRUINFO lpmi, DWORD dwParam2,
-		    DWORD dwParam3, DWORD dwParam4);
+                    DWORD dwParam3, DWORD dwParam4);
 
 
@@ -249,7 +300,7 @@
 #if 0
     if (!(hmru->dwParam1 & 1001)) {
-	RegSetValueExA (hmru->hKeyMRU, "MRUList", 0, REG_SZ,
-			  hmru->lpszMRUString,
-			  lstrlenA (hmru->lpszMRUString));
+        RegSetValueExA (hmru->hKeyMRU, "MRUList", 0, REG_SZ,
+                          hmru->lpszMRUString,
+                          lstrlenA (hmru->lpszMRUString));
     }
 
@@ -269,5 +320,5 @@
 
 //    FIXME (commctrl, "(%lx %lx %lx) empty stub!\n",
-//	   dwParam1, dwParam2, dwParam3);
+//         dwParam1, dwParam2, dwParam3);
 
     return 0;
@@ -280,5 +331,5 @@
 
 //    FIXME (commctrl, "(%lx %lx %lx %lx) empty stub!\n",
-//	   dwParam1, dwParam2, dwParam3, dwParam4);
+//         dwParam1, dwParam2, dwParam3, dwParam4);
 
     return TRUE;
@@ -304,7 +355,7 @@
 
     if (lpmi) {
-//	FIXME (commctrl, "(%lx %lx %lx %lx \"%s\" %lx)\n",
-//	       lpmi->dwParam1, lpmi->dwParam2, lpmi->dwParam3,
-//	       (DWORD)lpmi->hkeyMain, lpmi->lpszSubKey, lpmi->dwParam6);
+//      FIXME (commctrl, "(%lx %lx %lx %lx \"%s\" %lx)\n",
+//             lpmi->dwParam1, lpmi->dwParam2, lpmi->dwParam3,
+//             (DWORD)lpmi->hkeyMain, lpmi->lpszSubKey, lpmi->dwParam6);
     }
 
@@ -338,17 +389,17 @@
 
     if (!lpDest && lpSrc)
-	return lstrlenA (lpSrc);
+        return lstrlenA (lpSrc);
 
     if (nMaxLen == 0)
-	return 0;
+        return 0;
 
     if (lpSrc == NULL) {
-	lpDest[0] = '\0';
-	return 0;
+        lpDest[0] = '\0';
+        return 0;
     }
 
     len = lstrlenA (lpSrc);
     if (len >= nMaxLen)
-	len = nMaxLen - 1;
+        len = nMaxLen - 1;
 
     RtlMoveMemory (lpDest, lpSrc, len);
@@ -373,17 +424,17 @@
 {
 //    TRACE (commctrl, "(%p %p)\n", lppDest, lpSrc);
- 
+
     if (lpSrc) {
-	LPSTR ptr = COMCTL32_ReAlloc (*lppDest, lstrlenA (lpSrc) + 1);
-	if (!ptr)
-	    return FALSE;
-	lstrcpyA (ptr, lpSrc);
-	*lppDest = ptr;
+        LPSTR ptr = COMCTL32_ReAlloc (*lppDest, lstrlenA (lpSrc) + 1);
+        if (!ptr)
+            return FALSE;
+        lstrcpyA (ptr, lpSrc);
+        *lppDest = ptr;
     }
     else {
-	if (*lppDest) {
-	    COMCTL32_Free (*lppDest);
-	    *lppDest = NULL;
-	}
+        if (*lppDest) {
+            COMCTL32_Free (*lppDest);
+            *lppDest = NULL;
+        }
     }
 
@@ -411,17 +462,17 @@
 
     if (!lpDest && lpSrc)
-	return lstrlenW (lpSrc);
+        return lstrlenW (lpSrc);
 
     if (nMaxLen == 0)
-	return 0;
+        return 0;
 
     if (lpSrc == NULL) {
-	lpDest[0] = L'\0';
-	return 0;
+        lpDest[0] = L'\0';
+        return 0;
     }
 
     len = lstrlenW (lpSrc);
     if (len >= nMaxLen)
-	len = nMaxLen - 1;
+        len = nMaxLen - 1;
 
     RtlMoveMemory (lpDest, lpSrc, len*sizeof(WCHAR));
@@ -446,18 +497,18 @@
 {
 //    TRACE (commctrl, "(%p %p)\n", lppDest, lpSrc);
- 
+
     if (lpSrc) {
-	INT len = lstrlenW (lpSrc) + 1;
-	LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len * sizeof(WCHAR));
-	if (!ptr)
-	    return FALSE;
-	lstrcpyW (ptr, lpSrc);
-	*lppDest = ptr;
+        INT len = lstrlenW (lpSrc) + 1;
+        LPWSTR ptr = COMCTL32_ReAlloc (*lppDest, len * sizeof(WCHAR));
+        if (!ptr)
+            return FALSE;
+        lstrcpyW (ptr, lpSrc);
+        *lppDest = ptr;
     }
     else {
-	if (*lppDest) {
-	    COMCTL32_Free (*lppDest);
-	    *lppDest = NULL;
-	}
+        if (*lppDest) {
+            COMCTL32_Free (*lppDest);
+            *lppDest = NULL;
+        }
     }
 
@@ -494,9 +545,9 @@
     if (hdsa)
     {
-	hdsa->nItemCount = 0;
+        hdsa->nItemCount = 0;
         hdsa->pData = NULL;
-	hdsa->nMaxCount = 0;
-	hdsa->nItemSize = nSize;
-	hdsa->nGrow = MAX(1, nGrow);
+        hdsa->nMaxCount = 0;
+        hdsa->nItemSize = nSize;
+        hdsa->nGrow = MAX(1, nGrow);
     }
 
@@ -522,8 +573,8 @@
 
     if (!hdsa)
-	return FALSE;
+        return FALSE;
 
     if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
-	return FALSE;
+        return FALSE;
 
     return COMCTL32_Free (hdsa);
@@ -532,5 +583,5 @@
 
 /**************************************************************************
- * DSA_GetItem [COMCTL32.322] 
+ * DSA_GetItem [COMCTL32.322]
  *
  * PARAMS
@@ -550,9 +601,9 @@
 
 //    TRACE (commctrl, "(%p %d %p)\n", hdsa, nIndex, pDest);
-    
+
     if (!hdsa)
-	return FALSE;
+        return FALSE;
     if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
-	return FALSE;
+        return FALSE;
 
     pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
@@ -564,5 +615,5 @@
 
 /**************************************************************************
- * DSA_GetItemPtr [COMCTL32.323] 
+ * DSA_GetItemPtr [COMCTL32.323]
  *
  * Retrieves a pointer to the specified item.
@@ -585,10 +636,10 @@
 
     if (!hdsa)
-	return NULL;
+        return NULL;
     if ((nIndex < 0) || (nIndex >= hdsa->nItemCount))
-	return NULL;
+        return NULL;
 
     pSrc = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
-    
+
 //    TRACE (commctrl, "-- ret=%p\n", pSrc);
 
@@ -598,5 +649,5 @@
 
 /**************************************************************************
- * DSA_SetItem [COMCTL32.325] 
+ * DSA_SetItem [COMCTL32.325]
  *
  * Sets the contents of an item in the array.
@@ -617,30 +668,30 @@
     INT  nSize, nNewItems;
     LPVOID pDest, lpTemp;
-    
+
 //    TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
 
     if ((!hdsa) || nIndex < 0)
-	return FALSE;
-      
+        return FALSE;
+
     if (hdsa->nItemCount <= nIndex) {
-	/* within the old array */
-	if (hdsa->nMaxCount > nIndex) {
-	    /* within the allocated space, set a new boundary */
-	    hdsa->nItemCount = nIndex + 1;
-	}
-	else {
-	    /* resize the block of memory */
-	    nNewItems =
-		hdsa->nGrow * ((INT)((nIndex - 1) / hdsa->nGrow) + 1);
-	    nSize = hdsa->nItemSize * nNewItems;
-
-	    lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
-	    if (!lpTemp)
-		return FALSE;
-
-	    hdsa->nMaxCount = nNewItems;
-	    hdsa->nItemCount = nIndex + 1;
-	    hdsa->pData = lpTemp;
-	}    
+        /* within the old array */
+        if (hdsa->nMaxCount > nIndex) {
+            /* within the allocated space, set a new boundary */
+            hdsa->nItemCount = nIndex + 1;
+        }
+        else {
+            /* resize the block of memory */
+            nNewItems =
+                hdsa->nGrow * ((INT)((nIndex - 1) / hdsa->nGrow) + 1);
+            nSize = hdsa->nItemSize * nNewItems;
+
+            lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
+            if (!lpTemp)
+                return FALSE;
+
+            hdsa->nMaxCount = nNewItems;
+            hdsa->nItemCount = nIndex + 1;
+            hdsa->pData = lpTemp;
+        }
     }
 
@@ -648,5 +699,5 @@
     pDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
 //    TRACE("-- move dest=%p src=%p size=%d\n",
-//	   pDest, pSrc, hdsa->nItemSize);
+//         pDest, pSrc, hdsa->nItemSize);
     memmove (pDest, pSrc, hdsa->nItemSize);
 
@@ -656,5 +707,5 @@
 
 /**************************************************************************
- * DSA_InsertItem [COMCTL32.325] 
+ * DSA_InsertItem [COMCTL32.325]
  *
  * PARAMS
@@ -674,43 +725,43 @@
     LPVOID  lpTemp, lpDest;
     LPDWORD p;
-    
+
 //    TRACE("(%p %d %p)\n", hdsa, nIndex, pSrc);
 
     if ((!hdsa) || nIndex < 0)
-	return -1;
+        return -1;
 
     for (i = 0; i < hdsa->nItemSize; i += 4) {
-	p = *(DWORD**)((char *) pSrc + i);
-//	if (IsBadStringPtrA ((char*)p, 256))
-//	    TRACE("-- %d=%p\n", i, (DWORD*)p);
-//	else
-//	    TRACE("-- %d=%p [%s]\n", i, p, debugstr_a((char*)p));
-    }
-   
+        p = *(DWORD**)((char *) pSrc + i);
+//      if (IsBadStringPtrA ((char*)p, 256))
+//          TRACE("-- %d=%p\n", i, (DWORD*)p);
+//      else
+//          TRACE("-- %d=%p [%s]\n", i, p, debugstr_a((char*)p));
+    }
+
     /* when nIndex > nItemCount then append */
     if (nIndex >= hdsa->nItemCount)
- 	nIndex = hdsa->nItemCount;
+        nIndex = hdsa->nItemCount;
 
     /* do we need to resize ? */
     if (hdsa->nItemCount >= hdsa->nMaxCount) {
-	nNewItems = hdsa->nMaxCount + hdsa->nGrow;
-	nSize = hdsa->nItemSize * nNewItems;
-
-	lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
-	if (!lpTemp)
-	    return -1;
-
-	hdsa->nMaxCount = nNewItems;
-	hdsa->pData = lpTemp;         
+        nNewItems = hdsa->nMaxCount + hdsa->nGrow;
+        nSize = hdsa->nItemSize * nNewItems;
+
+        lpTemp = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
+        if (!lpTemp)
+            return -1;
+
+        hdsa->nMaxCount = nNewItems;
+        hdsa->pData = lpTemp;
     }
 
     /* do we need to move elements ? */
     if (nIndex < hdsa->nItemCount) {
-	lpTemp = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
-	lpDest = (char *) lpTemp + hdsa->nItemSize;
-	nSize = (hdsa->nItemCount - nIndex) * hdsa->nItemSize;
-//	TRACE("-- move dest=%p src=%p size=%d\n",
-//	       lpDest, lpTemp, nSize);
-	memmove (lpDest, lpTemp, nSize);
+        lpTemp = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
+        lpDest = (char *) lpTemp + hdsa->nItemSize;
+        nSize = (hdsa->nItemCount - nIndex) * hdsa->nItemSize;
+//      TRACE("-- move dest=%p src=%p size=%d\n",
+//             lpDest, lpTemp, nSize);
+        memmove (lpDest, lpTemp, nSize);
     }
 
@@ -719,5 +770,5 @@
     lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
 //    TRACE("-- move dest=%p src=%p size=%d\n",
-//	   lpDest, pSrc, hdsa->nItemSize);
+//         lpDest, pSrc, hdsa->nItemSize);
     memmove (lpDest, pSrc, hdsa->nItemSize);
 
@@ -727,5 +778,5 @@
 
 /**************************************************************************
- * DSA_DeleteItem [COMCTL32.326] 
+ * DSA_DeleteItem [COMCTL32.326]
  *
  * PARAMS
@@ -743,34 +794,34 @@
     LPVOID lpDest,lpSrc;
     INT  nSize;
-    
+
 //    TRACE (commctrl, "(%p %d)\n", hdsa, nIndex);
 
     if (!hdsa)
-	return -1;
+        return -1;
     if (nIndex < 0 || nIndex >= hdsa->nItemCount)
-	return -1;
+        return -1;
 
     /* do we need to move ? */
     if (nIndex < hdsa->nItemCount - 1) {
-	lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
-	lpSrc = (char *) lpDest + hdsa->nItemSize;
-	nSize = hdsa->nItemSize * (hdsa->nItemCount - nIndex - 1);
-//	TRACE (commctrl, "-- move dest=%p src=%p size=%d\n",
-//	       lpDest, lpSrc, nSize);
-	memmove (lpDest, lpSrc, nSize);
-    }
-    
+        lpDest = (char *) hdsa->pData + (hdsa->nItemSize * nIndex);
+        lpSrc = (char *) lpDest + hdsa->nItemSize;
+        nSize = hdsa->nItemSize * (hdsa->nItemCount - nIndex - 1);
+//      TRACE (commctrl, "-- move dest=%p src=%p size=%d\n",
+//             lpDest, lpSrc, nSize);
+        memmove (lpDest, lpSrc, nSize);
+    }
+
     hdsa->nItemCount--;
-    
+
     /* free memory ? */
     if ((hdsa->nMaxCount - hdsa->nItemCount) >= hdsa->nGrow) {
-	nSize = hdsa->nItemSize * hdsa->nItemCount;
-
-	lpDest = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
-	if (!lpDest)
-	    return -1;
-
-	hdsa->nMaxCount = hdsa->nItemCount;
-	hdsa->pData = lpDest;
+        nSize = hdsa->nItemSize * hdsa->nItemCount;
+
+        lpDest = (LPVOID)COMCTL32_ReAlloc (hdsa->pData, nSize);
+        if (!lpDest)
+            return -1;
+
+        hdsa->nMaxCount = hdsa->nItemCount;
+        hdsa->pData = lpDest;
     }
 
@@ -797,8 +848,8 @@
 //    TRACE (commctrl, "(%p)\n", hdsa);
 
-    if (!hdsa) 
-	return FALSE;
+    if (!hdsa)
+        return FALSE;
     if (hdsa->pData && (!COMCTL32_Free (hdsa->pData)))
-	return FALSE;
+        return FALSE;
 
     hdsa->nItemCount = 0;
@@ -835,9 +886,9 @@
     hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
     if (hdpa) {
-	hdpa->nGrow = MAX(8, nGrow);
-	hdpa->hHeap = COMCTL32_hHeap;
-	hdpa->nMaxCount = hdpa->nGrow * 2;
-	hdpa->ptrs =
-	    (LPVOID*)COMCTL32_Alloc (hdpa->nMaxCount * sizeof(LPVOID));
+        hdpa->nGrow = MAX(8, nGrow);
+        hdpa->hHeap = COMCTL32_hHeap;
+        hdpa->nMaxCount = hdpa->nGrow * 2;
+        hdpa->ptrs =
+            (LPVOID*)COMCTL32_Alloc (hdpa->nMaxCount * sizeof(LPVOID));
     }
 
@@ -865,8 +916,8 @@
 
     if (!hdpa)
-	return FALSE;
+        return FALSE;
 
     if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
-	return FALSE;
+        return FALSE;
 
     return HeapFree (hdpa->hHeap, 0, hdpa);
@@ -894,5 +945,5 @@
 
     if (!hdpa)
-	return FALSE;
+        return FALSE;
 
     hdpa->nGrow = MAX(8, nGrow);
@@ -929,32 +980,32 @@
 
     if (!hdpa)
-	return NULL;
+        return NULL;
 
 //    TRACE (commctrl, "(%p %p)\n", hdpa, hdpaNew);
 
     if (!hdpaNew) {
-	/* create a new DPA */
-	hdpaTemp = (HDPA)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
-				    sizeof(DPA));
-	hdpaTemp->hHeap = hdpa->hHeap;
-	hdpaTemp->nGrow = hdpa->nGrow;
+        /* create a new DPA */
+        hdpaTemp = (HDPA)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
+                                    sizeof(DPA));
+        hdpaTemp->hHeap = hdpa->hHeap;
+        hdpaTemp->nGrow = hdpa->nGrow;
     }
     else
-	hdpaTemp = hdpaNew;
+        hdpaTemp = hdpaNew;
 
     if (hdpaTemp->ptrs) {
-	/* remove old pointer array */
-	HeapFree (hdpaTemp->hHeap, 0, hdpaTemp->ptrs);
-	hdpaTemp->ptrs = NULL;
-	hdpaTemp->nItemCount = 0;
-	hdpaTemp->nMaxCount = 0;
+        /* remove old pointer array */
+        HeapFree (hdpaTemp->hHeap, 0, hdpaTemp->ptrs);
+        hdpaTemp->ptrs = NULL;
+        hdpaTemp->nItemCount = 0;
+        hdpaTemp->nMaxCount = 0;
     }
 
     /* create a new pointer array */
     nNewItems = hdpaTemp->nGrow *
-		((INT)((hdpa->nItemCount - 1) / hdpaTemp->nGrow) + 1);
+                ((INT)((hdpa->nItemCount - 1) / hdpaTemp->nGrow) + 1);
     nSize = nNewItems * sizeof(LPVOID);
     hdpaTemp->ptrs =
-	(LPVOID*)HeapAlloc (hdpaTemp->hHeap, HEAP_ZERO_MEMORY, nSize);
+        (LPVOID*)HeapAlloc (hdpaTemp->hHeap, HEAP_ZERO_MEMORY, nSize);
     hdpaTemp->nMaxCount = nNewItems;
 
@@ -962,5 +1013,5 @@
     hdpaTemp->nItemCount = hdpa->nItemCount;
     memmove (hdpaTemp->ptrs, hdpa->ptrs,
-	     hdpaTemp->nItemCount * sizeof(LPVOID));
+             hdpaTemp->nItemCount * sizeof(LPVOID));
 
     return hdpaTemp;
@@ -988,9 +1039,9 @@
 
     if (!hdpa)
-	return NULL;
+        return NULL;
     if (!hdpa->ptrs)
-	return NULL;
+        return NULL;
     if ((i < 0) || (i >= hdpa->nItemCount))
-	return NULL;
+        return NULL;
 
 //    TRACE (commctrl, "-- %p\n", hdpa->ptrs[i]);
@@ -1020,9 +1071,9 @@
 
     if (!hdpa->ptrs)
-	return -1;
+        return -1;
 
     for (i = 0; i < hdpa->nItemCount; i++) {
-	if (hdpa->ptrs[i] == p)
-	    return i;
+        if (hdpa->ptrs[i] == p)
+            return i;
     }
 
@@ -1055,43 +1106,43 @@
 
     if ((!hdpa) || (i < 0))
-	return -1;
+        return -1;
 
     if (!hdpa->ptrs) {
-	hdpa->ptrs =
-	    (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
-				2 * hdpa->nGrow * sizeof(LPVOID));
-	if (!hdpa->ptrs)
-	    return -1;
-	hdpa->nMaxCount = hdpa->nGrow * 2;
+        hdpa->ptrs =
+            (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
+                                2 * hdpa->nGrow * sizeof(LPVOID));
+        if (!hdpa->ptrs)
+            return -1;
+        hdpa->nMaxCount = hdpa->nGrow * 2;
         nIndex = 0;
     }
     else {
-	if (hdpa->nItemCount >= hdpa->nMaxCount) {
-//	    TRACE (commctrl, "-- resizing\n");
-	    nNewItems = hdpa->nMaxCount + hdpa->nGrow;
-	    nSize = nNewItems * sizeof(LPVOID);
-
-	    lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
-					   hdpa->ptrs, nSize);
-	    if (!lpTemp)
-		return -1;
-	    hdpa->nMaxCount = nNewItems;
-	    hdpa->ptrs = lpTemp;
-	}
-
-	if (i >= hdpa->nItemCount) {
-	    nIndex = hdpa->nItemCount;
-//	    TRACE (commctrl, "-- appending at %d\n", nIndex);
-	}
-	else {
-//	    TRACE (commctrl, "-- inserting at %d\n", i);
-	    lpTemp = hdpa->ptrs + i;
-	    lpDest = lpTemp + 1;
-	    nSize  = (hdpa->nItemCount - i) * sizeof(LPVOID);
-//	    TRACE (commctrl, "-- move dest=%p src=%p size=%x\n",
-//		   lpDest, lpTemp, nSize);
-	    memmove (lpDest, lpTemp, nSize);
-	    nIndex = i;
-	}
+        if (hdpa->nItemCount >= hdpa->nMaxCount) {
+//          TRACE (commctrl, "-- resizing\n");
+            nNewItems = hdpa->nMaxCount + hdpa->nGrow;
+            nSize = nNewItems * sizeof(LPVOID);
+
+            lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
+                                           hdpa->ptrs, nSize);
+            if (!lpTemp)
+                return -1;
+            hdpa->nMaxCount = nNewItems;
+            hdpa->ptrs = lpTemp;
+        }
+
+        if (i >= hdpa->nItemCount) {
+            nIndex = hdpa->nItemCount;
+//          TRACE (commctrl, "-- appending at %d\n", nIndex);
+        }
+        else {
+//          TRACE (commctrl, "-- inserting at %d\n", i);
+            lpTemp = hdpa->ptrs + i;
+            lpDest = lpTemp + 1;
+            nSize  = (hdpa->nItemCount - i) * sizeof(LPVOID);
+//          TRACE (commctrl, "-- move dest=%p src=%p size=%x\n",
+//                 lpDest, lpTemp, nSize);
+            memmove (lpDest, lpTemp, nSize);
+            nIndex = i;
+        }
     }
 
@@ -1123,30 +1174,30 @@
 {
     LPVOID *lpTemp;
-    
+
 //    TRACE (commctrl, "(%p %d %p)\n", hdpa, i, p);
 
     if ((!hdpa) || i < 0)
-	return FALSE;
-      
+        return FALSE;
+
     if (hdpa->nItemCount <= i) {
-	/* within the old array */
-	if (hdpa->nMaxCount > i) {
-	    /* within the allocated space, set a new boundary */
-	    hdpa->nItemCount = i;
-	}
-	else {
-	    /* resize the block of memory */
-	    INT nNewItems =
-		hdpa->nGrow * ((INT)((i - 1) / hdpa->nGrow) + 1);
-	    INT nSize = nNewItems * sizeof(LPVOID);
-
-	    lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
-					   hdpa->ptrs, nSize);
-	    if (!lpTemp)
-		return FALSE;
-
-	    hdpa->nItemCount = nNewItems;
-	    hdpa->ptrs = lpTemp;        
-	}    
+        /* within the old array */
+        if (hdpa->nMaxCount > i) {
+            /* within the allocated space, set a new boundary */
+            hdpa->nItemCount = i;
+        }
+        else {
+            /* resize the block of memory */
+            INT nNewItems =
+                hdpa->nGrow * ((INT)((i - 1) / hdpa->nGrow) + 1);
+            INT nSize = nNewItems * sizeof(LPVOID);
+
+            lpTemp = (LPVOID*)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
+                                           hdpa->ptrs, nSize);
+            if (!lpTemp)
+                return FALSE;
+
+            hdpa->nItemCount = nNewItems;
+            hdpa->ptrs = lpTemp;
+        }
     }
 
@@ -1177,9 +1228,9 @@
     LPVOID *lpDest, *lpSrc, lpTemp = NULL;
     INT  nSize;
-    
+
 //    TRACE (commctrl, "(%p %d)\n", hdpa, i);
 
     if ((!hdpa) || i < 0 || i >= hdpa->nItemCount)
-	return NULL;
+        return NULL;
 
     lpTemp = hdpa->ptrs[i];
@@ -1187,25 +1238,25 @@
     /* do we need to move ?*/
     if (i < hdpa->nItemCount - 1) {
-	lpDest = hdpa->ptrs + i;
-	lpSrc = lpDest + 1;
-	nSize = (hdpa->nItemCount - i - 1) * sizeof(LPVOID);
-//	TRACE (commctrl,"-- move dest=%p src=%p size=%x\n",
-//	       lpDest, lpSrc, nSize);
-	memmove (lpDest, lpSrc, nSize);
-    }
-    
+        lpDest = hdpa->ptrs + i;
+        lpSrc = lpDest + 1;
+        nSize = (hdpa->nItemCount - i - 1) * sizeof(LPVOID);
+//      TRACE (commctrl,"-- move dest=%p src=%p size=%x\n",
+//             lpDest, lpSrc, nSize);
+        memmove (lpDest, lpSrc, nSize);
+    }
+
     hdpa->nItemCount --;
-    
+
     /* free memory ?*/
     if ((hdpa->nMaxCount - hdpa->nItemCount) >= hdpa->nGrow) {
-	INT nNewItems = MIN(hdpa->nGrow * 2, hdpa->nItemCount);
-	nSize = nNewItems * sizeof(LPVOID);
-	lpDest = (LPVOID)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
-				      hdpa->ptrs, nSize);
-	if (!lpDest)
-	    return NULL;
-
-	hdpa->nMaxCount = nNewItems;
-	hdpa->ptrs = (LPVOID*)lpDest;         
+        INT nNewItems = MIN(hdpa->nGrow * 2, hdpa->nItemCount);
+        nSize = nNewItems * sizeof(LPVOID);
+        lpDest = (LPVOID)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
+                                      hdpa->ptrs, nSize);
+        if (!lpDest)
+            return NULL;
+
+        hdpa->nMaxCount = nNewItems;
+        hdpa->ptrs = (LPVOID*)lpDest;
     }
 
@@ -1232,14 +1283,14 @@
 //    TRACE (commctrl, "(%p)\n", hdpa);
 
-    if (!hdpa) 
-	return FALSE;
+    if (!hdpa)
+        return FALSE;
 
     if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
-	return FALSE;
+        return FALSE;
 
     hdpa->nItemCount = 0;
     hdpa->nMaxCount = hdpa->nGrow * 2;
     hdpa->ptrs = (LPVOID*)HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
-				     hdpa->nMaxCount * sizeof(LPVOID));
+                                     hdpa->nMaxCount * sizeof(LPVOID));
 
     return TRUE;
@@ -1265,5 +1316,5 @@
 static VOID
 DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r,
-	       PFNDPACOMPARE pfnCompare, LPARAM lParam)
+               PFNDPACOMPARE pfnCompare, LPARAM lParam)
 {
     LPVOID t, v;
@@ -1271,17 +1322,17 @@
 
 //    TRACE (commctrl, "l=%i r=%i\n", l, r);
- 
+
     i = l;
     j = r;
     v = lpPtrs[(int)(l+r)/2];
     do {
-	while ((pfnCompare)(lpPtrs[i], v, lParam) > 0) i++;
-	while ((pfnCompare)(lpPtrs[j], v, lParam) < 0) j--;
-	if (i <= j) 
-	{
-	    t = lpPtrs[i];
-	    lpPtrs[i++] = lpPtrs[j];
-	    lpPtrs[j--] = t;
-	}
+        while ((pfnCompare)(lpPtrs[i], v, lParam) > 0) i++;
+        while ((pfnCompare)(lpPtrs[j], v, lParam) < 0) j--;
+        if (i <= j)
+        {
+            t = lpPtrs[i];
+            lpPtrs[i++] = lpPtrs[j];
+            lpPtrs[j--] = t;
+        }
     } while (i <= j);
     if (l < j) DPA_QuickSort (lpPtrs, l, j, pfnCompare, lParam);
@@ -1309,11 +1360,11 @@
 {
     if (!hdpa || !pfnCompare)
-	return FALSE;
+        return FALSE;
 
 //    TRACE (commctrl, "(%p %p 0x%lx)\n", hdpa, pfnCompare, lParam);
 
     if ((hdpa->nItemCount > 1) && (hdpa->ptrs))
-	DPA_QuickSort (hdpa->ptrs, 0, hdpa->nItemCount - 1,
-		       pfnCompare, lParam);
+        DPA_QuickSort (hdpa->ptrs, 0, hdpa->nItemCount - 1,
+                       pfnCompare, lParam);
 
     return TRUE;
@@ -1346,60 +1397,60 @@
 INT WINAPI
 DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart,
-	    PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions)
+            PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions)
 {
     if (!hdpa || !pfnCompare || !pFind)
-	return -1;
+        return -1;
 
 //    TRACE (commctrl, "(%p %p %d %p 0x%08lx 0x%08x)\n",
-//	   hdpa, pFind, nStart, pfnCompare, lParam, uOptions);
+//         hdpa, pFind, nStart, pfnCompare, lParam, uOptions);
 
     if (uOptions & DPAS_SORTED) {
-	/* array is sorted --> use binary search */
-	INT l, r, x, n;
-	LPVOID *lpPtr;
-
-//	TRACE (commctrl, "binary search\n");
-
-	l = (nStart == -1) ? 0 : nStart;
-	r = hdpa->nItemCount - 1;
-	lpPtr = hdpa->ptrs;
-	while (r >= l) {
-	    x = (l + r) / 2;
-	    n = (pfnCompare)(pFind, lpPtr[x], lParam);
-	    if (n < 0)
-		r = x - 1;
-	    else
-		l = x + 1;
-	    if (n == 0) {
-//		TRACE (commctrl, "-- ret=%d\n", n);
-		return n;
-	    }
-	}
-
-	if (uOptions & DPAS_INSERTBEFORE) {
-//	    TRACE (commctrl, "-- ret=%d\n", r);
-	    return r;
-	}
-
-	if (uOptions & DPAS_INSERTAFTER) {
-//	    TRACE (commctrl, "-- ret=%d\n", l);
-	    return l;
-	}
+        /* array is sorted --> use binary search */
+        INT l, r, x, n;
+        LPVOID *lpPtr;
+
+//      TRACE (commctrl, "binary search\n");
+
+        l = (nStart == -1) ? 0 : nStart;
+        r = hdpa->nItemCount - 1;
+        lpPtr = hdpa->ptrs;
+        while (r >= l) {
+            x = (l + r) / 2;
+            n = (pfnCompare)(pFind, lpPtr[x], lParam);
+            if (n < 0)
+                r = x - 1;
+            else
+                l = x + 1;
+            if (n == 0) {
+//              TRACE (commctrl, "-- ret=%d\n", n);
+                return n;
+            }
+        }
+
+        if (uOptions & DPAS_INSERTBEFORE) {
+//          TRACE (commctrl, "-- ret=%d\n", r);
+            return r;
+        }
+
+        if (uOptions & DPAS_INSERTAFTER) {
+//          TRACE (commctrl, "-- ret=%d\n", l);
+            return l;
+        }
     }
     else {
-	/* array is not sorted --> use linear search */
-	LPVOID *lpPtr;
-	INT  nIndex;
-
-//	TRACE (commctrl, "linear search\n");
-	
-	nIndex = (nStart == -1)? 0 : nStart;
-	lpPtr = hdpa->ptrs;
-	for (; nIndex < hdpa->nItemCount; nIndex++) {
-	    if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) {
-//		TRACE (commctrl, "-- ret=%d\n", nIndex);
-		return nIndex;
-	    }
-	}
+        /* array is not sorted --> use linear search */
+        LPVOID *lpPtr;
+        INT  nIndex;
+
+//      TRACE (commctrl, "linear search\n");
+
+        nIndex = (nStart == -1)? 0 : nStart;
+        lpPtr = hdpa->ptrs;
+        for (; nIndex < hdpa->nItemCount; nIndex++) {
+            if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) {
+//              TRACE (commctrl, "-- ret=%d\n", nIndex);
+                return nIndex;
+            }
+        }
     }
 
@@ -1431,15 +1482,15 @@
 
     if (hHeap)
-	hdpa = (HDPA)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(DPA));
+        hdpa = (HDPA)HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(DPA));
     else
-	hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
+        hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
 
     if (hdpa) {
-	hdpa->nGrow = MIN(8, nGrow);
-	hdpa->hHeap = hHeap ? hHeap : COMCTL32_hHeap;
-	hdpa->nMaxCount = hdpa->nGrow * 2;
-	hdpa->ptrs =
-	    (LPVOID*)HeapAlloc (hHeap, HEAP_ZERO_MEMORY,
-				hdpa->nMaxCount * sizeof(LPVOID));
+        hdpa->nGrow = MIN(8, nGrow);
+        hdpa->hHeap = hHeap ? hHeap : COMCTL32_hHeap;
+        hdpa->nMaxCount = hdpa->nGrow * 2;
+        hdpa->ptrs =
+            (LPVOID*)HeapAlloc (hHeap, HEAP_ZERO_MEMORY,
+                                hdpa->nMaxCount * sizeof(LPVOID));
     }
 
@@ -1476,29 +1527,29 @@
 
 //    TRACE (commctrl, "(0x%04x 0x%04x %d %p 0x%08lx)\n",
-//	   lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr,
-//	   lpNotify->dwParam5);
+//         lpNotify->hwndFrom, lpNotify->hwndTo, uCode, lpHdr,
+//         lpNotify->dwParam5);
 
     if (!lpNotify->hwndTo)
-	return 0;
+        return 0;
 
     if (lpNotify->hwndFrom == -1) {
-	lpNmh = lpHdr;
-	idFrom = lpHdr->idFrom;
+        lpNmh = lpHdr;
+        idFrom = lpHdr->idFrom;
     }
     else {
-	if (lpNotify->hwndFrom) {
-	    HWND hwndParent = GetParent (lpNotify->hwndFrom);
-	    if (hwndParent) {
-		hwndParent = GetWindow (lpNotify->hwndFrom, GW_OWNER);
-		if (hwndParent)
-		    idFrom = GetDlgCtrlID (lpNotify->hwndFrom);
-	    }
-	}
-
-	lpNmh = (lpHdr) ? lpHdr : &nmhdr;
-
-	lpNmh->hwndFrom = lpNotify->hwndFrom;
-	lpNmh->idFrom = idFrom;
-	lpNmh->code = uCode;
+        if (lpNotify->hwndFrom) {
+            HWND hwndParent = GetParent (lpNotify->hwndFrom);
+            if (hwndParent) {
+                hwndParent = GetWindow (lpNotify->hwndFrom, GW_OWNER);
+                if (hwndParent)
+                    idFrom = GetDlgCtrlID (lpNotify->hwndFrom);
+            }
+        }
+
+        lpNmh = (lpHdr) ? lpHdr : &nmhdr;
+
+        lpNmh->hwndFrom = lpNotify->hwndFrom;
+        lpNmh->idFrom = idFrom;
+        lpNmh->code = uCode;
     }
 
@@ -1523,10 +1574,10 @@
 LRESULT WINAPI
 COMCTL32_SendNotify (HWND hwndFrom, HWND hwndTo,
-		     UINT uCode, LPNMHDR lpHdr)
+                     UINT uCode, LPNMHDR lpHdr)
 {
     NOTIFYDATA notify;
 
 //    TRACE (commctrl, "(0x%04x 0x%04x %d %p)\n",
-//	   hwndFrom, hwndTo, uCode, lpHdr);
+//         hwndFrom, hwndTo, uCode, lpHdr);
 
     notify.hwndFrom = hwndFrom;
@@ -1556,5 +1607,5 @@
 LRESULT WINAPI
 COMCTL32_SendNotifyEx (HWND hwndTo, HWND hwndFrom, UINT uCode,
-		       LPNMHDR lpHdr, DWORD dwParam5)
+                       LPNMHDR lpHdr, DWORD dwParam5)
 {
     NOTIFYDATA notify;
@@ -1562,13 +1613,13 @@
 
 //    TRACE (commctrl, "(0x%04x 0x%04x %d %p 0x%08lx)\n",
-//	   hwndFrom, hwndTo, uCode, lpHdr, dwParam5);
+//         hwndFrom, hwndTo, uCode, lpHdr, dwParam5);
 
     hwndNotify = hwndTo;
     if (!hwndTo) {
-	if (IsWindow (hwndFrom)) {
-	    hwndNotify = GetParent (hwndFrom);
-	    if (!hwndNotify)
-		return 0;
-	}
+        if (IsWindow (hwndFrom)) {
+            hwndNotify = GetParent (hwndFrom);
+            if (!hwndNotify)
+                return 0;
+        }
     }
 
@@ -1605,5 +1656,5 @@
 
     if (*lpStr2 == 0)
-	return ((LPSTR)lpStr1);
+        return ((LPSTR)lpStr1);
     len1 = 0;
     while (lpStr1[len1] != 0) ++len1;
@@ -1611,15 +1662,15 @@
     while (lpStr2[len2] != 0) ++len2;
     if (len2 == 0)
-	return ((LPSTR)(lpStr1 + len1));
+        return ((LPSTR)(lpStr1 + len1));
     first = tolower (*lpStr2);
     while (len1 >= len2) {
-	if (tolower(*lpStr1) == first) {
-	    for (i = 1; i < len2; ++i)
-		if (tolower (lpStr1[i]) != tolower(lpStr2[i]))
-		    break;
-	    if (i >= len2)
-		return ((LPSTR)lpStr1);
-        }
-	++lpStr1; --len1;
+        if (tolower(*lpStr1) == first) {
+            for (i = 1; i < len2; ++i)
+                if (tolower (lpStr1[i]) != tolower(lpStr2[i]))
+                    break;
+            if (i >= len2)
+                return ((LPSTR)lpStr1);
+        }
+        ++lpStr1; --len1;
     }
     return (NULL);
@@ -1641,39 +1692,4 @@
  *
  * Enumerates all items in a dynamic pointer array.
- *
- * PARAMS
- *     hdpa     [I] handle to the dynamic pointer array
- *     enumProc [I]
- *     lParam   [I] 
- *
- * RETURNS
- *     none
- */
-
-VOID WINAPI
-DPA_EnumCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
-{
-    INT i;
-
-//    TRACE (commctrl, "(%p %p %08lx)\n", hdpa, enumProc, lParam);
-
-    if (!hdpa)
-	return;
-    if (hdpa->nItemCount <= 0)
-	return;
-
-    for (i = 0; i < hdpa->nItemCount; i++) {
-	if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
-	    return;
-    }
-
-    return;
-}
-
-
-/**************************************************************************
- * DPA_DestroyCallback [COMCTL32.386]
- *
- * Enumerates all items in a dynamic pointer array and destroys it.
  *
  * PARAMS
@@ -1683,4 +1699,40 @@
  *
  * RETURNS
+ *     none
+ */
+
+
+VOID WINAPI
+DPA_EnumCallback (const HDPA hdpa, DPAENUMPROC enumProc, LPARAM lParam)
+{
+    INT i;
+
+//    TRACE (commctrl, "(%p %p %08lx)\n", hdpa, enumProc, lParam);
+
+    if (!hdpa)
+        return;
+    if (hdpa->nItemCount <= 0)
+        return;
+
+    for (i = 0; i < hdpa->nItemCount; i++) {
+        if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
+            return;
+    }
+
+    return;
+}
+
+
+/**************************************************************************
+ * DPA_DestroyCallback [COMCTL32.386]
+ *
+ * Enumerates all items in a dynamic pointer array and destroys it.
+ *
+ * PARAMS
+ *     hdpa     [I] handle to the dynamic pointer array
+ *     enumProc [I]
+ *     lParam   [I]
+ *
+ * RETURNS
  *     Success: TRUE
  *     Failure: FALSE
@@ -1720,12 +1772,12 @@
 
     if (!hdsa)
-	return;
+        return;
     if (hdsa->nItemCount <= 0)
-	return;
+        return;
 
     for (i = 0; i < hdsa->nItemCount; i++) {
-	LPVOID lpItem = DSA_GetItemPtr (hdsa, i);
-	if ((enumProc)(lpItem, lParam) == 0)
-	    return;
+        LPVOID lpItem = DSA_GetItemPtr (hdsa, i);
+        if ((enumProc)(lpItem, lParam) == 0)
+            return;
     }
 
@@ -1796,5 +1848,5 @@
  */
 LPSTR WINAPI COMCTL32_StrRChrA( LPCSTR lpStart, LPCSTR lpEnd, WORD wMatch) {
-//  return lstrrchr(lpStart, lpEnd, wMatch); 
+//  return lstrrchr(lpStart, lpEnd, wMatch);
 }
 
@@ -1804,5 +1856,5 @@
  */
 LPWSTR WINAPI COMCTL32_StrRChrW( LPCWSTR lpStart, LPCWSTR lpEnd, WORD wMatch) {
-//  return lstrrchrw(lpStart, lpEnd, wMatch); 
+//  return lstrrchrw(lpStart, lpEnd, wMatch);
 }
 
@@ -1838,5 +1890,5 @@
 //    if( CRTDLL_wcschr(lpSet, *(WORD*)lpLoop))
 //      return (INT)(lpLoop-lpStr);
-  
+
 //  return (INT)(lpLoop-lpStr);
 }
Index: trunk/src/comctl32/imagelist.c
===================================================================
--- trunk/src/comctl32/imagelist.c	(revision 293)
+++ trunk/src/comctl32/imagelist.c	(revision 295)
@@ -1,3 +1,3 @@
-/* $Id: imagelist.c,v 1.4 1999-06-23 19:45:00 achimha Exp $ */
+/* $Id: imagelist.c,v 1.5 1999-07-12 15:58:47 cbratschi Exp $ */
 /*
  *  ImageList implementation
@@ -21,7 +21,12 @@
  *    - ImageList_Draw, ImageList_DrawEx and ImageList_GetIcon use
  *      ImageList_DrawIndirect. Since ImageList_DrawIndirect is still
- *      partially imlemented, the functions mentioned above will be 
+ *      partially imlemented, the functions mentioned above will be
  *      limited in functionality too.
  */
+
+/* CB: todo
+  - ImageList_Read
+  - ImageList_Write
+*/
 
 /* This must be defined because the HIMAGELIST type is just a pointer
@@ -32,5 +37,5 @@
 #define __WINE_IMAGELIST_C
 
-#include "imagelist.h" 
+#include "imagelist.h"
 #include "commctrl.h"
 #include "comctl32.h"
@@ -57,5 +62,5 @@
 
 /*************************************************************************
- * IMAGELIST_InternalExpandBitmaps [Internal] 
+ * IMAGELIST_InternalExpandBitmaps [Internal]
  *
  * Expands the bitmaps of an image list by the given number of images.
@@ -101,5 +106,5 @@
 
     if (himl->hbmMask) {
-        hbmNewBitmap = 
+        hbmNewBitmap =
             CreateBitmap (nNewWidth, himl->cy, 1, 1, NULL);
 
@@ -138,5 +143,5 @@
 
 INT WINAPI
-ImageList_Add (HIMAGELIST himl,	HBITMAP hbmImage, HBITMAP hbmMask)
+ImageList_Add (HIMAGELIST himl, HBITMAP hbmImage, HBITMAP hbmMask)
 {
     HDC    hdcSrc, hdcDst;
@@ -146,5 +151,5 @@
 
     if (!himl || !hbmImage)
-	return -1;
+        return -1;
 
     GetObjectA (hbmImage, sizeof(BITMAP), (LPVOID)&bmp);
@@ -164,21 +169,21 @@
     BitBlt (hdcDst, himl->cCurImage * himl->cx, 0,
               bmp.bmWidth, himl->cy, hdcSrc, 0, 0, SRCCOPY);
-          
+
     if (himl->hbmMask) {
         if (hbmMask) {
-	    /* copy mask bitmap */
+            /* copy mask bitmap */
             SelectObject (hdcDst, himl->hbmMask);
             SelectObject (hdcSrc, hbmMask);
             BitBlt (hdcDst, nStartX, 0, bmp.bmWidth, himl->cy,
-		      hdcSrc, 0, 0, SRCCOPY);
+                      hdcSrc, 0, 0, SRCCOPY);
         }
         else {
-	    /* copy monochrome image to the mask bitmap */
+            /* copy monochrome image to the mask bitmap */
             SelectObject (hdcDst, himl->hbmMask);
             SelectObject (hdcSrc, hbmImage);
-	    SetBkColor (hdcSrc, GetNearestColor (hdcSrc,
-			  GetPixel (hdcSrc, 0, 0)));
-	    BitBlt (hdcDst, nStartX, 0, bmp.bmWidth, himl->cy,
-		      hdcSrc, nStartX, 0, SRCCOPY);
+            SetBkColor (hdcSrc, GetNearestColor (hdcSrc,
+                          GetPixel (hdcSrc, 0, 0)));
+            BitBlt (hdcDst, nStartX, 0, bmp.bmWidth, himl->cy,
+                      hdcSrc, nStartX, 0, SRCCOPY);
         }
     }
@@ -216,5 +221,5 @@
 
 /*************************************************************************
- * ImageList_AddMasked [COMCTL32.41] 
+ * ImageList_AddMasked [COMCTL32.41]
  *
  * Adds an image or images to an image list and creates a mask from the
@@ -239,8 +244,8 @@
 
     if (himl == NULL)
-	return -1;
+        return -1;
 
     if (!GetObjectA (hBitmap, sizeof(BITMAP), &bmp))
-	return -1;
+        return -1;
 
     nImageCount = bmp.bmWidth / himl->cx;
@@ -261,15 +266,15 @@
 
     if (himl->hbmMask) {
-	COLORREF bkColor = (clrMask != CLR_DEFAULT) ? clrMask :
-	    GetNearestColor (hdcBitmap, GetPixel (hdcBitmap, 0, 0));
-
-	/* create mask from image */
+        COLORREF bkColor = (clrMask != CLR_DEFAULT) ? clrMask :
+            GetNearestColor (hdcBitmap, GetPixel (hdcBitmap, 0, 0));
+
+        /* create mask from image */
         hdcMask = CreateCompatibleDC (0);
         SelectObject (hdcMask, himl->hbmMask);
 
-	/* create monochrome image to the mask bitmap */
-	SetBkColor (hdcBitmap, bkColor);
-	BitBlt (hdcMask, nIndex * himl->cx, 0, bmp.bmWidth, himl->cy,
-		  hdcBitmap, 0, 0, SRCCOPY);
+        /* create monochrome image to the mask bitmap */
+        SetBkColor (hdcBitmap, bkColor);
+        BitBlt (hdcMask, nIndex * himl->cx, 0, bmp.bmWidth, himl->cy,
+                  hdcBitmap, 0, 0, SRCCOPY);
 
         DeleteDC (hdcMask);
@@ -278,5 +283,5 @@
     DeleteDC (hdcImage);
     DeleteDC (hdcBitmap);
-  
+
     return nIndex;
 }
@@ -284,5 +289,5 @@
 
 /*************************************************************************
- * ImageList_BeginDrag [COMCTL32.42] 
+ * ImageList_BeginDrag [COMCTL32.42]
  *
  * Creates a temporary image list that contains one image. It will be used
@@ -302,5 +307,5 @@
 BOOL WINAPI
 ImageList_BeginDrag (HIMAGELIST himlTrack, INT iTrack,
-	             INT dxHotspot, INT dyHotspot)
+                     INT dxHotspot, INT dyHotspot)
 {
     HDC hdcSrc, hdcDst;
@@ -309,5 +314,5 @@
 
     if (himlTrack == NULL)
-	return FALSE;
+        return FALSE;
 
     if (himlInternalDrag)
@@ -315,6 +320,6 @@
 
     himlInternalDrag =
-	ImageList_Create (himlTrack->cx, himlTrack->cy,
-			  himlTrack->flags, 1, 1);
+        ImageList_Create (himlTrack->cx, himlTrack->cy,
+                          himlTrack->flags, 1, 1);
     if (himlInternalDrag == NULL) {
 //        ERR(imagelist, "Error creating drag image list!\n");
@@ -350,7 +355,7 @@
 
 /*************************************************************************
- * ImageList_Copy [COMCTL32.43] 
- *
- *  Copies an image of the source image list to an image of the 
+ * ImageList_Copy [COMCTL32.43]
+ *
+ *  Copies an image of the source image list to an image of the
  *  destination image list. Images can be copied or swapped.
  *
@@ -373,17 +378,17 @@
 
 BOOL WINAPI
-ImageList_Copy (HIMAGELIST himlDst, INT iDst,	HIMAGELIST himlSrc,
-		INT iSrc, INT uFlags)
-{
-    HDC hdcSrc, hdcDst;    
+ImageList_Copy (HIMAGELIST himlDst, INT iDst,   HIMAGELIST himlSrc,
+                INT iSrc, INT uFlags)
+{
+    HDC hdcSrc, hdcDst;
 
 //    TRACE(imagelist, "iDst=%d  iSrc=%d\n", iDst, iSrc);
 
     if ((himlSrc == NULL) || (himlDst == NULL))
-	return FALSE;
+        return FALSE;
     if ((iDst < 0) || (iDst >= himlDst->cCurImage))
-	return FALSE;
+        return FALSE;
     if ((iSrc < 0) || (iSrc >= himlSrc->cCurImage))
-	return FALSE;
+        return FALSE;
 
     hdcSrc = CreateCompatibleDC (0);
@@ -401,5 +406,5 @@
                                        himlSrc->uBitsPixel, NULL);
         hbmTempMask = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
-				      1, NULL);
+                                      1, NULL);
 
         /* copy (and stretch) destination to temporary bitmaps.(save) */
@@ -494,5 +499,5 @@
 HIMAGELIST WINAPI
 ImageList_Create (INT cx, INT cy, UINT flags,
-		  INT cInitial, INT cGrow)
+                  INT cInitial, INT cGrow)
 {
     HIMAGELIST himl;
@@ -500,5 +505,5 @@
     INT      nCount;
     HBITMAP  hbmTemp;
-    static WORD aBitBlend25[] = 
+    static WORD aBitBlend25[] =
         {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
 
@@ -542,5 +547,5 @@
     if (himl->flags & ILC_MASK) {
         himl->hbmMask = CreateBitmap (himl->cx * himl->cMaxImage, himl->cy,
-					1, 1, NULL);
+                                        1, 1, NULL);
         if (himl->hbmMask == 0) {
 //            ERR(imagelist, "Error creating mask bitmap!\n");
@@ -567,5 +572,5 @@
 
 /*************************************************************************
- * ImageList_Destroy [COMCTL32.45] 
+ * ImageList_Destroy [COMCTL32.45]
  *
  * Destroys an image list.
@@ -581,7 +586,7 @@
 BOOL WINAPI
 ImageList_Destroy (HIMAGELIST himl)
-{ 
+{
     if (!himl)
-	return FALSE;
+        return FALSE;
 
     /* delete image bitmaps */
@@ -596,5 +601,5 @@
     if (himl->hbrBlend50)
         DeleteObject (himl->hbrBlend50);
-        
+
     COMCTL32_Free (himl);
 
@@ -604,5 +609,5 @@
 
 /*************************************************************************
- * ImageList_DragEnter [COMCTL32.46] 
+ * ImageList_DragEnter [COMCTL32.46]
  *
  * Locks window update and displays the drag image at the given position.
@@ -626,10 +631,10 @@
 {
     if (himlInternalDrag == NULL)
-	return FALSE;
+        return FALSE;
 
     if (hwndLock)
-	hwndInternalDrag = hwndLock;
+        hwndInternalDrag = hwndLock;
     else
-	hwndInternalDrag = GetDesktopWindow ();
+        hwndInternalDrag = GetDesktopWindow ();
 
     xInternalPos = x;
@@ -638,5 +643,5 @@
     hdcBackBuffer = CreateCompatibleDC (0);
     hbmBackBuffer = CreateCompatibleBitmap (hdcBackBuffer,
-		himlInternalDrag->cx, himlInternalDrag->cy);
+                himlInternalDrag->cx, himlInternalDrag->cy);
 
     ImageList_DragShowNolock (TRUE);
@@ -647,5 +652,5 @@
 
 /*************************************************************************
- * ImageList_DragLeave [COMCTL32.47] 
+ * ImageList_DragLeave [COMCTL32.47]
  *
  * Unlocks window update and hides the drag image.
@@ -663,7 +668,7 @@
 {
     if (hwndLock)
-	hwndInternalDrag = hwndLock;
+        hwndInternalDrag = hwndLock;
     else
-	hwndInternalDrag = GetDesktopWindow ();
+        hwndInternalDrag = GetDesktopWindow ();
 
     ImageList_DragShowNolock (FALSE);
@@ -677,5 +682,5 @@
 
 /*************************************************************************
- * ImageList_DragMove [COMCTL32.48] 
+ * ImageList_DragMove [COMCTL32.48]
  *
  * Moves the drag image.
@@ -709,5 +714,5 @@
 
 /*************************************************************************
- * ImageList_DragShowNolock [COMCTL32.49] 
+ * ImageList_DragShowNolock [COMCTL32.49]
  *
  * Shows or hides the drag image.
@@ -733,18 +738,18 @@
 
     hdcDrag = GetDCEx (hwndInternalDrag, 0,
-			 DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
+                         DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
 
     if (bShow) {
-	/* show drag image */
-
-	/* save background */
-
-	/* draw drag image */
+        /* show drag image */
+
+        /* save background */
+
+        /* draw drag image */
 
     }
     else {
-	/* hide drag image */
-
-	/* restore background */
+        /* hide drag image */
+
+        /* restore background */
 
     }
@@ -780,5 +785,5 @@
 BOOL WINAPI
 ImageList_Draw (HIMAGELIST himl, INT i, HDC hdc,
-		INT x, INT y, UINT fStyle)
+                INT x, INT y, UINT fStyle)
 {
     IMAGELISTDRAWPARAMS imldp;
@@ -833,6 +838,6 @@
 BOOL WINAPI
 ImageList_DrawEx (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y,
-		  INT dx, INT dy, COLORREF rgbBk, COLORREF rgbFg,
-		  UINT fStyle)
+                  INT dx, INT dy, COLORREF rgbBk, COLORREF rgbFg,
+                  UINT fStyle)
 {
     IMAGELISTDRAWPARAMS imldp;
@@ -858,5 +863,5 @@
 
 /*************************************************************************
- * ImageList_DrawIndirect [COMCTL32.52] 
+ * ImageList_DrawIndirect [COMCTL32.52]
  *
  * Draws an image using ...
@@ -888,11 +893,11 @@
 
     if (pimldp == NULL)
-	return FALSE;
+        return FALSE;
     if (pimldp->cbSize < sizeof(IMAGELISTDRAWPARAMS))
-	return FALSE;
+        return FALSE;
     if (pimldp->himl == NULL)
-	return FALSE;
+        return FALSE;
     if ((pimldp->i < 0) || (pimldp->i > pimldp->himl->cCurImage))
-	return FALSE;
+        return FALSE;
 
     himlLocal = pimldp->himl;
@@ -914,5 +919,5 @@
         bMaskTrans = TRUE;
     }
-    
+
     /* ILD_IMAGE state (changes) */
     if (pimldp->fStyle & ILD_IMAGE)
@@ -922,5 +927,5 @@
         bImageTrans = FALSE;
     }
-    
+
     /* ILD_MASK state (changes) */
     if ((pimldp->fStyle & ILD_MASK) && (himlLocal->hbmMask))
@@ -947,17 +952,17 @@
     if (bMask)
     {
-	/* draw the mask */
-	SelectObject (hdcImageList, himlLocal->hbmMask);
-	SetBkColor (hdcImageList, RGB(255, 255, 255));
-	SetTextColor (hdcImageList, RGB(0, 0, 0));
-	BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy,
-		  hdcImageList, himlLocal->cx * pimldp->i, 0,
-		  bMaskTrans ? SRCAND : SRCCOPY);
+        /* draw the mask */
+        SelectObject (hdcImageList, himlLocal->hbmMask);
+        SetBkColor (hdcImageList, RGB(255, 255, 255));
+        SetTextColor (hdcImageList, RGB(0, 0, 0));
+        BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy,
+                  hdcImageList, himlLocal->cx * pimldp->i, 0,
+                  bMaskTrans ? SRCAND : SRCCOPY);
     }
 
     if (bImage)
     {
-	/* draw the image */
-	SelectObject (hdcImageList, himlLocal->hbmImage);
+        /* draw the image */
+        SelectObject (hdcImageList, himlLocal->hbmImage);
 
         if (!bImageTrans)
@@ -993,9 +998,9 @@
             SelectObject (hdcImageList, himlLocal->hbmMask);
             BitBlt (hdcTempImage, 0, 0, himlLocal->cx,
-                      himlLocal->cy, hdcImageList, 
+                      himlLocal->cy, hdcImageList,
                       pimldp->i * himlLocal->cx, 0, SRCPAINT);
 
             BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy,
-		      hdcTempImage, 0, 0, SRCAND);
+                      hdcTempImage, 0, 0, SRCAND);
 
             /* fill */
@@ -1011,5 +1016,5 @@
             SelectObject (hdcImageList, himlLocal->hbmMask);
             BitBlt (hdcTempImage, 0, 0, himlLocal->cx,
-                      himlLocal->cy, hdcImageList, 
+                      himlLocal->cy, hdcImageList,
                       pimldp->i * himlLocal->cx, 0, SRCPAINT);
 
@@ -1020,18 +1025,18 @@
             DeleteDC (hdcTempImage);
         }
-    }   
+    }
 
     /* Draw overlay image */
     if (pimldp->fStyle & 0x0700) {
-	nOvlIdx = (pimldp->fStyle & 0x0700) >> 8;
-	if ((nOvlIdx >= 1) && (nOvlIdx <= MAX_OVERLAYIMAGE)) {
-	    nOvlIdx = pimldp->himl->nOvlIdx[nOvlIdx - 1];
-	    if ((nOvlIdx >= 0) && (nOvlIdx <= pimldp->himl->cCurImage)) {
-		if (pimldp->himl->hbmMask) {  
+        nOvlIdx = (pimldp->fStyle & 0x0700) >> 8;
+        if ((nOvlIdx >= 1) && (nOvlIdx <= MAX_OVERLAYIMAGE)) {
+            nOvlIdx = pimldp->himl->nOvlIdx[nOvlIdx - 1];
+            if ((nOvlIdx >= 0) && (nOvlIdx <= pimldp->himl->cCurImage)) {
+                if (pimldp->himl->hbmMask) {
                     SelectObject (hdcImageList, pimldp->himl->hbmMask);
                     BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy,
                               hdcImageList, pimldp->himl->cx * nOvlIdx, 0,
-			      SRCAND);
-		}  
+                              SRCAND);
+                }
                 SelectObject (hdcImageList, pimldp->himl->hbmImage);
                 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y,
@@ -1043,5 +1048,5 @@
 
     DeleteDC (hdcImageList);
-  
+
     return TRUE;
 }
@@ -1151,5 +1156,5 @@
 {
     if (himl == NULL)
-	return CLR_NONE;
+        return CLR_NONE;
 
     return himl->clrBk;
@@ -1187,5 +1192,5 @@
 
 /*************************************************************************
- * ImageList_GetIcon [COMCTL32.57] 
+ * ImageList_GetIcon [COMCTL32.57]
  *
  * Creates an icon from a masked image of an image list.
@@ -1209,5 +1214,5 @@
 
     if ((himl == NULL) || (i < 0) || (i >= himl->cCurImage))
-	return 0;
+        return 0;
 
     hdcSrc = CreateCompatibleDC(0);
@@ -1222,10 +1227,10 @@
     SelectObject (hdcDst, ii.hbmMask);
     if (himl->hbmMask) {
-	SelectObject (hdcSrc, himl->hbmMask);
-	BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
-		  hdcSrc, i * himl->cx, 0, SRCCOPY);
+        SelectObject (hdcSrc, himl->hbmMask);
+        BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
+                  hdcSrc, i * himl->cx, 0, SRCCOPY);
     }
     else
-	PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
+        PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
 
     /* draw image*/
@@ -1233,7 +1238,7 @@
     SelectObject (hdcSrc, himl->hbmImage);
     BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
-	      hdcSrc, i * himl->cx, 0, SRCCOPY);
-
-    hIcon = CreateIconIndirect (&ii);    
+              hdcSrc, i * himl->cx, 0, SRCCOPY);
+
+    hIcon = CreateIconIndirect (&ii);
 
     DeleteDC (hdcSrc);
@@ -1268,12 +1273,12 @@
 {
     if (himl == NULL)
-	return FALSE;
+        return FALSE;
     if ((himl->cx <= 0) || (himl->cy <= 0))
-	return FALSE;
+        return FALSE;
 
     if (cx)
-	*cx = himl->cx;
+        *cx = himl->cx;
     if (cy)
-	*cy = himl->cy;
+        *cy = himl->cy;
 
     return TRUE;
@@ -1298,5 +1303,5 @@
 {
     if (himl == NULL)
-	return 0;
+        return 0;
 
     return himl->cCurImage;
@@ -1323,16 +1328,16 @@
 {
     if ((himl == NULL) || (pImageInfo == NULL))
-	return FALSE;
+        return FALSE;
     if ((i < 0) || (i >= himl->cCurImage))
-	return FALSE;
+        return FALSE;
 
     pImageInfo->hbmImage = himl->hbmImage;
     pImageInfo->hbmMask  = himl->hbmMask;
-    
+
     pImageInfo->rcImage.top    = 0;
     pImageInfo->rcImage.bottom = himl->cy;
     pImageInfo->rcImage.left   = i * himl->cx;
     pImageInfo->rcImage.right  = (i+1) * himl->cx;
-    
+
     return TRUE;
 }
@@ -1340,5 +1345,5 @@
 
 /*************************************************************************
- * ImageList_GetImageRect [COMCTL32.61] 
+ * ImageList_GetImageRect [COMCTL32.61]
  *
  * Retrieves the rectangle of the specified image in an image list.
@@ -1361,7 +1366,7 @@
 {
     if ((himl == NULL) || (lpRect == NULL))
-	return FALSE;
+        return FALSE;
     if ((i < 0) || (i >= himl->cCurImage))
-	return FALSE;
+        return FALSE;
 
     lpRect->left   = i * himl->cx;
@@ -1397,6 +1402,6 @@
 
 HIMAGELIST WINAPI
-ImageList_LoadImageA (HINSTANCE hi, LPCSTR lpbmp, INT cx,	INT cGrow,
-			COLORREF clrMask, UINT uType,	UINT uFlags)
+ImageList_LoadImageA (HINSTANCE hi, LPCSTR lpbmp, INT cx,       INT cGrow,
+                        COLORREF clrMask, UINT uType,   UINT uFlags)
 {
     HIMAGELIST himl = NULL;
@@ -1413,4 +1418,17 @@
         BITMAP bmp;
         GetObjectA (handle, sizeof(BITMAP), &bmp);
+
+        /* To match windows behavior, if cx is set to zero and
+         the flag DI_DEFAULTSIZE is specified, cx becomes the
+         system metric value for icons. If the flag is not specified
+         the function sets the size to the height of the bitmap */
+        if (cx == 0)
+        {
+            if (uFlags & DI_DEFAULTSIZE)
+                cx = GetSystemMetrics (SM_CXICON);
+            else
+                cx = bmp.bmHeight;
+        }
+
         nImageCount = bmp.bmWidth / cx;
 
@@ -1425,5 +1443,5 @@
         GetIconInfo (handle, &ii);
         GetObjectA (ii.hbmColor, sizeof(BITMAP), (LPVOID)&bmp);
-        himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight, 
+        himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
                                  ILC_MASK | ILC_COLOR, 1, cGrow);
         ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
@@ -1433,5 +1451,5 @@
 
     DeleteObject (handle);
-    
+
     return himl;
 }
@@ -1462,5 +1480,5 @@
 HIMAGELIST WINAPI
 ImageList_LoadImageW (HINSTANCE hi, LPCWSTR lpbmp, INT cx, INT cGrow,
-			COLORREF clrMask, UINT uType,	UINT uFlags)
+                        COLORREF clrMask, UINT uType,   UINT uFlags)
 {
     HIMAGELIST himl = NULL;
@@ -1489,5 +1507,5 @@
         GetIconInfo (handle, &ii);
         GetObjectA (ii.hbmMask, sizeof(BITMAP), (LPVOID)&bmp);
-        himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight, 
+        himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
                                  ILC_MASK | ILC_COLOR, 1, cGrow);
         ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
@@ -1497,5 +1515,5 @@
 
     DeleteObject (handle);
-    
+
     return himl;
 }
@@ -1503,5 +1521,5 @@
 
 /*************************************************************************
- * ImageList_Merge [COMCTL32.65] 
+ * ImageList_Merge [COMCTL32.65]
  *
  * Creates a new image list that contains a merged image from the specified
@@ -1523,5 +1541,5 @@
 HIMAGELIST WINAPI
 ImageList_Merge (HIMAGELIST himl1, INT i1, HIMAGELIST himl2, INT i2,
-		 INT dx, INT dy)
+                 INT dx, INT dy)
 {
     HIMAGELIST himlDst = NULL;
@@ -1532,5 +1550,5 @@
 
     if ((himl1 == NULL) || (himl2 == NULL))
-	return NULL;
+        return NULL;
 
     /* check indices */
@@ -1584,19 +1602,19 @@
         nX1 = i1 * himl1->cx;
         nX2 = i2 * himl2->cx;
-        
+
         /* copy image */
         SelectObject (hdcSrcImage, himl1->hbmImage);
         SelectObject (hdcDstImage, himlDst->hbmImage);
-        BitBlt (hdcDstImage, 0, 0, cxDst, cyDst, 
+        BitBlt (hdcDstImage, 0, 0, cxDst, cyDst,
                   hdcSrcImage, 0, 0, BLACKNESS);
-        BitBlt (hdcDstImage, xOff1, yOff1, himl1->cx, himl1->cy, 
+        BitBlt (hdcDstImage, xOff1, yOff1, himl1->cx, himl1->cy,
                   hdcSrcImage, nX1, 0, SRCCOPY);
 
         SelectObject (hdcSrcImage, himl2->hbmMask);
-        BitBlt (hdcDstImage, xOff2, yOff2, himl2->cx, himl2->cy, 
+        BitBlt (hdcDstImage, xOff2, yOff2, himl2->cx, himl2->cy,
                   hdcSrcImage, nX2, 0, SRCAND);
 
         SelectObject (hdcSrcImage, himl2->hbmImage);
-        BitBlt (hdcDstImage, xOff2, yOff2, himl2->cx, himl2->cy, 
+        BitBlt (hdcDstImage, xOff2, yOff2, himl2->cx, himl2->cy,
                   hdcSrcImage, nX2, 0, SRCPAINT);
 
@@ -1604,11 +1622,11 @@
         SelectObject (hdcSrcImage, himl1->hbmMask);
         SelectObject (hdcDstImage, himlDst->hbmMask);
-        BitBlt (hdcDstImage, 0, 0, cxDst, cyDst, 
+        BitBlt (hdcDstImage, 0, 0, cxDst, cyDst,
                   hdcSrcImage, 0, 0, WHITENESS);
-        BitBlt (hdcDstImage, xOff1, yOff1, himl1->cx, himl1->cy, 
+        BitBlt (hdcDstImage, xOff1, yOff1, himl1->cx, himl1->cy,
                   hdcSrcImage, nX1, 0, SRCCOPY);
 
         SelectObject (hdcSrcImage, himl2->hbmMask);
-        BitBlt (hdcDstImage, xOff2, yOff2, himl2->cx, himl2->cy, 
+        BitBlt (hdcDstImage, xOff2, yOff2, himl2->cx, himl2->cy,
                   hdcSrcImage, nX2, 0, SRCAND);
 
@@ -1616,5 +1634,5 @@
         DeleteDC (hdcDstImage);
     }
-   
+
     return himlDst;
 }
@@ -1711,5 +1729,5 @@
 //        TRACE(imagelist, " - Max. number of images: %d / %d (Old/New)\n",
 //                 himl->cMaxImage, himl->cCurImage + himl->cGrow - 1);
-        
+
         hbmNewImage =
             CreateBitmap (cxNew, himl->cy, 1, himl->uBitsPixel, NULL);
@@ -1726,5 +1744,5 @@
         if (i > 0) {
 //            TRACE (imagelist, "Pre image copy: Copy %d images\n", i);
-       
+
             SelectObject (hdcSrc, himl->hbmImage);
             SelectObject (hdcDst, hbmNewImage);
@@ -1777,5 +1795,5 @@
 
 /*************************************************************************
- * ImageList_Replace [COMCTL32.68] 
+ * ImageList_Replace [COMCTL32.68]
  *
  * Replaces an image in an image list with a new image.
@@ -1794,5 +1812,5 @@
 BOOL WINAPI
 ImageList_Replace (HIMAGELIST himl, INT i, HBITMAP hbmImage,
-		   HBITMAP hbmMask)
+                   HBITMAP hbmMask)
 {
     HDC hdcImageList, hdcImage;
@@ -1803,5 +1821,5 @@
         return FALSE;
     }
-    
+
     if ((i >= himl->cCurImage) || (i < 0)) {
 //        ERR (imagelist, "Invalid image index!\n");
@@ -1864,13 +1882,13 @@
 
     if (himl == NULL)
-	return -1;
+        return -1;
     if ((i >= himl->cCurImage) || (i < -1))
-	return -1;
+        return -1;
 
     GetIconInfo (hIcon, &ii);
 //    if (ii.hbmMask == 0)
-//	ERR (imagelist, "no mask!\n");
+//      ERR (imagelist, "no mask!\n");
 //    if (ii.hbmColor == 0)
-//	ERR (imagelist, "no color!\n");
+//      ERR (imagelist, "no color!\n");
     GetObjectA (ii.hbmMask, sizeof(BITMAP), (LPVOID)&bmp);
 
@@ -1888,10 +1906,10 @@
 //    TRACE (imagelist, "hdcImageList=0x%x!\n", hdcImageList);
 //    if (hdcImageList == 0)
-//	ERR (imagelist, "invalid hdcImageList!\n");
+//      ERR (imagelist, "invalid hdcImageList!\n");
 
     hdcImage = CreateCompatibleDC (0);
 //    TRACE (imagelist, "hdcImage=0x%x!\n", hdcImage);
 //    if (hdcImage == 0)
-//	ERR (imagelist, "invalid hdcImage!\n");
+//      ERR (imagelist, "invalid hdcImage!\n");
 
     hbmOldDst = SelectObject (hdcImageList, himl->hbmImage);
@@ -1913,11 +1931,11 @@
 
     if (hdcImageList)
-	DeleteDC (hdcImageList);
+        DeleteDC (hdcImageList);
     if (hdcImage)
-	DeleteDC (hdcImage);
+        DeleteDC (hdcImage);
     if (ii.hbmColor)
-	DeleteObject (ii.hbmColor);
+        DeleteObject (ii.hbmColor);
     if (ii.hbmMask)
-	DeleteObject (ii.hbmMask);
+        DeleteObject (ii.hbmMask);
 
     return nIndex;
@@ -1926,5 +1944,5 @@
 
 /*************************************************************************
- * ImageList_SetBkColor [COMCTL32.70] 
+ * ImageList_SetBkColor [COMCTL32.70]
  *
  * Sets the background color of an image list.
@@ -1945,5 +1963,5 @@
 
     if (himl == NULL)
-	return CLR_NONE;
+        return CLR_NONE;
 
     clrOldBk = himl->clrBk;
@@ -1974,5 +1992,5 @@
 BOOL WINAPI
 ImageList_SetDragCursorImage (HIMAGELIST himlDrag, INT iDrag,
-			      INT dxHotspot, INT dyHotspot)
+                              INT dxHotspot, INT dyHotspot)
 {
     HIMAGELIST himlTemp;
@@ -1981,11 +1999,11 @@
 
     if (himlInternalDrag == NULL)
-	return FALSE;
+        return FALSE;
 
 //    TRACE (imagelist, " dxH=%d dyH=%d nX=%d nY=%d\n",
-//	   dxHotspot, dyHotspot, nInternalDragHotspotX, nInternalDragHotspotY);
+//         dxHotspot, dyHotspot, nInternalDragHotspotX, nInternalDragHotspotY);
 
     himlTemp = ImageList_Merge (himlInternalDrag, 0, himlDrag, iDrag,
-				dxHotspot, dyHotspot);
+                                dxHotspot, dyHotspot);
 
     ImageList_Destroy (himlInternalDrag);
@@ -2000,5 +2018,5 @@
 
 /*************************************************************************
- * ImageList_SetFilter [COMCTL32.76] 
+ * ImageList_SetFilter [COMCTL32.76]
  *
  * Sets a filter (or does something completely different)!!???
@@ -2022,5 +2040,5 @@
 {
 //    FIXME (imagelist, "(%p 0x%x 0x%lx):empty stub!\n",
-//	   himl, i, dwFilter);
+//         himl, i, dwFilter);
 
     return FALSE;
@@ -2049,5 +2067,5 @@
 
     if (!himl)
-	return FALSE;
+        return FALSE;
 
     /* remove all images*/
@@ -2099,9 +2117,9 @@
 
     if (!himl)
-	return FALSE;
+        return FALSE;
     if (himl->cCurImage >= iImageCount)
-	return FALSE;
+        return FALSE;
     if (himl->cMaxImage > iImageCount)
-	return TRUE;
+        return TRUE;
 
     nNewCount = iImageCount + himl->cGrow;
@@ -2118,19 +2136,19 @@
         SelectObject (hdcBitmap, hbmNewBitmap);
 
-	/* copy images */
+        /* copy images */
         BitBlt (hdcBitmap, 0, 0, nCopyCount * himl->cx, himl->cy,
                   hdcImageList, 0, 0, SRCCOPY);
 
-	/* delete 'empty' image space */
-	SetBkColor (hdcBitmap, RGB(255, 255, 255));
-	SetTextColor (hdcBitmap, RGB(0, 0, 0));
-	PatBlt (hdcBitmap,  nCopyCount * himl->cx, 0, 
-		  (nNewCount - nCopyCount) * himl->cx, himl->cy, BLACKNESS);
-
-	DeleteObject (himl->hbmImage);
-	himl->hbmImage = hbmNewBitmap;
+        /* delete 'empty' image space */
+        SetBkColor (hdcBitmap, RGB(255, 255, 255));
+        SetTextColor (hdcBitmap, RGB(0, 0, 0));
+        PatBlt (hdcBitmap,  nCopyCount * himl->cx, 0,
+                  (nNewCount - nCopyCount) * himl->cx, himl->cy, BLACKNESS);
+
+        DeleteObject (himl->hbmImage);
+        himl->hbmImage = hbmNewBitmap;
     }
 //    else
-//	ERR (imagelist, "Could not create new image bitmap !\n");
+//      ERR (imagelist, "Could not create new image bitmap !\n");
 
     if (himl->hbmMask)
@@ -2143,13 +2161,13 @@
             SelectObject (hdcBitmap, hbmNewBitmap);
 
-	    /* copy images */
+            /* copy images */
             BitBlt (hdcBitmap, 0, 0, nCopyCount * himl->cx, himl->cy,
                       hdcImageList, 0, 0, SRCCOPY);
 
-	    /* delete 'empty' image space */
-	    SetBkColor (hdcBitmap, RGB(255, 255, 255));
-	    SetTextColor (hdcBitmap, RGB(0, 0, 0));
-            PatBlt (hdcBitmap,  nCopyCount * himl->cx, 0, 
-		      (nNewCount - nCopyCount) * himl->cx, himl->cy, BLACKNESS);
+            /* delete 'empty' image space */
+            SetBkColor (hdcBitmap, RGB(255, 255, 255));
+            SetTextColor (hdcBitmap, RGB(0, 0, 0));
+            PatBlt (hdcBitmap,  nCopyCount * himl->cx, 0,
+                      (nNewCount - nCopyCount) * himl->cx, himl->cy, BLACKNESS);
 
             DeleteObject (himl->hbmMask);
@@ -2191,10 +2209,10 @@
 {
     if (!himl)
-	return FALSE;
+        return FALSE;
     if ((iOverlay < 1) || (iOverlay > MAX_OVERLAYIMAGE))
-	return FALSE;
+        return FALSE;
     if ((iImage < 0) || (iImage > himl->cCurImage))
-	return FALSE;
-    
+        return FALSE;
+
     himl->nOvlIdx[iOverlay - 1] = iImage;
     return TRUE;
@@ -2227,5 +2245,5 @@
 //{
 //    if (!himl)
-//	return FALSE;
+//      return FALSE;
 //
 //    FIXME (imagelist, "empty stub!\n");
Index: trunk/src/comctl32/ipaddress.c
===================================================================
--- trunk/src/comctl32/ipaddress.c	(revision 293)
+++ trunk/src/comctl32/ipaddress.c	(revision 295)
@@ -1,6 +1,8 @@
-/* $Id: ipaddress.c,v 1.5 1999-06-25 15:49:01 achimha Exp $ */
+/* $Id: ipaddress.c,v 1.6 1999-07-12 15:58:47 cbratschi Exp $ */
 /*
  * IP Address control
  *
+ * Copyright 1999 Chris Morgan<cmorgan@wpi.edu> and
+ *                James Abbatiello<abbeyj@wpi.edu>
  * Copyright 1998, 1999 Eric Kohl
  * Copyright 1998 Alex Priem <alexp@sci.kun.nl>
@@ -8,17 +10,16 @@
  *
  * NOTES
-
  *
  * TODO:
  *    -Check ranges when changing field-focus.
- * 	  -Check all notifications/behavior.
+ *        -Check all notifications/behavior.
  *    -Optimization: include lpipsi in IPADDRESS_INFO.
- *	  -CurrentFocus: field that has focus at moment of processing.
- *	  -connect Rect32 rcClient.
- *	  -handle right and left arrows correctly. Boring.
- *	  -split GotoNextField in CheckField and GotoNextField.
- *	  -check ipaddress.cpp for missing features.
+ *        -CurrentFocus: field that has focus at moment of processing.
+ *        -connect Rect32 rcClient.
+ *        -handle right and left arrows correctly. Boring.
+ *        -split GotoNextField in CheckField and GotoNextField.
+ *        -check ipaddress.cpp for missing features.
  *    -refresh: draw '.' instead of setpixel.
- *	  -handle VK_ESCAPE.
+ *        -handle VK_ESCAPE.
  */
 
@@ -36,7 +37,7 @@
 
 
-static BOOL 
+static BOOL
 IPADDRESS_SendNotify (HWND hwnd, UINT command);
-static BOOL 
+static BOOL
 IPADDRESS_SendIPAddressNotify (HWND hwnd, UINT field, BYTE newValue);
 
@@ -55,31 +56,26 @@
 IPADDRESS_Refresh (HWND hwnd, HDC hdc)
 {
-	RECT rcClient;
-	HBRUSH hbr;
-	COLORREF clr=GetSysColor (COLOR_3DDKSHADOW);
+        RECT rcClient;
+        HBRUSH hbr;
+        COLORREF clr=GetSysColor (COLOR_3DDKSHADOW);
     int i,x,fieldsize;
 
     GetClientRect (hwnd, &rcClient);
-	hbr =  CreateSolidBrush (RGB(255,255,255));
+        hbr =  CreateSolidBrush (RGB(255,255,255));
     DrawEdge (hdc, &rcClient, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
-	FillRect (hdc, &rcClient, hbr);
+        FillRect (hdc, &rcClient, hbr);
     DeleteObject (hbr);
 
-	x=rcClient.left;
-	fieldsize=(rcClient.right-rcClient.left) /4;
-
-	for (i=0; i<3; i++) {		/* Should draw text "." here */
-		x+=fieldsize;
-		SetPixel (hdc, x,   13, clr);
-		SetPixel (hdc, x,   14, clr);
-		SetPixel (hdc, x+1, 13, clr);
-		SetPixel (hdc, x+1, 14, clr);
-
-	}
-
-}
-
-
-
+        x=rcClient.left;
+        fieldsize=(rcClient.right-rcClient.left) /4;
+
+        for (i=0; i<3; i++) {           /* Should draw text "." here */
+                x+=fieldsize;
+                SetPixel (hdc, x,   13, clr);
+                SetPixel (hdc, x,   14, clr);
+                SetPixel (hdc, x+1, 13, clr);
+                SetPixel (hdc, x+1, 14, clr);
+        }
+}
 
 
@@ -88,8 +84,8 @@
 {
     IPADDRESS_INFO *infoPtr;
-	RECT rcClient, edit;
-	int i,fieldsize;
-	LPIP_SUBCLASS_INFO lpipsi;
-	
+        RECT rcClient, edit;
+        int i,fieldsize;
+        LPIP_SUBCLASS_INFO lpipsi;
+
 
     infoPtr = (IPADDRESS_INFO *)COMCTL32_Alloc (sizeof(IPADDRESS_INFO));
@@ -98,39 +94,37 @@
     GetClientRect (hwnd, &rcClient);
 
-	fieldsize=(rcClient.right-rcClient.left) /4;
-
-	edit.top   =rcClient.top+2;
-	edit.bottom=rcClient.bottom-2;
-
-	lpipsi=(LPIP_SUBCLASS_INFO)
-			GetPropA ((HWND)hwnd, IP_SUBCLASS_PROP);
-	if (lpipsi == NULL)  {
-		lpipsi= (LPIP_SUBCLASS_INFO) COMCTL32_Alloc (sizeof(IP_SUBCLASS_INFO));
-		lpipsi->hwnd = hwnd;
-		lpipsi->uRefCount++;
-		SetPropA ((HWND)hwnd, IP_SUBCLASS_PROP,
-					(HANDLE)lpipsi);
-/*		infoPtr->lpipsi= lpipsi; */
-//	} else 
-	}
-//		WARN (ipaddress,"IP-create called twice\n");
-	
-	for (i=0; i<=3; i++) {
-		infoPtr->LowerLimit[i]=0;
-		infoPtr->UpperLimit[i]=255;
-		edit.left=rcClient.left+i*fieldsize+3;
-		edit.right=rcClient.left+(i+1)*fieldsize-2;
-		lpipsi->hwndIP[i]= CreateWindowA ("edit", NULL, 
-				WS_CHILD | WS_VISIBLE | ES_LEFT,
-				edit.left, edit.top, edit.right-edit.left, edit.bottom-edit.top,
-				hwnd, (HMENU) 1, GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
-		lpipsi->wpOrigProc[i]= (WNDPROC)
-					SetWindowLongA (lpipsi->hwndIP[i],GWL_WNDPROC, (LONG)
-					IPADDRESS_SubclassProc);
-		SetPropA ((HWND)lpipsi->hwndIP[i], IP_SUBCLASS_PROP,
-					(HANDLE)lpipsi);
-	}
-
-	lpipsi->infoPtr= infoPtr;
+        fieldsize=(rcClient.right-rcClient.left) /4;
+
+        edit.top   =rcClient.top+2;
+        edit.bottom=rcClient.bottom-2;
+
+        lpipsi=(LPIP_SUBCLASS_INFO) GetPropA ((HWND)hwnd, IP_SUBCLASS_PROP);
+        if (lpipsi == NULL)  {
+                lpipsi= (LPIP_SUBCLASS_INFO) COMCTL32_Alloc (sizeof(IP_SUBCLASS_INFO));
+                lpipsi->hwnd = hwnd;
+                lpipsi->uRefCount++;
+                SetPropA ((HWND)hwnd, IP_SUBCLASS_PROP, (HANDLE)lpipsi);
+/*              infoPtr->lpipsi= lpipsi; */
+//      } else
+        }
+//              WARN (ipaddress,"IP-create called twice\n");
+
+        for (i=0; i<=3; i++)
+        {
+                infoPtr->LowerLimit[i]=0;
+                infoPtr->UpperLimit[i]=255;
+                edit.left=rcClient.left+i*fieldsize+6;
+                edit.right=rcClient.left+(i+1)*fieldsize-2;
+                lpipsi->hwndIP[i]= CreateWindowA ("edit", NULL,
+                                WS_CHILD | WS_VISIBLE | ES_CENTER,
+                                edit.left, edit.top, edit.right-edit.left, edit.bottom-edit.top,
+                                hwnd, (HMENU) 1, GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
+                lpipsi->wpOrigProc[i]= (WNDPROC)
+                                        SetWindowLongA (lpipsi->hwndIP[i],GWL_WNDPROC, (LONG)
+                                        IPADDRESS_SubclassProc);
+                SetPropA ((HWND)lpipsi->hwndIP[i], IP_SUBCLASS_PROP, (HANDLE)lpipsi);
+        }
+
+        lpipsi->infoPtr= infoPtr;
 
     return 0;
@@ -141,13 +135,13 @@
 IPADDRESS_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
 {
-	int i;
+        int i;
     IPADDRESS_INFO *infoPtr = IPADDRESS_GetInfoPtr (hwnd);
-	LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO)
+        LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO)
             GetPropA ((HWND)hwnd, IP_SUBCLASS_PROP);
 
-	for (i=0; i<=3; i++) {
-		SetWindowLongA ((HWND)lpipsi->hwndIP[i], GWL_WNDPROC,
+        for (i=0; i<=3; i++) {
+                SetWindowLongA ((HWND)lpipsi->hwndIP[i], GWL_WNDPROC,
                   (LONG)lpipsi->wpOrigProc[i]);
-	}
+        }
 
     COMCTL32_Free (infoPtr);
@@ -161,5 +155,5 @@
     HDC hdc;
 
-//	TRACE (ipaddress,"\n");
+//      TRACE (ipaddress,"\n");
     hdc = GetDC (hwnd);
     IPADDRESS_Refresh (hwnd, hdc);
@@ -167,5 +161,5 @@
 
     IPADDRESS_SendIPAddressNotify (hwnd, 0, 0);  /* FIXME: should use -1 */
-    IPADDRESS_SendNotify (hwnd, EN_KILLFOCUS);       
+    IPADDRESS_SendNotify (hwnd, EN_KILLFOCUS);
     InvalidateRect (hwnd, NULL, TRUE);
 
@@ -183,5 +177,5 @@
     IPADDRESS_Refresh (hwnd, hdc);
     if(!wParam)
-	EndPaint (hwnd, &ps);
+        EndPaint (hwnd, &ps);
     return 0;
 }
@@ -193,5 +187,5 @@
     HDC hdc;
 
-//	TRACE (ipaddress,"\n");
+//      TRACE (ipaddress,"\n");
 
     hdc = GetDC (hwnd);
@@ -207,5 +201,5 @@
 {
     /* IPADDRESS_INFO *infoPtr = IPADDRESS_GetInfoPtr (hwnd); */
-//	TRACE (ipaddress,"\n");
+//      TRACE (ipaddress,"\n");
     return 0;
 }
@@ -225,5 +219,5 @@
 IPADDRESS_SendIPAddressNotify (HWND hwnd, UINT field, BYTE newValue)
 {
-	NMIPADDRESS nmip;
+        NMIPADDRESS nmip;
 
 //    TRACE (ipaddress, "%x %x\n",field,newValue);
@@ -232,6 +226,6 @@
     nmip.hdr.code     = IPN_FIELDCHANGED;
 
-	nmip.iField=field;
-	nmip.iValue=newValue;
+        nmip.iField=field;
+        nmip.iValue=newValue;
 
     return (BOOL)SendMessageA (GetParent (hwnd), WM_NOTIFY,
@@ -245,21 +239,21 @@
 IPADDRESS_ClearAddress (HWND hwnd, WPARAM wParam, LPARAM lParam)
 {
-	int i;
-	HDC hdc;
-	char buf[1];
-	LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO)
+        int i;
+        HDC hdc;
+        char buf[1];
+        LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO)
             GetPropA ((HWND)hwnd,IP_SUBCLASS_PROP);
 
-//	TRACE (ipaddress,"\n");
-
-	buf[0]=0;
-	for (i=0; i<=3; i++) 
-		SetWindowTextA (lpipsi->hwndIP[i],buf);
-	
+//      TRACE (ipaddress,"\n");
+
+        buf[0]=0;
+        for (i=0; i<=3; i++)
+                SetWindowTextA (lpipsi->hwndIP[i],buf);
+
     hdc = GetDC (hwnd);
     IPADDRESS_Refresh (hwnd, hdc);
     ReleaseDC (hwnd, hdc);
-	
-	return 0;
+
+        return 0;
 }
 
@@ -275,8 +269,8 @@
 
  for (i=0; i<=3; i++) {
-		GetWindowTextA (lpipsi->hwndIP[i],buf,5);
-	if (buf[0])
-	    return 0;
-	}
+                GetWindowTextA (lpipsi->hwndIP[i],buf,5);
+        if (buf[0])
+            return 0;
+        }
 
  return 1;
@@ -298,16 +292,16 @@
  ip_addr=0;
  for (i=0; i<=3; i++) {
-		GetWindowTextA (lpipsi->hwndIP[i],field,4);
-		ip_addr*=256;
-		if (field[0]) {
-			field[3]=0;
-			fieldvalue=atoi(field);
-			if (fieldvalue<infoPtr->LowerLimit[i]) 
-				fieldvalue=infoPtr->LowerLimit[i];
-			if (fieldvalue>infoPtr->UpperLimit[i]) 
-				fieldvalue=infoPtr->UpperLimit[i];
-			ip_addr+=fieldvalue;
-			valid++;
-		}
+                GetWindowTextA (lpipsi->hwndIP[i],field,4);
+                ip_addr*=256;
+                if (field[0]) {
+                        field[3]=0;
+                        fieldvalue=atoi(field);
+                        if (fieldvalue<infoPtr->LowerLimit[i])
+                                fieldvalue=infoPtr->LowerLimit[i];
+                        if (fieldvalue>infoPtr->UpperLimit[i])
+                                fieldvalue=infoPtr->UpperLimit[i];
+                        ip_addr+=fieldvalue;
+                        valid++;
+                }
  }
 
@@ -322,14 +316,14 @@
 {
     IPADDRESS_INFO *infoPtr = IPADDRESS_GetInfoPtr (hwnd);
-	INT index;
-	
-// 	TRACE (ipaddress,"\n");
-
-	index=(INT) wParam;
-	if ((index<0) || (index>3)) return 0;
-
-	infoPtr->LowerLimit[index]=lParam & 0xff;
-	infoPtr->UpperLimit[index]=(lParam >>8)  & 0xff;
-	return 1;
+        INT index;
+
+//      TRACE (ipaddress,"\n");
+
+        index=(INT) wParam;
+        if ((index<0) || (index>3)) return 0;
+
+        infoPtr->LowerLimit[index]=lParam & 0xff;
+        infoPtr->UpperLimit[index]=(lParam >>8)  & 0xff;
+        return 1;
 }
 
@@ -338,25 +332,25 @@
 {
     IPADDRESS_INFO *infoPtr = IPADDRESS_GetInfoPtr (hwnd);
-	HDC hdc;
-	LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO)
+        HDC hdc;
+        LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO)
             GetPropA ((HWND)hwnd, IP_SUBCLASS_PROP);
-	int i,ip_address,value;
+        int i,ip_address,value;
     char buf[20];
 
-// 	TRACE (ipaddress,"\n");
-	ip_address=(DWORD) lParam;
-
-	for (i=3; i>=0; i--) {
-		value=ip_address & 0xff;
-		if ((value>=infoPtr->LowerLimit[i]) && (value<=infoPtr->UpperLimit[i])) 
-			{
-			 sprintf (buf,"%d",value);
-			 SetWindowTextA (lpipsi->hwndIP[i],buf);
-			 IPADDRESS_SendNotify (hwnd, EN_CHANGE);
-		}
-		ip_address/=256;
-	}
-
-    hdc = GetDC (hwnd);		/* & send notifications */
+//      TRACE (ipaddress,"\n");
+        ip_address=(DWORD) lParam;
+
+        for (i=3; i>=0; i--) {
+                value=ip_address & 0xff;
+                if ((value>=infoPtr->LowerLimit[i]) && (value<=infoPtr->UpperLimit[i]))
+                        {
+                         sprintf (buf,"%d",value);
+                         SetWindowTextA (lpipsi->hwndIP[i],buf);
+                         IPADDRESS_SendNotify (hwnd, EN_CHANGE);
+                }
+                ip_address/=256;
+        }
+
+    hdc = GetDC (hwnd);         /* & send notifications */
     IPADDRESS_Refresh (hwnd, hdc);
     ReleaseDC (hwnd, hdc);
@@ -372,14 +366,14 @@
 {
     /* IPADDRESS_INFO *infoPtr = IPADDRESS_GetInfoPtr (hwnd); */
-	LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO)
-            GetPropA ((HWND)hwnd, IP_SUBCLASS_PROP);
-	INT index;
-
-	index=(INT) wParam;
-// 	TRACE (ipaddress," %d\n", index);
-	if ((index<0) || (index>3)) return 0;
-	
-	SetFocus (lpipsi->hwndIP[index]);
-	
+        LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO) GetPropA ((HWND)hwnd,
+                                               IP_SUBCLASS_PROP);
+        INT index;
+
+        index=(INT) wParam;
+//      TRACE (ipaddress," %d\n", index);
+        if ((index<0) || (index>3)) return 0;
+
+        SetFocus (lpipsi->hwndIP[index]);
+
     return 1;
 }
@@ -391,50 +385,96 @@
 //    TRACE (ipaddress, "\n");
 
-	SetFocus (hwnd);
-	IPADDRESS_SendNotify (hwnd, EN_SETFOCUS);
-	IPADDRESS_SetFocusToField (hwnd, 0, 0);
-
- 	return TRUE;
-}
-
-
-
-/* tab/shift-tab: IPN_FIELDCHANGED, lose focus.
-   dot, space,right arrow:	set focus to next child edit.
-   numerics (0..9), control characters: forward to default edit control 
-   other characters: dropped
-*/
-   
-
-
-
-static int
+        SetFocus (hwnd);
+        IPADDRESS_SendNotify (hwnd, EN_SETFOCUS);
+        IPADDRESS_SetFocusToField (hwnd, 0, 0);
+
+        return TRUE;
+}
+
+static INT
+IPADDRESS_CheckField (LPIP_SUBCLASS_INFO lpipsi, int currentfield)
+{
+  int newField,fieldvalue;
+  char field[20];
+  IPADDRESS_INFO *infoPtr=lpipsi->infoPtr;
+
+  if(currentfield >= 0 && currentfield < 4)
+  {
+//    TRACE("\n");
+    GetWindowTextA (lpipsi->hwndIP[currentfield],field,4);
+    if (field[0])
+    {
+      field[3]=0;
+      newField=-1;
+      fieldvalue=atoi(field);
+
+      if (fieldvalue < infoPtr->LowerLimit[currentfield])
+        newField=infoPtr->LowerLimit[currentfield];
+
+      if (fieldvalue > infoPtr->UpperLimit[currentfield])
+        newField=infoPtr->UpperLimit[currentfield];
+
+      if (newField >= 0)
+      {
+        sprintf (field,"%d",newField);
+        SetWindowTextA (lpipsi->hwndIP[currentfield], field);
+        return TRUE;
+      }
+    }
+  }
+  return FALSE;
+}
+
+
+static INT
 IPADDRESS_GotoNextField (LPIP_SUBCLASS_INFO lpipsi, int currentfield)
 {
- int newField,fieldvalue;
- char field[20];
- IPADDRESS_INFO *infoPtr=lpipsi->infoPtr;
-
-// TRACE (ipaddress,"\n");
- GetWindowTextA (lpipsi->hwndIP[currentfield],field,4);
- if (field[0]) {
-	field[3]=0;	
-	newField=-1;
-	fieldvalue=atoi(field);
-	if (fieldvalue<infoPtr->LowerLimit[currentfield]) 
-		newField=infoPtr->LowerLimit[currentfield];
-	if (fieldvalue>infoPtr->UpperLimit[currentfield])
-		newField=infoPtr->UpperLimit[currentfield];
-	if (newField>=0) {
-		sprintf (field,"%d",newField);
-		SetWindowTextA (lpipsi->hwndIP[currentfield], field);
-		return 1;
-	}
- }
-
- if (currentfield<3) 
-		SetFocus (lpipsi->hwndIP[currentfield+1]);
- return 0;
-}
+  if(currentfield >= -1 && currentfield < 4)
+  {
+    IPADDRESS_CheckField(lpipsi, currentfield); /* check the fields value */
+
+    if(currentfield < 3)
+    {
+      SetFocus (lpipsi->hwndIP[currentfield+1]);
+      return TRUE;
+    }
+  }
+  return FALSE;
+}
+
+
+/* period: move and select the text in the next field to the right if */
+/*         the current field is not empty(l!=0), we are not in the */
+/*         left most position, and nothing is selected(startsel==endsel) */
+
+/* spacebar: same behavior as period */
+
+/* alpha characters: completely ignored */
+
+/* digits: accepted when field text length < 2 ignored otherwise. */
+/*         when 3 numbers have been entered into the field the value */
+/*         of the field is checked, if the field value exceeds the */
+/*         maximum value and is changed the field remains the current */
+/*         field, otherwise focus moves to the field to the right */
+
+/* tab: change focus from the current ipaddress control to the next */
+/*      control in the tab order */
+
+/* right arrow: move to the field on the right to the left most */
+/*              position in that field if no text is selected, */
+/*              we are in the right most position in the field, */
+/*              we are not in the right most field */
+
+/* left arrow: move to the field on the left to the right most */
+/*             position in that field if no text is selected, */
+/*             we are in the left most position in the current field */
+/*             and we are not in the left most field */
+
+/* backspace: delete the character to the left of the cursor position, */
+/*            if none are present move to the field on the left if */
+/*            we are not in the left most field and delete the right */
+/*            most digit in that field while keeping the cursor */
+/*            on the right side of the field */
+
 
 
@@ -442,58 +482,117 @@
 IPADDRESS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
- int i,l,index;
- IPADDRESS_INFO *infoPtr;
- LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO)
-            GetPropA ((HWND)hwnd,IP_SUBCLASS_PROP); 
-
- infoPtr = lpipsi->infoPtr;
- index=0;             /* FIXME */
- for (i=0; i<=3; i++) 
-		if (lpipsi->hwndIP[i]==hwnd) index=i;
-
- switch (uMsg) {
-	case WM_CHAR: break;
-	case WM_KEYDOWN: {
-			char c=(char) wParam;
-			if (c==VK_TAB) {
- 				HWND pwnd;
-				int shift;
-				shift = GetKeyState(VK_SHIFT) & 0x8000;
-				if (shift)
-					pwnd=GetNextDlgTabItem (GetParent (hwnd), 0, TRUE);
-				else
-					pwnd=GetNextDlgTabItem (GetParent (hwnd), 0, FALSE);
-				if (pwnd) SetFocus (pwnd);
-				break;
-			}
-			
-			if ((c==' ') || (c=='.') || (c==VK_RIGHT)) {
-				IPADDRESS_GotoNextField (lpipsi,index);
-				wParam=0;
-				lParam=0;
-				break;
-			}
-			if (c==VK_LEFT) {
-				
-			}
-			if (c==VK_RETURN) {
-			}
-			if (((c>='0') && (c<='9')) || (iscntrl(c))) {
-				l=GetWindowTextLengthA (lpipsi->hwndIP[index]);
-				if (l==3) 
-					if (IPADDRESS_GotoNextField (lpipsi,index)) {
-						wParam=0;
-						lParam=0;
-					}
-				break;
-			}
-	
-			wParam=0;
-			lParam=0;
-			break;
-		}
- }
-
- return CallWindowProcA (lpipsi->wpOrigProc[index], hwnd, uMsg, wParam, lParam);
+  IPADDRESS_INFO *infoPtr;
+  LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO) GetPropA ((HWND)hwnd,IP_SUBCLASS_PROP);
+  CHAR c = (CHAR)wParam;
+  INT i, l, index, startsel, endsel;
+
+  infoPtr = lpipsi->infoPtr;
+  index=0;             /* FIXME */
+  for (i=0; i<=3; i++)
+    if (lpipsi->hwndIP[i]==hwnd) index=i;
+
+  switch (uMsg) {
+  case WM_CHAR:
+    if(isdigit(c)) /* process all digits */
+    {
+      int return_val;
+      SendMessageA(lpipsi->hwndIP[index], EM_GETSEL, (WPARAM)&startsel, (LPARAM)&endsel);
+      l = GetWindowTextLengthA (lpipsi->hwndIP[index]);
+      if(l==2 && startsel==endsel) /* field is full after this key is processed */
+      {
+        /* process the digit press before we check the field */
+        return_val = CallWindowProcA (lpipsi->wpOrigProc[index], hwnd, uMsg, wParam, lParam);
+
+        /* if the field value was changed stay at the current field */
+        if(!IPADDRESS_CheckField(lpipsi, index))
+          IPADDRESS_GotoNextField (lpipsi,index);
+
+        return return_val;
+      }
+
+      if(l > 2) /* field is full, stop key messages */
+      {
+        lParam = 0;
+        wParam = 0;
+      }
+      break;
+    }
+
+    if(c == '.') /* VK_PERIOD */
+    {
+      l = GetWindowTextLengthA(lpipsi->hwndIP[index]);
+      SendMessageA(lpipsi->hwndIP[index], EM_GETSEL, (WPARAM)&startsel, (LPARAM)&endsel);
+      if(l != 0 && startsel==endsel && startsel != 0)
+      {
+        IPADDRESS_GotoNextField(lpipsi, index);
+        SendMessageA(lpipsi->hwndIP[index+1], EM_SETSEL, (WPARAM)0, (LPARAM)3);
+      }
+    }
+
+    /* stop all other characters */
+    wParam = 0;
+    lParam = 0;
+    break;
+
+  case WM_KEYDOWN:
+    if(c == VK_SPACE)
+    {
+      l = GetWindowTextLengthA(lpipsi->hwndIP[index]);
+      SendMessageA(lpipsi->hwndIP[index], EM_GETSEL, (WPARAM)&startsel, (LPARAM)&endsel);
+      if(l != 0 && startsel==endsel && startsel != 0)
+      {
+        IPADDRESS_GotoNextField(lpipsi, index);
+        SendMessageA(lpipsi->hwndIP[index+1], EM_SETSEL, (WPARAM)0, (LPARAM)3);
+      }
+    }
+
+    if(c == VK_RIGHT)
+    {
+      SendMessageA(lpipsi->hwndIP[index], EM_GETSEL, (WPARAM)&startsel, (LPARAM)&endsel);
+      l = GetWindowTextLengthA (lpipsi->hwndIP[index]);
+
+      if(startsel==endsel && startsel==l)
+      {
+        IPADDRESS_GotoNextField(lpipsi, index);
+        SendMessageA(lpipsi->hwndIP[index+1], EM_SETSEL, (WPARAM)0,(LPARAM)0);
+      }
+    }
+
+    if(c == VK_LEFT)
+    {
+      SendMessageA(lpipsi->hwndIP[index], EM_GETSEL, (WPARAM)&startsel, (LPARAM)&endsel);
+      if(startsel==0 && startsel==endsel && index > 0)
+      {
+        IPADDRESS_GotoNextField(lpipsi, index - 2);
+        l = GetWindowTextLengthA(lpipsi->hwndIP[index-1]);
+        SendMessageA(lpipsi->hwndIP[index-1], EM_SETSEL, (WPARAM)l,(LPARAM)l);
+      }
+    }
+
+    if(c == VK_BACK) /* VK_BACKSPACE */
+    {
+      CHAR buf[4];
+
+      SendMessageA(lpipsi->hwndIP[index], EM_GETSEL, (WPARAM)&startsel, (LPARAM)&endsel);
+      l = GetWindowTextLengthA (lpipsi->hwndIP[index]);
+      if(startsel==endsel && startsel==0 && index > 0)
+      {
+        l = GetWindowTextLengthA(lpipsi->hwndIP[index-1]);
+        if(l!=0)
+        {
+          GetWindowTextA (lpipsi->hwndIP[index-1],buf,4);
+          buf[l-1] = '\0';
+          SetWindowTextA(lpipsi->hwndIP[index-1], buf);
+          SendMessageA(lpipsi->hwndIP[index-1], EM_SETSEL, (WPARAM)l,(LPARAM)l);
+        }
+        IPADDRESS_GotoNextField(lpipsi, index - 2);
+      }
+    }
+    break;
+
+  default:
+    break;
+  }
+  return CallWindowProcA (lpipsi->wpOrigProc[index], hwnd, uMsg, wParam, lParam);
 }
 
@@ -503,51 +602,51 @@
     switch (uMsg)
     {
-	case IPM_CLEARADDRESS:
-		return IPADDRESS_ClearAddress (hwnd, wParam, lParam);
-
-	case IPM_SETADDRESS:
-	    return IPADDRESS_SetAddress (hwnd, wParam, lParam);
-
-	case IPM_GETADDRESS:
-	    return IPADDRESS_GetAddress (hwnd, wParam, lParam);
-
-	case IPM_SETRANGE:
-	    return IPADDRESS_SetRange (hwnd, wParam, lParam);
-
-	case IPM_SETFOCUS:
-	    return IPADDRESS_SetFocusToField (hwnd, wParam, lParam);
-
-	case IPM_ISBLANK:
-		return IPADDRESS_IsBlank (hwnd, wParam, lParam);
-
-	case WM_CREATE:
-	    return IPADDRESS_Create (hwnd, wParam, lParam);
-
-	case WM_DESTROY:
-	    return IPADDRESS_Destroy (hwnd, wParam, lParam);
-
-	case WM_GETDLGCODE:
-	    return DLGC_WANTARROWS | DLGC_WANTCHARS;
-
-	case WM_KILLFOCUS:
-	    return IPADDRESS_KillFocus (hwnd, wParam, lParam);
-
-	case WM_LBUTTONDOWN:
+        case IPM_CLEARADDRESS:
+                return IPADDRESS_ClearAddress (hwnd, wParam, lParam);
+
+        case IPM_SETADDRESS:
+            return IPADDRESS_SetAddress (hwnd, wParam, lParam);
+
+        case IPM_GETADDRESS:
+            return IPADDRESS_GetAddress (hwnd, wParam, lParam);
+
+        case IPM_SETRANGE:
+            return IPADDRESS_SetRange (hwnd, wParam, lParam);
+
+        case IPM_SETFOCUS:
+            return IPADDRESS_SetFocusToField (hwnd, wParam, lParam);
+
+        case IPM_ISBLANK:
+                return IPADDRESS_IsBlank (hwnd, wParam, lParam);
+
+        case WM_CREATE:
+            return IPADDRESS_Create (hwnd, wParam, lParam);
+
+        case WM_DESTROY:
+            return IPADDRESS_Destroy (hwnd, wParam, lParam);
+
+        case WM_GETDLGCODE:
+            return DLGC_WANTARROWS | DLGC_WANTCHARS;
+
+        case WM_KILLFOCUS:
+            return IPADDRESS_KillFocus (hwnd, wParam, lParam);
+
+        case WM_LBUTTONDOWN:
         return IPADDRESS_LButtonDown (hwnd, wParam, lParam);
 
-	case WM_PAINT:
-	    return IPADDRESS_Paint (hwnd, wParam);
-
-	case WM_SETFOCUS:
-	    return IPADDRESS_SetFocus (hwnd, wParam, lParam);
-
-	case WM_SIZE:
-	    return IPADDRESS_Size (hwnd, wParam, lParam);
-
-	default:
-//	    if (uMsg >= WM_USER)
-//		ERR (ipaddress, "unknown msg %04x wp=%08x lp=%08lx\n",
-//		     uMsg, wParam, lParam);
-	    return DefWindowProcA (hwnd, uMsg, wParam, lParam);
+        case WM_PAINT:
+            return IPADDRESS_Paint (hwnd, wParam);
+
+        case WM_SETFOCUS:
+            return IPADDRESS_SetFocus (hwnd, wParam, lParam);
+
+        case WM_SIZE:
+            return IPADDRESS_Size (hwnd, wParam, lParam);
+
+        default:
+//          if (uMsg >= WM_USER)
+//              ERR (ipaddress, "unknown msg %04x wp=%08x lp=%08lx\n",
+//                   uMsg, wParam, lParam);
+            return DefWindowProcA (hwnd, uMsg, wParam, lParam);
     }
     return 0;
@@ -570,5 +669,5 @@
     wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
     wndClass.lpszClassName = WC_IPADDRESSA;
- 
+
     RegisterClassA (&wndClass);
 }
Index: trunk/src/comctl32/listview.c
===================================================================
--- trunk/src/comctl32/listview.c	(revision 293)
+++ trunk/src/comctl32/listview.c	(revision 295)
@@ -3392,5 +3392,6 @@
               if (dispInfo.item.mask & LVIF_DI_SETITEM)
               {
-                Str_SetPtrA(&lpItem->pszText, dispInfo.item.pszText);
+                if (lpSubItem)
+                   Str_SetPtrA(&lpSubItem->pszText, dispInfo.item.pszText);
               }
               lpLVItem->pszText = dispInfo.item.pszText;
@@ -3398,5 +3399,5 @@
             else if (lpLVItem->mask & LVIF_TEXT)
             {
-              lpLVItem->pszText = lpItem->pszText;
+              lpLVItem->pszText = lpSubItem->pszText;
             }
           }
@@ -3989,5 +3990,5 @@
         lvFindInfo.vkDirection = VK_UP;
         ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
-        while ((nItem = LISTVIEW_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
+        while ((nItem = ListView_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
         {
           if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
@@ -4012,5 +4013,5 @@
         lvFindInfo.vkDirection = VK_DOWN;
         ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
-        while ((nItem = LISTVIEW_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
+        while ((nItem = ListView_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
         {
           if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
@@ -4036,5 +4037,5 @@
         lvFindInfo.vkDirection = VK_LEFT;
         ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
-        while ((nItem = LISTVIEW_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
+        while ((nItem = ListView_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
         {
           if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
@@ -4060,5 +4061,5 @@
         lvFindInfo.vkDirection = VK_RIGHT;
         ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
-        while ((nItem = LISTVIEW_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
+        while ((nItem = ListView_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
         {
           if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
@@ -4667,5 +4668,5 @@
   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
   BOOL bResult = FALSE;
-  HDITEMA hdi;
+  HDITEMA hdi, hdiget;
 
   if ((lpColumn != NULL) && (nColumn >= 0) &&
@@ -4679,4 +4680,10 @@
       /* format member is valid */
       hdi.mask |= HDI_FORMAT;
+
+      /* get current format first */
+      hdiget.mask = HDI_FORMAT;
+      if (Header_GetItemA(infoPtr->hwndHeader, nColumn, &hdiget))
+              /* preserve HDF_STRING if present */
+              hdi.fmt = hdiget.fmt & HDF_STRING;
 
       /* set text alignment (leftmost column must be left-aligned) */
@@ -5244,5 +5251,4 @@
 
   /* create header */
-
   infoPtr->hwndHeader = CreateWindowA(WC_HEADERA, (LPCSTR)NULL,
                                       WS_CHILD | HDS_HORZ | HDS_BUTTONS,
@@ -5623,17 +5629,17 @@
 
   case VK_LEFT:
-    nItem = LISTVIEW_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_TOLEFT);
+    nItem = ListView_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_TOLEFT);
     break;
 
   case VK_UP:
-    nItem = LISTVIEW_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_ABOVE);
+    nItem = ListView_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_ABOVE);
     break;
 
   case VK_RIGHT:
-    nItem = LISTVIEW_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_TORIGHT);
+    nItem = ListView_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_TORIGHT);
     break;
 
   case VK_DOWN:
-    nItem = LISTVIEW_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_BELOW);
+    nItem = ListView_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_BELOW);
     break;
 
Index: trunk/src/comctl32/propsheet.c
===================================================================
--- trunk/src/comctl32/propsheet.c	(revision 293)
+++ trunk/src/comctl32/propsheet.c	(revision 295)
@@ -1,3 +1,3 @@
-/* $Id: propsheet.c,v 1.5 1999-07-04 21:05:59 cbratschi Exp $ */
+/* $Id: propsheet.c,v 1.6 1999-07-12 15:58:48 cbratschi Exp $ */
 /*
  * Property Sheets
@@ -791,5 +791,5 @@
   PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
                                                     PropSheetInfoStr);
-
+  if (!psInfo) return;
   /*
    * Set the dirty flag of this page.
Index: trunk/src/comctl32/rebar.c
===================================================================
--- trunk/src/comctl32/rebar.c	(revision 293)
+++ trunk/src/comctl32/rebar.c	(revision 295)
@@ -1,3 +1,3 @@
-/* $Id: rebar.c,v 1.6 1999-06-30 15:52:17 cbratschi Exp $ */
+/* $Id: rebar.c,v 1.7 1999-07-12 15:58:48 cbratschi Exp $ */
 /*
  * Rebar control
@@ -431,6 +431,22 @@
 #if 0
             else if (!lstrcmpA (szClassName, WC_COMBOBOXEXA)) {
+                INT nEditHeight, yPos;
+                RECT rc;
+                HWND hwndEdit;
+
                 /* special placement code for extended combo box */
 
+                /* get size of edit line */
+                hwndEdit = SendMessageA (lpBand->hwndChild, CBEM_GETEDITCONTROL, 0, 0);
+                GetWindowRect (hwndEdit, &rc);
+                nEditHeight = rc.bottom - rc.top;
+                yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
+
+                /* center combo box inside child area */
+                SetWindowPos (lpBand->hwndChild, HWND_TOP,
+                            lpBand->rcChild.left, /*lpBand->rcChild.top*/ yPos,
+                            lpBand->rcChild.right - lpBand->rcChild.left,
+                            nEditHeight,
+                            SWP_SHOWWINDOW);
 
             }
Index: trunk/src/comctl32/status.c
===================================================================
--- trunk/src/comctl32/status.c	(revision 293)
+++ trunk/src/comctl32/status.c	(revision 295)
@@ -1,3 +1,3 @@
-/* $Id: status.c,v 1.8 1999-07-04 21:05:59 cbratschi Exp $ */
+/* $Id: status.c,v 1.9 1999-07-12 15:58:48 cbratschi Exp $ */
 /*
  * Interface code to StatusWindow widget/control
@@ -665,4 +665,5 @@
     if (style & SBT_OWNERDRAW)
     {
+      if (!(part->style & SBT_OWNERDRAW) && part->text) COMCTL32_Free(part->text);
       part->text = (LPWSTR)text;
     } else
@@ -720,7 +721,9 @@
     if (style & SBT_OWNERDRAW)
     {
+      if (!(part->style & SBT_OWNERDRAW) && part->text) COMCTL32_Free(part->text);
       part->text = text;
     } else
     {
+      //compare
       if (lstrcmpW(part->text,text) == 0)
       {
Index: trunk/src/comctl32/tab.c
===================================================================
--- trunk/src/comctl32/tab.c	(revision 293)
+++ trunk/src/comctl32/tab.c	(revision 295)
@@ -1,3 +1,3 @@
-/* $Id: tab.c,v 1.8 1999-07-04 21:05:59 cbratschi Exp $ */
+/* $Id: tab.c,v 1.9 1999-07-12 15:58:48 cbratschi Exp $ */
 /*
  * Tab control
@@ -398,5 +398,5 @@
   pt.y = (INT)HIWORD(lParam);
 
-  newItem=TAB_InternalHitTest (hwnd, infoPtr,pt,(unsigned int*)&dummy);
+  newItem=TAB_InternalHitTest (hwnd, infoPtr,pt,&dummy);
 
 //  TRACE(tab, "On Tab, item %d\n", newItem);
Index: trunk/src/comctl32/toolbar.c
===================================================================
--- trunk/src/comctl32/toolbar.c	(revision 293)
+++ trunk/src/comctl32/toolbar.c	(revision 295)
@@ -1,3 +1,3 @@
-/* $Id: toolbar.c,v 1.10 1999-07-07 17:08:42 cbratschi Exp $ */
+/* $Id: toolbar.c,v 1.11 1999-07-12 15:58:49 cbratschi Exp $ */
 /*
  * Toolbar control
@@ -16,5 +16,4 @@
  *   - Internal COMMCTL32 bitmaps.
  *   - Fix TOOLBAR_SetButtonInfo32A.
- *   - Customize dialog (CB: under construction).
  *   - Drag & drop of buttons
  *
@@ -30,5 +29,6 @@
 
 /* CB: Odin32/WINE bugs
-  - IMAGELIST_Draw draws a line too much at the bottom of the bitmap
+  - IMAGELIST_Draw draws a line too at the bottom of the bitmap (toolbar.exe)
+    imagelist uses default size values instead of real bitmap values
 */
 
@@ -132,5 +132,5 @@
     HDC hdcImageList = CreateCompatibleDC (0);
     HDC hdcMask = CreateCompatibleDC (0);
-    HIMAGELIST himl = infoPtr->himlStd;
+    HIMAGELIST himl = infoPtr->himlDef;
     HBITMAP hbmMask;
 
@@ -182,5 +182,5 @@
     {
       if ((dwStyle & TBSTYLE_FLAT) && (btnPtr->idCommand == 0))
-          TOOLBAR_DrawFlatSeparator (&btnPtr->rect, hdc);
+          TOOLBAR_DrawFlatSeparator (&rc, hdc);
       return;
     }
@@ -189,15 +189,12 @@
     if (!(btnPtr->fsState & TBSTATE_ENABLED))
     {
-      DrawEdge (hdc, &rc, EDGE_RAISED,
+      if (!(dwStyle & TBSTYLE_FLAT))
+        DrawEdge (hdc, &rc, EDGE_RAISED,
                   BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
 
-      if (dwStyle & TBSTYLE_FLAT)
-      {
-/*        if (infoPtr->himlDis) */
-              ImageList_Draw (infoPtr->himlDis, btnPtr->iBitmap, hdc,
-                              rc.left+1, rc.top+1, ILD_NORMAL);
-/*        else */
-/*            TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1); */
-      } else
+      if (infoPtr->himlDis)
+        ImageList_Draw (infoPtr->himlDis, btnPtr->iBitmap, hdc,
+                       rc.left+1, rc.top+1, ILD_NORMAL);
+      else
         TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
 
@@ -210,5 +207,5 @@
     {
       DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
-      ImageList_Draw (infoPtr->himlStd, btnPtr->iBitmap, hdc,
+      ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
                       rc.left+2, rc.top+2, ILD_NORMAL);
       TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
@@ -227,15 +224,8 @@
 
         TOOLBAR_DrawPattern (hdc, &rc);
-        if (dwStyle & TBSTYLE_FLAT)
-        {
-            if (infoPtr->himlDef != NULL)
-            ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
-                            rc.left+2, rc.top+2, ILD_NORMAL);
-            else
-            ImageList_Draw (infoPtr->himlStd, btnPtr->iBitmap, hdc,
-                            rc.left+2, rc.top+2, ILD_NORMAL);
-        } else
-            ImageList_Draw (infoPtr->himlStd, btnPtr->iBitmap, hdc,
-                            rc.left+2, rc.top+2, ILD_NORMAL);
+
+        ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
+                        rc.left+2, rc.top+2, ILD_NORMAL);
+
         TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
         return;
@@ -254,4 +244,5 @@
     }
 
+    /* normal state */
     if (dwStyle & TBSTYLE_FLAT)
     {
@@ -260,17 +251,16 @@
                      BF_RECT | BF_MIDDLE | BF_SOFT);
 
-      if(infoPtr->himlDef != NULL)
-          ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
+      if(btnPtr->bHot && infoPtr->himlHot)
+          ImageList_Draw (infoPtr->himlHot, btnPtr->iBitmap, hdc,
                           rc.left +2, rc.top +2, ILD_NORMAL);
       else
-          ImageList_Draw (infoPtr->himlStd, btnPtr->iBitmap, hdc,
+          ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
                           rc.left +2, rc.top +2, ILD_NORMAL);
     } else
     {
-      /* normal state */
       DrawEdge (hdc, &rc, EDGE_RAISED,
                 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
 
-      ImageList_Draw (infoPtr->himlStd, btnPtr->iBitmap, hdc,
+      ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
                       rc.left+1, rc.top+1, ILD_NORMAL);
     }
@@ -831,4 +821,105 @@
 }
 
+static VOID TBCUSTOMIZE_AvailSelChange(HWND hwnd);
+static VOID TBCUSTOMIZE_VisSelChange(HWND hwnd);
+
+static BOOL TBCUSTOMIZE_FillData(HWND hwnd,TOOLBAR_INFO* infoPtr)
+{
+  TBUTTON_INFO* btnPtr;
+  INT i;
+  INT leftCount = 0;
+  INT rightCount = 0;
+  INT nItem;
+
+  SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_RESETCONTENT,0,0);
+  SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_RESETCONTENT,0,0);
+
+  /* insert 'virtual' separator button into 'available buttons' list */
+  nItem = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"Separator");
+  SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETITEMDATA,nItem,0);
+
+  /* copy all buttons and append them to the listboxes */
+  btnPtr = infoPtr->buttons;
+  for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
+  {
+    if (IsWindowUnicode(infoPtr->hwndNotify))
+    {
+      TBNOTIFYW tbNotify;
+
+      tbNotify.hdr.hwndFrom = infoPtr->hwndToolbar;
+      tbNotify.hdr.idFrom   = GetWindowLongA(infoPtr->hwndToolbar,GWL_ID);
+      tbNotify.iItem    = i;
+      tbNotify.tbButton = (TBBUTTON*)btnPtr;
+      tbNotify.cchText  = 0;
+      tbNotify.pszText  = NULL;
+
+      // send TBN_QUERYINSERT notification
+
+      tbNotify.hdr.code     = TBN_QUERYINSERT;
+
+      if (!SendMessageW(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)tbNotify.hdr.idFrom,(LPARAM)&tbNotify)) continue;
+
+      // send TBN_QUERYDELETE notification
+
+      tbNotify.hdr.code     = TBN_QUERYDELETE;
+
+      btnPtr->bDelete = (BOOL)SendMessageW(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)tbNotify.hdr.idFrom,(LPARAM)&tbNotify);
+
+      //get tool name
+
+      TBCUSTOMIZE_GetToolNameW(infoPtr,btnPtr,i);
+
+    } else
+    {
+      TBNOTIFYA tbNotify;
+
+      tbNotify.hdr.hwndFrom = infoPtr->hwndToolbar;
+      tbNotify.hdr.idFrom   = GetWindowLongA(infoPtr->hwndToolbar,GWL_ID);
+      tbNotify.iItem    = i;
+      tbNotify.tbButton = (TBBUTTON*)btnPtr;
+      tbNotify.cchText  = 0;
+      tbNotify.pszText  = NULL;
+
+      // send TBN_QUERYINSERT notification
+
+      tbNotify.hdr.code     = TBN_QUERYINSERT;
+
+      if (!SendMessageA(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)tbNotify.hdr.idFrom,(LPARAM)&tbNotify)) continue;
+
+      // send TBN_QUERYDELETE notification
+
+      tbNotify.hdr.code     = TBN_QUERYDELETE;
+
+      btnPtr->bDelete = (BOOL)SendMessageA(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)tbNotify.hdr.idFrom,(LPARAM)&tbNotify);
+
+      //get tool name
+
+      TBCUSTOMIZE_GetToolNameA(infoPtr,btnPtr,i);
+    }
+
+    if (btnPtr->fsState & TBSTATE_HIDDEN)
+    {
+      nItem = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"");
+      SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETITEMDATA,nItem,btnPtr->nCustomID);
+      leftCount++;
+    } else
+    {
+      nItem = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"");
+      SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,nItem,btnPtr->nCustomID);
+      rightCount++;
+    }
+  }
+
+  if (leftCount == 0 && rightCount == 0) return FALSE;
+
+  SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETCURSEL,0,0);
+  SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETCURSEL,(rightCount > 0) ? 0:(WPARAM)-1,0);
+
+  TBCUSTOMIZE_AvailSelChange(hwnd);
+  TBCUSTOMIZE_VisSelChange(hwnd);
+
+  return TRUE;
+}
+
 static BOOL TBCUSTOMIZE_InitDialog(HWND hwnd,WPARAM wParam,LPARAM lParam)
 {
@@ -836,125 +927,304 @@
 
   infoPtr = (TOOLBAR_INFO*)lParam;
-  SetWindowLongA (hwnd, DWL_USER, (DWORD)infoPtr);
+  SetWindowLongA(hwnd,DWL_USER,(DWORD)infoPtr);
 
   if (infoPtr)
   {
-    TBUTTON_INFO* btnPtr;
-    INT i;
-    INT leftCount = 0;
-    INT rightCount = 0;
-    INT nItem;
-
-    infoPtr->hDsa = DSA_Create(sizeof(TBUTTON_INFO),5);
-
-    /* insert 'virtual' separator button into 'available buttons' list */
-    SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"Separator");
-
-    /* copy all buttons and append them to the right listbox */
-    btnPtr = infoPtr->buttons;
-    for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
+    INT x;
+
+    //custom ID: 1-nNumButtons, 0 == new separator
+    for (x = 0;x < infoPtr->nNumButtons;x++)
     {
-      DSA_InsertItem (infoPtr->hDsa, i, btnPtr);
-
-      if (IsWindowUnicode(infoPtr->hwndNotify))
+      infoPtr->buttons[x].nCustomID = x+1;
+      infoPtr->buttons[x].pszName = NULL;
+    }
+    infoPtr->nMaxCustomID = infoPtr->nNumButtons;
+
+    //save tools
+    infoPtr->nNumOldButtons = infoPtr->nNumButtons;
+    infoPtr->oldButtons = COMCTL32_Alloc(infoPtr->nNumOldButtons*sizeof(TBUTTON_INFO));
+    memcpy(&infoPtr->oldButtons[0],&infoPtr->buttons[0],infoPtr->nNumOldButtons*sizeof(TBUTTON_INFO));
+
+    if (!TBCUSTOMIZE_FillData(hwnd,infoPtr)) EndDialog(hwnd,FALSE);
+  }
+
+  return TRUE;
+}
+
+static BOOL TBCUSTOMIZE_Close(HWND hwnd,WPARAM wParam,LPARAM lParam)
+{
+  EndDialog(hwnd,FALSE);
+
+  return TRUE;
+}
+
+static VOID TBCUSTOMIZE_Reset(HWND hwnd)
+{
+  TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
+  NMHDR nmhdr;
+  INT x;
+
+  //Send TBN_RESET
+  nmhdr.hwndFrom = infoPtr->hwndToolbar;
+  nmhdr.idFrom   = GetWindowLongA(infoPtr->hwndToolbar,GWL_ID);
+  nmhdr.code     = TBN_RESET;
+
+  SendMessageA(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)nmhdr.idFrom,(LPARAM)&nmhdr);
+
+  for (x = 0;x < infoPtr->nNumOldButtons;x++) COMCTL32_Free(infoPtr->oldButtons[x].pszName);
+
+  //restore data
+  if (infoPtr->nNumButtons != infoPtr->nNumOldButtons)
+  {
+    COMCTL32_Free(infoPtr->buttons);
+    infoPtr->nNumButtons = infoPtr->nNumOldButtons;
+    infoPtr->buttons = COMCTL32_Alloc(infoPtr->nNumButtons*sizeof(TBUTTON_INFO));
+  }
+  memcpy(&infoPtr->buttons[0],&infoPtr->oldButtons[0],infoPtr->nNumButtons*sizeof(TBUTTON_INFO));
+
+  if (!TBCUSTOMIZE_FillData(hwnd,infoPtr)) EndDialog(hwnd,FALSE);
+
+  TOOLBAR_CalcToolbar(infoPtr->hwndToolbar);
+  InvalidateRect(infoPtr->hwndToolbar,NULL,TRUE);
+}
+
+static TBUTTON_INFO* TBCUSTOMIZE_GetBtnPtr(TOOLBAR_INFO* infoPtr,INT customID)
+{
+  INT x;
+  TBUTTON_INFO* btnPtr = infoPtr->buttons;
+
+  if (customID == 0) return NULL;
+
+  for (x = 0;x < infoPtr->nNumButtons;btnPtr++)
+    if (btnPtr->nCustomID == customID) return btnPtr;
+
+  return NULL;
+}
+
+static VOID TBCUSTOMIZE_AddTool(HWND hwnd)
+{
+  TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
+  LRESULT pos,count;
+  INT customID;
+  TBUTTON_INFO* btnPtr;
+  LRESULT rightSel,rightCount,rightPos;
+
+  pos = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETCURSEL,0,0);
+  if (pos == (LRESULT)-1) return;
+
+  count = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETCOUNT,0,0);
+
+  customID = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETITEMDATA,pos,0);
+  if (customID == 0) btnPtr = NULL; else
+  {
+    btnPtr = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
+    if (btnPtr == NULL) return;
+
+    SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_DELETESTRING,pos,0);
+  }
+
+  rightSel = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCURSEL,0,0);
+  rightCount = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCOUNT,0,0);
+
+  if (rightSel != (LRESULT)-1)
+    rightPos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_INSERTSTRING,rightSel,(LPARAM)"");
+  else
+    rightPos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"");
+  if (!btnPtr)
+  { //new separator
+    TBUTTON_INFO* newButtons;
+
+    newButtons = COMCTL32_Alloc((infoPtr->nNumButtons+1)*sizeof(TBUTTON_INFO));
+    memcpy(&newButtons[0],&infoPtr->buttons[0],infoPtr->nNumButtons*sizeof(TBUTTON_INFO));
+    COMCTL32_Free(infoPtr->buttons);
+
+    infoPtr->buttons = newButtons;
+    infoPtr->nNumButtons++;
+
+    btnPtr = &infoPtr->buttons[infoPtr->nNumButtons-1];
+    ZeroMemory(btnPtr,sizeof(TBUTTON_INFO));
+    btnPtr->fsStyle = TBSTYLE_SEP;
+    btnPtr->bDelete = TRUE;
+
+    customID = ++infoPtr->nMaxCustomID;
+    btnPtr->nCustomID = customID;
+    SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,rightPos,customID);
+  } else
+  {
+    SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,rightPos,customID);
+    btnPtr->fsState &= ~TBSTATE_HIDDEN;
+  }
+  SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETCURSEL,rightPos,0);
+  TBCUSTOMIZE_VisSelChange(hwnd);
+
+  if (rightCount > 0)
+  { //change order
+    TBUTTON_INFO* btnPtr2;
+    INT customID2,pos1,pos2;
+
+    pos1 = 0;
+    while (infoPtr->buttons[pos1].nCustomID != customID) pos1++;
+    if (rightPos < rightCount)
+    { //insert before
+      customID2 = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,rightPos+1,0);
+      pos2 = 0;
+      while (infoPtr->buttons[pos2].nCustomID != customID2) pos2++;
+    } else
+    { //insert behind
+      INT x;
+
+      customID2 = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,rightPos-1,0);
+      pos2 = 0;
+      while (infoPtr->buttons[pos2].nCustomID != customID2) pos2++;
+      //exchange to use first alogrithm
+      x = pos1;
+      pos1 = pos2;
+      pos2 = x;
+    }
+
+    if (pos1+1 != pos2)
+    {
+      TBUTTON_INFO temp;
+      INT x;
+
+      memcpy(&temp,&infoPtr->buttons[pos1],sizeof(TBUTTON_INFO));
+      if (pos1 < pos2)
       {
-        TBNOTIFYW tbNotify;
-
-        tbNotify.hdr.hwndFrom = infoPtr->hwndToolbar;
-        tbNotify.hdr.idFrom   = GetWindowLongA(infoPtr->hwndToolbar,GWL_ID);
-        tbNotify.iItem    = i;
-        tbNotify.tbButton = (TBBUTTON*)btnPtr;
-        tbNotify.cchText  = 0;
-        tbNotify.pszText  = NULL;
-
-        // send TBN_QUERYINSERT notification
-
-        tbNotify.hdr.code     = TBN_QUERYINSERT;
-
-        if (!SendMessageW(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)tbNotify.hdr.idFrom,(LPARAM)&tbNotify)) continue;
-
-        // send TBN_QUERYDELETE notification
-
-        tbNotify.hdr.code     = TBN_QUERYDELETE;
-
-        btnPtr->bDelete = (BOOL)SendMessageW(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)tbNotify.hdr.idFrom,(LPARAM)&tbNotify);
-
-        //get tool name
-
-        TBCUSTOMIZE_GetToolNameW(infoPtr,btnPtr,i);
-
+        for (x = pos1;x < pos2;x++)
+          memcpy(&infoPtr->buttons[x],&infoPtr->buttons[x+1],sizeof(TBUTTON_INFO));
+        memcpy(&infoPtr->buttons[pos2-1],&temp,sizeof(TBUTTON_INFO));
       } else
       {
-        TBNOTIFYA tbNotify;
-
-        tbNotify.hdr.hwndFrom = infoPtr->hwndToolbar;
-        tbNotify.hdr.idFrom   = GetWindowLongA(infoPtr->hwndToolbar,GWL_ID);
-        tbNotify.iItem    = i;
-        tbNotify.tbButton = (TBBUTTON*)btnPtr;
-        tbNotify.cchText  = 0;
-        tbNotify.pszText  = NULL;
-
-        // send TBN_QUERYINSERT notification
-
-        tbNotify.hdr.code     = TBN_QUERYINSERT;
-
-        if (!SendMessageA(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)tbNotify.hdr.idFrom,(LPARAM)&tbNotify)) continue;
-
-        // send TBN_QUERYDELETE notification
-
-        tbNotify.hdr.code     = TBN_QUERYDELETE;
-
-        btnPtr->bDelete = (BOOL)SendMessageA(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)tbNotify.hdr.idFrom,(LPARAM)&tbNotify);
-
-        //get tool name
-
-        TBCUSTOMIZE_GetToolNameA(infoPtr,btnPtr,i);
+        for (x = pos1-1;x >= pos2;x--)
+          memcpy(&infoPtr->buttons[x+1],&infoPtr->buttons[x],sizeof(TBUTTON_INFO));
+        memcpy(&infoPtr->buttons[pos2],&temp,sizeof(TBUTTON_INFO));
       }
-
-      if (btnPtr->fsState & TBSTATE_HIDDEN)
+    }
+  }
+
+  if (pos == count-1 && pos > 0) pos--;
+  SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETCURSEL,pos,0);
+  TBCUSTOMIZE_AvailSelChange(hwnd);
+
+  TOOLBAR_CalcToolbar(infoPtr->hwndToolbar);
+  InvalidateRect(infoPtr->hwndToolbar,NULL,TRUE);
+}
+
+static VOID TBCUSTOMIZE_RemoveTool(HWND hwnd)
+{
+  TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
+  LRESULT pos,count;
+  INT customID;
+  TBUTTON_INFO* btnPtr;
+
+  pos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCURSEL,0,0);
+  if (pos == (LRESULT)-1) return;
+
+  count = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCOUNT,0,0);
+
+  customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos,0);
+  if (customID == 0) return; //no allowed
+
+  btnPtr = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
+  if (btnPtr == NULL || !btnPtr->bDelete) return;
+
+  SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_DELETESTRING,pos,0);
+
+  if (btnPtr->fsStyle & TBSTYLE_SEP)
+  { //remove separator
+    TBUTTON_INFO* newButtons;
+    INT nIndex,x;
+
+    //find pos
+    for (x = 0;x < infoPtr->nNumButtons;x++) if (&infoPtr->buttons[x] == btnPtr)
+    {
+      nIndex = x;
+      break;
+    }
+
+    infoPtr->nNumButtons--;
+    newButtons = COMCTL32_Alloc(infoPtr->nNumButtons*sizeof(TBUTTON_INFO));
+
+    if (nIndex > 0)
+      memcpy(&newButtons[0],&infoPtr->buttons[0],nIndex*sizeof(TBUTTON_INFO));
+
+    if (nIndex < infoPtr->nNumButtons)
+      memcpy (&newButtons[nIndex],&infoPtr->buttons[nIndex+1],(infoPtr->nNumButtons-nIndex)*sizeof(TBUTTON_INFO));
+
+    COMCTL32_Free(infoPtr->buttons);
+    infoPtr->buttons = newButtons;
+  } else
+  {
+    LRESULT leftSel,leftCount,leftPos;
+
+    leftSel = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETCURSEL,0,0);
+    leftCount = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETCOUNT,0,0);
+
+    if (leftSel == 0)
+      if (leftCount > 1) leftSel++; else leftSel = -1;
+
+    if (leftSel != (LRESULT)-1)
+      leftPos = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_INSERTSTRING,leftSel,(LPARAM)"");
+    else
+      leftPos = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"");
+    SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETITEMDATA,leftPos,customID);
+
+    SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETCURSEL,leftPos,0);
+    TBCUSTOMIZE_AvailSelChange(hwnd);
+
+    btnPtr->fsState |= TBSTATE_HIDDEN;
+
+    if (leftCount > 1)
+    { //change order
+      TBUTTON_INFO* btnPtr2;
+      INT customID2,pos1,pos2;
+
+      pos1 = 0;
+      while (infoPtr->buttons[pos1].nCustomID != customID) pos1++;
+      if (leftPos < leftCount)
+      { //insert before
+        customID2 = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETITEMDATA,leftPos+1,0);
+        pos2 = 0;
+        while (infoPtr->buttons[pos2].nCustomID != customID2) pos2++;
+      } else
+      { //insert behind
+        INT x;
+
+        customID2 = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETITEMDATA,leftPos-1,0);
+        pos2 = 0;
+        while (infoPtr->buttons[pos2].nCustomID != customID2) pos2++;
+        //exchange to use first alogrithm
+        x = pos1;
+        pos1 = pos2;
+        pos2 = x;
+      }
+
+      if (pos1+1 != pos2)
       {
-        nItem = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"");
-        SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETITEMDATA,nItem,(LPARAM)btnPtr);
-        leftCount++;
-      } else
-      {
-        nItem = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"");
-        SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,nItem,(LPARAM)btnPtr);
-        rightCount++;
+        TBUTTON_INFO temp;
+        INT x;
+
+        memcpy(&temp,&infoPtr->buttons[pos1],sizeof(TBUTTON_INFO));
+        if (pos1 < pos2)
+        {
+          for (x = pos1;x < pos2;x++)
+            memcpy(&infoPtr->buttons[x],&infoPtr->buttons[x+1],sizeof(TBUTTON_INFO));
+          memcpy(&infoPtr->buttons[pos2-1],&temp,sizeof(TBUTTON_INFO));
+        } else
+        {
+          for (x = pos1-1;x >= pos2;x--)
+            memcpy(&infoPtr->buttons[x+1],&infoPtr->buttons[x],sizeof(TBUTTON_INFO));
+          memcpy(&infoPtr->buttons[pos2],&temp,sizeof(TBUTTON_INFO));
+        }
       }
     }
-
-    if (leftCount == 0 && rightCount == 0)
-    {
-      EndDialog(hwnd,FALSE);
-
-      return TRUE;
-    }
   }
 
-  return TRUE;
-}
-
-static BOOL TBCUSTOMIZE_Close(HWND hwnd,WPARAM wParam,LPARAM lParam)
-{
-  EndDialog(hwnd,FALSE);
-
-  return TRUE;
-}
-
-static VOID TBCUSTOMIZE_Reset(HWND hwnd)
-{
-  //CB: todo
-  //Send TBN_RESET
-}
-
-static VOID TBCUSTOMIZE_AddTool(HWND hwnd)
-{
-  //CB: todo
-}
-
-static VOID TBCUSTOMIZE_RemoveTool(HWND hwnd)
-{
-  //CB: todo
+  if (pos == count-1) pos--;
+  SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETCURSEL,pos,0);
+  TBCUSTOMIZE_VisSelChange(hwnd);
+
+  TOOLBAR_CalcToolbar(infoPtr->hwndToolbar);
+  InvalidateRect(infoPtr->hwndToolbar,NULL,TRUE);
 }
 
@@ -974,10 +1244,117 @@
 static VOID TBCUSTOMIZE_MoveToolUp(HWND hwnd)
 {
-  //CB: todo
+  TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
+  LRESULT pos;
+  TBUTTON_INFO button;
+  INT customID;
+  TBUTTON_INFO* btnPtr1,* btnPtr2;
+
+  pos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCURSEL,0,0);
+  if (pos == (LRESULT)-1 || pos == 0) return;
+
+  //update listbox
+
+  customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos,0);
+  btnPtr1 = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
+  if (btnPtr1 == NULL) return;
+
+  customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos-1,0);
+  btnPtr2 = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
+  if (btnPtr2 == NULL) return;
+
+  SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,pos,btnPtr2->nCustomID);
+  SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,pos-1,btnPtr1->nCustomID);
+
+  SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETCURSEL,pos-1,0);
+  TBCUSTOMIZE_VisSelChange(hwnd);
+
+  //update buttons
+  memcpy(&button,btnPtr1,sizeof(TBUTTON_INFO));
+  memcpy(btnPtr1,btnPtr2,sizeof(TBUTTON_INFO));
+  memcpy(btnPtr2,&button,sizeof(TBUTTON_INFO));
+
+  TOOLBAR_CalcToolbar(infoPtr->hwndToolbar);
+  InvalidateRect(infoPtr->hwndToolbar,NULL,TRUE);
 }
 
 static VOID TBCUSTOMIZE_MoveToolDown(HWND hwnd)
 {
-  //CB: todo
+  TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
+  LRESULT pos,count;
+  TBUTTON_INFO button;
+  INT customID;
+  TBUTTON_INFO* btnPtr1,* btnPtr2;
+
+  pos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCURSEL,0,0);
+  if (pos == (LRESULT)-1) return;
+
+  count = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCOUNT,0,0);
+  if (pos == count-1) return;
+
+  //update listbox
+
+  customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos,0);
+  btnPtr1 = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
+  if (btnPtr1 == NULL) return;
+
+  customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos+1,0);
+  btnPtr2 = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
+  if (btnPtr2 == NULL) return;
+
+  SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,pos,btnPtr2->nCustomID);
+  SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,pos+1,btnPtr1->nCustomID);
+
+  SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETCURSEL,pos+1,0);
+  TBCUSTOMIZE_VisSelChange(hwnd);
+
+  //update buttons
+  memcpy(&button,btnPtr1,sizeof(TBUTTON_INFO));
+  memcpy(btnPtr1,btnPtr2,sizeof(TBUTTON_INFO));
+  memcpy(btnPtr2,&button,sizeof(TBUTTON_INFO));
+
+  TOOLBAR_CalcToolbar(infoPtr->hwndToolbar);
+  InvalidateRect(infoPtr->hwndToolbar,NULL,TRUE);
+}
+
+static VOID TBCUSTOMIZE_AvailSelChange(HWND hwnd)
+{
+  LRESULT pos;
+  HWND hwndBtn;
+
+  pos = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETCURSEL,0,0);
+
+  hwndBtn = GetDlgItem(hwnd,IDOK);
+  EnableWindow(hwndBtn,(pos == (LRESULT)-1) ? FALSE:TRUE);
+}
+
+static VOID TBCUSTOMIZE_VisSelChange(HWND hwnd)
+{
+  TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
+  LRESULT pos;
+
+  pos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCURSEL,0,0);
+
+  if (pos == (LRESULT)-1)
+  {
+    EnableWindow(GetDlgItem(hwnd,IDC_REMOVE_BTN),FALSE);
+    EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN),FALSE);
+    EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN),FALSE);
+  } else
+  {
+    INT customID;
+    TBUTTON_INFO* btnPtr;
+    LRESULT count;
+
+    customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos,0);
+    btnPtr = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
+    count = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCOUNT,0,0);
+
+    if (btnPtr)
+      EnableWindow(GetDlgItem(hwnd,IDC_REMOVE_BTN),btnPtr->bDelete);
+    else
+      EnableWindow(GetDlgItem(hwnd,IDC_REMOVE_BTN),TRUE);
+    EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN),!(pos == 0));
+    EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN),!(pos == count-1));
+  }
 }
 
@@ -1007,4 +1384,26 @@
       TBCUSTOMIZE_MoveToolDown(hwnd);
       break;
+    case IDC_AVAILBTN_LBOX:
+      switch(HIWORD(wParam))
+      {
+        case LBN_SELCHANGE:
+          TBCUSTOMIZE_AvailSelChange(hwnd);
+          break;
+        case LBN_DBLCLK:
+          TBCUSTOMIZE_AddTool(hwnd);
+          break;
+      }
+      break;
+    case IDC_TOOLBARBTN_LBOX:
+      switch(HIWORD(wParam))
+      {
+        case LBN_SELCHANGE:
+          TBCUSTOMIZE_VisSelChange(hwnd);
+          break;
+        case LBN_DBLCLK:
+          TBCUSTOMIZE_RemoveTool(hwnd);
+          break;
+      }
+      break;
   }
 
@@ -1017,11 +1416,9 @@
   INT x;
 
-  for (x = 0;x < infoPtr->nNumButtons;x++)
-  {
-    COMCTL32_Free(infoPtr->buttons[x].pszName);
-    infoPtr->buttons[x].pszName = NULL;
-  }
-
-  if (infoPtr->hDsa) DSA_Destroy(infoPtr->hDsa);
+  for (x = 0;x < infoPtr->nNumOldButtons;x++)
+    COMCTL32_Free(infoPtr->oldButtons[x].pszName);
+  COMCTL32_Free(infoPtr->oldButtons);
+  infoPtr->oldButtons = NULL;
+  infoPtr->nNumOldButtons = 0;
 
   return TRUE;
@@ -1040,13 +1437,12 @@
     COLORREF oldText = 0;
     COLORREF oldBk = 0;
+    INT customID;
     TBUTTON_INFO* btnPtr;
     DWORD dwStyle = GetWindowLongA(infoPtr->hwndToolbar,GWL_STYLE);
 
-    btnPtr = (TBUTTON_INFO*)SendDlgItemMessageA(hwnd,wParam,LB_GETITEMDATA,lpdis->itemID,0);
-
-//              FIXME(toolbar, "action: %x itemState: %x\n",
-//                    lpdis->itemAction, lpdis->itemState);
-
-     if (btnPtr != NULL && !btnPtr->bDelete)
+    customID = SendDlgItemMessageA(hwnd,wParam,LB_GETITEMDATA,lpdis->itemID,0);
+    btnPtr = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
+
+    if (btnPtr != NULL && !btnPtr->bDelete)
     {
       if (lpdis->itemState & ODS_FOCUS) oldBk = SetBkColor(lpdis->hDC,GetSysColor(COLOR_HIGHLIGHT));
@@ -1075,26 +1471,24 @@
     if (lpdis->itemState & ODS_FOCUS) DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
 
-    /* draw button */
-    DrawEdge(lpdis->hDC,&rcButton,EDGE_RAISED,BF_RECT|BF_MIDDLE|BF_SOFT|BF_ADJUST);
-
-    if (btnPtr && !btnPtr->fsStyle & TBSTYLE_SEP)
+    //draw tool
+    if (btnPtr && !(btnPtr->fsStyle & TBSTYLE_SEP))
     {
+      //draw button
       if (dwStyle & TBSTYLE_FLAT)
       {
-        if(infoPtr->himlDef != NULL)
-            ImageList_Draw(infoPtr->himlDef,btnPtr->iBitmap,lpdis->hDC,
-                           rcButton.left+2,rcButton.top+2,ILD_NORMAL);
-        else
-            ImageList_Draw(infoPtr->himlStd,btnPtr->iBitmap,lpdis->hDC,
-                           rcButton.left+2,rcButton.top+2,ILD_NORMAL);
+        ImageList_Draw(infoPtr->himlDef,btnPtr->iBitmap,lpdis->hDC,rcButton.left+2,rcButton.top+2,ILD_NORMAL);
       } else
       {
-        /* normal state */
-        ImageList_Draw(infoPtr->himlStd,btnPtr->iBitmap,lpdis->hDC,
-                       rcButton.left+1,rcButton.top+1,ILD_NORMAL);
+        DrawEdge (lpdis->hDC,&rcButton,EDGE_RAISED,BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
+
+        ImageList_Draw(infoPtr->himlDef,btnPtr->iBitmap,lpdis->hDC,rcButton.left+1,rcButton.top+1,ILD_NORMAL);
       }
+
     } else
     { //draw separator
-
+      if (!(dwStyle & TBSTYLE_FLAT))
+        DrawEdge (lpdis->hDC,&rcButton,EDGE_RAISED,BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
+
+      TOOLBAR_DrawFlatSeparator(&rcButton,lpdis->hDC);
     }
 
@@ -1130,10 +1524,13 @@
     MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
 
-    infoPtr = (TOOLBAR_INFO *)GetWindowLongA(hwnd,DWL_USER);
-
     if (infoPtr)
-      lpmis->itemHeight = infoPtr->nBitmapHeight+8;
-    else
-      lpmis->itemHeight = 16+8; /* default height */
+    {
+      DWORD dwStyle = GetWindowLongA(infoPtr->hwndToolbar,GWL_STYLE);
+
+      if (dwStyle & TBSTYLE_FLAT)
+        lpmis->itemHeight = infoPtr->nBitmapHeight+4;
+      else
+        lpmis->itemHeight = infoPtr->nBitmapHeight+8;
+    } else lpmis->itemHeight = 16+8;
 
     return TRUE;
@@ -1187,73 +1584,88 @@
     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
-    INT nIndex = 0;
-
-    if ((!lpAddBmp) || ((INT)wParam <= 0))
+    INT nIndex = 0,nButtons;
+
+    if (!lpAddBmp)
         return -1;
 
-//    TRACE (toolbar, "adding %d bitmaps!\n", wParam);
-
-    if (!(infoPtr->himlStd)) {
-        /* create new standard image list */
-
-//      TRACE (toolbar, "creating standard image list!\n");
-
+    if (lpAddBmp->hInst == HINST_COMMCTRL)
+    {
+        if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
+            nButtons = 15;
+        else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
+            nButtons = 13;
+        else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
+            nButtons = 5;
+        else
+            return -1;
+
+//        TRACE ("adding %d internal bitmaps!\n", nButtons);
 
         /* Windows resize all the buttons to the size of a newly added STandard Image*/
-        /* TODO: The resizing  should be done each time a standard image is added*/
-        if (lpAddBmp->hInst == HINST_COMMCTRL)
+        if (lpAddBmp->nID & 1)
         {
-
-            if (lpAddBmp->nID & 1)
-            {
-                SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
-                              MAKELPARAM((WORD)26, (WORD)26));
-                SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
-                              MAKELPARAM((WORD)33, (WORD)33));
-            }
-            else
-            {
-                SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
-                              MAKELPARAM((WORD)16, (WORD)16));
-
-                SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
-                              MAKELPARAM((WORD)22, (WORD)22));
-            }
-
-            TOOLBAR_CalcToolbar (hwnd);
+            /* large icons */
+            SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
+                          MAKELPARAM((WORD)26, (WORD)26));
+            SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
+                          MAKELPARAM((WORD)33, (WORD)33));
         }
-
-        infoPtr->himlStd =
+        else
+        {
+            /* small icons */
+            SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
+                          MAKELPARAM((WORD)16, (WORD)16));
+            SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
+                          MAKELPARAM((WORD)22, (WORD)22));
+        }
+
+        TOOLBAR_CalcToolbar (hwnd);
+    }
+    else
+    {
+        nButtons = (INT)wParam;
+        if (nButtons <= 0)
+            return -1;
+
+//        TRACE ("adding %d bitmaps!\n", nButtons);
+    }
+
+    if (!(infoPtr->himlDef)) {
+        /* create new default image list */
+//        TRACE ("creating default image list!\n");
+
+        infoPtr->himlDef =
             ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
-                              ILC_COLOR | ILC_MASK, (INT)wParam, 2);
-    }
-
-    /* Add bitmaps to the standard image list */
-    if (lpAddBmp->hInst == (HINSTANCE)0) {
+                              ILC_COLOR | ILC_MASK, nButtons, 2);
+        infoPtr->himlInt = infoPtr->himlDef;
+    }
+
+    /* Add bitmaps to the default image list */
+    if (lpAddBmp->hInst == (HINSTANCE)0)
+    {
         nIndex =
-            ImageList_AddMasked (infoPtr->himlStd, (HBITMAP)lpAddBmp->nID,
+            ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
                                  CLR_DEFAULT);
     }
-    else if (lpAddBmp->hInst == HINST_COMMCTRL) {
+    else if (lpAddBmp->hInst == HINST_COMMCTRL)
+    {
         /* add internal bitmaps */
-
-//      FIXME (toolbar, "internal bitmaps not supported!\n");
-        /* TODO: Resize all the buttons when a new standard image is added */
+//        FIXME ("internal bitmaps not supported!\n");
 
         /* Hack to "add" some reserved images within the image list
            to get the right image indices */
-        nIndex = ImageList_GetImageCount (infoPtr->himlStd);
-        ImageList_SetImageCount (infoPtr->himlStd, nIndex + (INT)wParam);
-
-    }
-    else {
+        nIndex = ImageList_GetImageCount (infoPtr->himlDef);
+        ImageList_SetImageCount (infoPtr->himlDef, nIndex + nButtons);
+    }
+    else
+    {
         HBITMAP hBmp =
             LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
-        nIndex = ImageList_AddMasked (infoPtr->himlStd, hBmp, CLR_DEFAULT);
+        nIndex = ImageList_AddMasked (infoPtr->himlDef, hBmp, CLR_DEFAULT);
 
         DeleteObject (hBmp);
     }
 
-    infoPtr->nNumBitmaps += (INT)wParam;
+    infoPtr->nNumBitmaps += nButtons;
 
     return nIndex;
@@ -1632,4 +2044,6 @@
     HRSRC hRes;
     NMHDR nmhdr;
+
+    if (infoPtr->nNumButtons == 0) return 0;
 
     /* send TBN_BEGINADJUST notification */
@@ -1966,8 +2380,5 @@
     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
 
-    if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
-        return (LRESULT)infoPtr->himlDis;
-    else
-        return 0;
+    return (LRESULT)infoPtr->himlDis;
 }
 
@@ -1987,8 +2398,5 @@
     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
 
-    if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
-        return (LRESULT)infoPtr->himlHot;
-    else
-        return 0;
+    return (LRESULT)infoPtr->himlHot;
 }
 
@@ -2002,8 +2410,5 @@
     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
 
-    if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
-        return (LRESULT)infoPtr->himlDef;
-    else
-        return 0;
+    return (LRESULT)infoPtr->himlDef;
 }
 
@@ -2654,7 +3059,4 @@
     HIMAGELIST himlTemp;
 
-    if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
-        return 0;
-
     himlTemp = infoPtr->himlDis;
     infoPtr->himlDis = (HIMAGELIST)lParam;
@@ -2699,7 +3101,4 @@
     HIMAGELIST himlTemp;
 
-    if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
-        return 0;
-
     himlTemp = infoPtr->himlHot;
     infoPtr->himlHot = (HIMAGELIST)lParam;
@@ -2719,7 +3118,4 @@
     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     HIMAGELIST himlTemp;
-
-    if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
-        return 0;
 
     himlTemp = infoPtr->himlDef;
@@ -2933,6 +3329,7 @@
     infoPtr->dwDTFlags = DT_CENTER;
 
-    infoPtr->hDsa        = NULL;
     infoPtr->hwndToolbar = hwnd;
+    infoPtr->oldButtons = NULL;
+    infoPtr->nNumOldButtons = 0;
 
     SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
@@ -2994,15 +3391,7 @@
     }
 
-    /* destroy default image list */
-    if (infoPtr->himlDef)
-        ImageList_Destroy (infoPtr->himlDef);
-
-    /* destroy disabled image list */
-    if (infoPtr->himlDis)
-        ImageList_Destroy (infoPtr->himlDis);
-
-    /* destroy hot image list */
-    if (infoPtr->himlHot)
-        ImageList_Destroy (infoPtr->himlHot);
+    /* destroy internal image list */
+    if (infoPtr->himlInt)
+        ImageList_Destroy (infoPtr->himlInt);
 
     /* delete default font */
@@ -3192,5 +3581,5 @@
       {
         oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
-        if (oldBtnPtr->bHot)
+        if (oldBtnPtr->bHot) //CB: dynamic buttons
         {
           oldBtnPtr->bHot = FALSE;
Index: trunk/src/comctl32/tooltips.c
===================================================================
--- trunk/src/comctl32/tooltips.c	(revision 293)
+++ trunk/src/comctl32/tooltips.c	(revision 295)
@@ -1,3 +1,3 @@
-/* $Id: tooltips.c,v 1.11 1999-07-07 17:08:43 cbratschi Exp $ */
+/* $Id: tooltips.c,v 1.12 1999-07-12 15:58:49 cbratschi Exp $ */
 /*
  * Tool tip control
@@ -1133,5 +1133,5 @@
     if (nTool == -1) return 0;
 
-    TOOLTIPS_GetTipText(hwnd,infoPtr,nTool);
+    TOOLTIPS_GetTipText(hwnd,infoPtr,nTool); //CB: get text
 
     lstrcpyWtoA(lpToolInfo->lpszText,infoPtr->szTipText);
@@ -1156,5 +1156,5 @@
     if (nTool == -1) return 0;
 
-    TOOLTIPS_GetTipText(hwnd,infoPtr,nTool);
+    TOOLTIPS_GetTipText(hwnd,infoPtr,nTool); //CB: get text
 
     lstrcpyW(lpToolInfo->lpszText,infoPtr->szTipText);
@@ -1979,4 +1979,11 @@
 }
 
+static LRESULT
+TOOLTIPS_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
+{
+//    FIXME ("hwnd=%x wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
+
+    return 0;
+}
 
 static LRESULT
@@ -2020,4 +2027,5 @@
  * returns the length, in characters, of the tip text
  ******************************************************************/
+
 static LRESULT
 TOOLTIPS_OnWMGetTextLength(HWND hwnd, WPARAM wParam, LPARAM lParam)
@@ -2321,6 +2329,6 @@
             return TOOLTIPS_NCHitTest (hwnd, wParam, lParam);
 
-/*      case WM_NOTIFYFORMAT: */
-/*          return TOOLTIPS_NotifyFormat (hwnd, wParam, lParam); */
+        case WM_NOTIFYFORMAT:
+            return TOOLTIPS_NotifyFormat (hwnd, wParam, lParam);
 
         case WM_PAINT:
Index: trunk/src/comctl32/treeview.c
===================================================================
--- trunk/src/comctl32/treeview.c	(revision 293)
+++ trunk/src/comctl32/treeview.c	(revision 295)
@@ -1,3 +1,3 @@
-/* $Id: treeview.c,v 1.7 1999-06-30 15:52:19 cbratschi Exp $ */
+/* $Id: treeview.c,v 1.8 1999-07-12 15:58:49 cbratschi Exp $ */
 /* Treeview control
  *
@@ -42,4 +42,7 @@
  */
 
+/* CB: todo
+ - fix ffs();
+*/
 
 #include <string.h>
@@ -1268,4 +1271,5 @@
  * This method does the chaining of the insertion of a treeview item
  * before an item.
+ * If parent is NULL, we're inserting at the root of the list.
  */
 static void TREEVIEW_InsertBefore(
@@ -1305,8 +1309,11 @@
       upSibling->sibling = newItem->hItem;
     else
+    if (parent)
       /* this item is the first child of this parent, adjust parent pointers */
       parent->firstChild = newItem->hItem;
+    else infoPtr->TopRootItem = newItem->hItem;
   }
   else /* Insert as first child of this parent */
+  if (parent)
     parent->firstChild = newItem->hItem;
 }
@@ -1314,4 +1321,5 @@
 /***************************************************************************
  * This method does the chaining of the insertion of a treeview item
+ * If parent is NULL, we're inserting at the root of the list.
  * after an item.
  */
@@ -1357,4 +1365,5 @@
   }
   else /* Insert as first child of this parent */
+  if (parent)
     parent->firstChild = newItem->hItem;
 }
@@ -1390,4 +1399,11 @@
   /* Obtain the TVSORTBC struct */
   infoPtr->pCallBackSort = (LPTVSORTCB)lParam;
+
+  /* Check for a valid handle to the parent item */
+  if (!TREEVIEW_ValidItem(infoPtr, infoPtr->pCallBackSort->hParent))
+  {
+//    ERR ("invalid item hParent=%d\n", (INT)infoPtr->pCallBackSort->hParent);
+    return FALSE;
+  }
 
   /* Obtain the parent node to sort */
@@ -1627,9 +1643,13 @@
       else
       {
-        TREEVIEW_ITEM *aChild        =
-          &infoPtr->items[(INT)parentItem->firstChild];
+        TREEVIEW_ITEM *aChild;
 
         TREEVIEW_ITEM *previousChild = NULL;
         BOOL bItemInserted           = FALSE;
+
+        if (parentItem)
+          aChild = &infoPtr->items[(INT)parentItem->firstChild];
+        else
+          aChild = &infoPtr->items[(INT)infoPtr->TopRootItem];
 
         /* Iterate the parent children to see where we fit in */
Index: trunk/src/comctl32/updown.c
===================================================================
--- trunk/src/comctl32/updown.c	(revision 293)
+++ trunk/src/comctl32/updown.c	(revision 295)
@@ -1,3 +1,3 @@
-/* $Id: updown.c,v 1.5 1999-06-24 16:37:46 cbratschi Exp $ */
+/* $Id: updown.c,v 1.6 1999-07-12 15:58:51 cbratschi Exp $ */
 /*
  * Updown control
@@ -195,5 +195,5 @@
 
   /*if the buddy is a list window, we must set curr index */
-  if (!lstrcmpA(infoPtr->szBuddyClass,"ListBox"))
+  if (!lstrcmpiA(infoPtr->szBuddyClass,"ListBox"))
   {
     newVal = SendMessageA(infoPtr->Buddy,LB_GETCARETINDEX,0,0);
@@ -245,5 +245,5 @@
 
   /*if the buddy is a list window, we must set curr index */
-  if(!lstrcmpA(infoPtr->szBuddyClass, "ListBox"))
+  if(!lstrcmpiA(infoPtr->szBuddyClass, "ListBox"))
   {
     SendMessageA(infoPtr->Buddy,LB_SETCURSEL,infoPtr->CurVal,0);
@@ -365,4 +365,7 @@
     return FALSE;
 
+  /* Store buddy wundow handle */
+  infoPtr->Buddy = hwndBud;
+
   /* Store buddy window clas name */
   GetClassNameA (hwndBud, infoPtr->szBuddyClass, 40);
@@ -529,5 +532,5 @@
 
       /* If the buddy is an edit, will set focus to it */
-      if (!lstrcmpA(infoPtr->szBuddyClass,"Edit")) SetFocus(infoPtr->Buddy);
+      if (!lstrcmpiA(infoPtr->szBuddyClass,"Edit")) SetFocus(infoPtr->Buddy);
 
       /* Now see which one is the 'active' arrow */
@@ -702,5 +705,5 @@
    /*If we released the mouse and our buddy is an edit */
    /* we must select all text in it.                   */
-   if (!lstrcmpA(infoPtr->szBuddyClass,"Edit"))
+   if (!lstrcmpiA(infoPtr->szBuddyClass,"Edit"))
        SendMessageA(infoPtr->Buddy,EM_SETSEL,0,MAKELONG(0,-1));
 
