Sync to Wine-0_9_1:
Vitaliy Margolen <wine-patch@kievinfo.com>
- Unify HEADER_GetItem[A/W] into one function.
- Unify HEADER_InsertItem[A/W] into one function.
- Unify HEADER_SetItem[A/W] into one function.
Michael Kaufmann <hallo@michael-kaufmann.ch>
- Handle WM_PRINTCLIENT.
  Don't use SelectClipRgn in WM_PRINTCLIENT.
Dimi Paun <dimi@lattica.com>
- Validate the column index passed in by the caller.
Alex Villacís Lasso <a_villacis@palosanto.com>
- Do not issue a GetUpdateRect() to query an update region for
  WM_PAINT(wParam=HDC) case. Instead, use GetClientRect() for a bounding
  rect.
Vincent Béron <vberon@mecano.gme.usherb.ca>
- Move functions in comctl32/string.c to remove function declaration.
Dmitry Timoshkov <dmitry@codeweavers.com>
- Use Win32 APIs for string comparison.
- Avoid printing out a possibly uninitialized variable.
Ulrich Czekalla <ulrich@codeweavers.com>
- Clear bLButtonDown flags if mouse is not down.
Martin Fuchs <martin-fuchs@gmx.net>
- Include config.h and port.h for strncasecmp() in MSVC port.
Modified: trunk/reactos/lib/comctl32/animate.c
Modified: trunk/reactos/lib/comctl32/comboex.c
Modified: trunk/reactos/lib/comctl32/datetime.c
Modified: trunk/reactos/lib/comctl32/header.c
Modified: trunk/reactos/lib/comctl32/hotkey.c
Modified: trunk/reactos/lib/comctl32/imagelist.c
Modified: trunk/reactos/lib/comctl32/listview.c
Modified: trunk/reactos/lib/comctl32/monthcal.c
Modified: trunk/reactos/lib/comctl32/pager.c
Modified: trunk/reactos/lib/comctl32/progress.c
Modified: trunk/reactos/lib/comctl32/propsheet.c
Modified: trunk/reactos/lib/comctl32/rebar.c
Modified: trunk/reactos/lib/comctl32/status.c
Modified: trunk/reactos/lib/comctl32/string.c
Modified: trunk/reactos/lib/comctl32/syslink.c
Modified: trunk/reactos/lib/comctl32/tab.c
Modified: trunk/reactos/lib/comctl32/toolbar.c
Modified: trunk/reactos/lib/comctl32/tooltips.c
Modified: trunk/reactos/lib/comctl32/trackbar.c
Modified: trunk/reactos/lib/comctl32/treeview.c
Modified: trunk/reactos/lib/comctl32/updown.c

Modified: trunk/reactos/lib/comctl32/animate.c
--- trunk/reactos/lib/comctl32/animate.c	2005-11-17 17:34:22 UTC (rev 19295)
+++ trunk/reactos/lib/comctl32/animate.c	2005-11-17 19:36:54 UTC (rev 19296)
@@ -899,6 +899,7 @@
     case WM_TIMER:
         return ANIMATE_Timer(infoPtr);
 
+    case WM_PRINTCLIENT:
     case WM_PAINT:
         {
             /* the animation isn't playing, or has not decompressed

Modified: trunk/reactos/lib/comctl32/comboex.c
--- trunk/reactos/lib/comctl32/comboex.c	2005-11-17 17:34:22 UTC (rev 19295)
+++ trunk/reactos/lib/comctl32/comboex.c	2005-11-17 19:36:54 UTC (rev 19296)
@@ -1395,7 +1395,7 @@
     if (!item) {
         item = get_item_data(infoPtr, dis->itemID);
 	if (item == (CBE_ITEMDATA *)CB_ERR) {
-	    ERR("invalid item for id %d \n", dis->itemID);
+	    ERR("invalid item for id %d\n", dis->itemID);
 	    return 0;
 	}
     }

Modified: trunk/reactos/lib/comctl32/datetime.c
--- trunk/reactos/lib/comctl32/datetime.c	2005-11-17 17:34:22 UTC (rev 19295)
+++ trunk/reactos/lib/comctl32/datetime.c	2005-11-17 19:36:54 UTC (rev 19296)
@@ -1284,6 +1284,7 @@
     case WM_GETDLGCODE:
         return DLGC_WANTARROWS | DLGC_WANTCHARS;
 
+    case WM_PRINTCLIENT:
     case WM_PAINT:
         return DATETIME_Paint (infoPtr, (HDC)wParam);
 

Modified: trunk/reactos/lib/comctl32/header.c
--- trunk/reactos/lib/comctl32/header.c	2005-11-17 17:34:22 UTC (rev 19295)
+++ trunk/reactos/lib/comctl32/header.c	2005-11-17 19:36:54 UTC (rev 19296)
@@ -598,10 +598,99 @@
     nmitem.iImage = infoPtr->items[iItem].iImage;
 
     return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
-			       (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
+                               (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
 }
 
+/**
+ * Send Disp Info notification. 
+ *   depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA 
+ *   (so we handle the two cases only doing a specific cast for pszText).
+ *
+ * @param hwnd : hwnd header container handler
+ * @param mask : notification mask (usually HDI_TEXT or HDI_IMAGE)
+ * @param pDispInfo : NMHDDISPINFO structure (can be unicode or ansi)
+ * @param isW : TRUE if dispinfo is Unicode
+ */
+static BOOL
+HEADER_SendHeaderDispInfoNotify(HWND hwnd, INT iItem, INT mask, LPHDITEMW phdi, HEADER_ITEM* lpItem, BOOL isW)
+{
+    HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
+    BOOL ret;
+    BOOL convertToAnsi = FALSE;
+    BOOL convertToUnicode = FALSE;
+    BOOL isUnicodeNotify = FALSE;
+    NMHDDISPINFOW dispInfo;
 
+    if (mask & HDI_TEXT)
+    {
+        convertToAnsi = (isW && infoPtr->nNotifyFormat == NFR_ANSI);
+        convertToUnicode = (!isW && infoPtr->nNotifyFormat == NFR_UNICODE);
+    }
+    isUnicodeNotify = (isW && !convertToAnsi);
+    
+    memset(&dispInfo, 0, sizeof(NMHDDISPINFOW));
+    dispInfo.hdr.hwndFrom = hwnd;
+    dispInfo.hdr.idFrom   = GetWindowLongPtrW (hwnd, GWLP_ID);
+    if (isUnicodeNotify || convertToUnicode) 
+    {
+        dispInfo.hdr.code = HDN_GETDISPINFOW;
+    }
+    else
+    {
+        dispInfo.hdr.code = HDN_GETDISPINFOA;
+    }
+    dispInfo.iItem        = iItem;
+    dispInfo.mask         = mask;
+    /*
+    dispInfo.pszText      = Alloc(sizeof(WCHAR) * 260);
+    dispInfo.cchTextMax   = 260;
+    */
+    ret = (BOOL) SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 
+                              (WPARAM) dispInfo.hdr.idFrom, 
+                              (LPARAM) &dispInfo);
+
+    TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n", 
+          dispInfo.mask,
+          (isUnicodeNotify ? debugstr_w(dispInfo.pszText) : (LPSTR) dispInfo.pszText),
+          (void*) dispInfo.lParam);
+	  
+    if (dispInfo.mask & HDI_DI_SETITEM) 
+    {
+        if (dispInfo.mask & HDI_IMAGE) 
+        {
+            lpItem->iImage = dispInfo.iImage;
+        }
+        if (dispInfo.mask & HDI_TEXT) 
+        {
+            if (isUnicodeNotify || convertToUnicode)
+                Str_SetPtrW(&lpItem->pszText, (LPCWSTR)dispInfo.pszText);
+            else /*if (convertToAnsi || !isW)*/
+                Str_SetPtrAtoW(&lpItem->pszText, (LPCSTR)dispInfo.pszText);
+        }
+        
+        FIXME("NMHDDISPINFO returns with flags HDI_DI_SETITEM\n");
+    }
+    
+    if (NULL != phdi)
+    {
+        if ((phdi->mask & mask) & HDI_IMAGE) 
+        {
+            phdi->iImage = dispInfo.iImage;
+        }
+        if ((phdi->mask & mask) & HDI_TEXT) 
+        {
+            if (isUnicodeNotify)
+                Str_GetPtrW ((LPCWSTR)dispInfo.pszText, phdi->pszText, phdi->cchTextMax);
+            else if (convertToUnicode)
+                Str_GetPtrWtoA ((LPCWSTR)dispInfo.pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
+            else /*if (!isW) */
+                Str_GetPtrA ((LPCSTR)dispInfo.pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
+        }
+    }
+    return ret;
+}
+
+
 static BOOL
 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
 {
@@ -712,11 +801,9 @@
 
 
 static LRESULT
-HEADER_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
+HEADER_GetItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
 {
     HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
-    HDITEMA   *phdi = (HDITEMA*)lParam;
-    INT       nItem = (INT)wParam;
     HEADER_ITEM *lpItem;
 
     if (!phdi)
@@ -727,12 +814,10 @@
     if (phdi->mask == 0)
 	return TRUE;
 
-    if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem)) {
+    if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
         lpItem = NULL;
-    }
-    else {
+    else
         lpItem = &infoPtr->items[nItem];
-    }
 
     if (phdi->mask & HDI_BITMAP)
 	phdi->hbm = (lpItem != NULL) ? lpItem->hbm : 0;
@@ -746,86 +831,34 @@
     if (phdi->mask & HDI_LPARAM)
 	phdi->lParam = (lpItem != NULL) ? lpItem->lParam : 0;
 
-    if (phdi->mask & HDI_TEXT) {
-	if (lpItem == NULL) {
-	    *phdi->pszText = 0;
-	}
-	else if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
-	    if (lpItem->pszText)
-		WideCharToMultiByte (CP_ACP, 0, lpItem->pszText, -1,
-				     phdi->pszText, phdi->cchTextMax, NULL, NULL);
-	    else
-	        *phdi->pszText = 0;
-	}
-	else
-	    phdi->pszText = LPSTR_TEXTCALLBACKA;
+    if (phdi->mask & HDI_IMAGE) 
+    {
+        phdi->iImage = (lpItem != NULL) ? lpItem->iImage : 0;
+        if (lpItem->iImage == I_IMAGECALLBACK) 
+        {
+            HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, phdi, lpItem, bUnicode);
+        }
     }
 
-    if (phdi->mask & HDI_IMAGE)
-	phdi->iImage = (lpItem != NULL) ? lpItem->iImage : 0;
-
     if (phdi->mask & HDI_ORDER)
 	phdi->iOrder = (lpItem != NULL) ? lpItem->iOrder : 0;
 
-    return TRUE;
-}
-
-
-static LRESULT
-HEADER_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
-{
-    HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
-    HDITEMW   *phdi = (HDITEMW*)lParam;
-    INT       nItem = (INT)wParam;
-    HEADER_ITEM *lpItem;
-
-    if (!phdi)
-	return FALSE;
-
-    TRACE("[nItem=%d]\n", nItem);
-
-    if (phdi->mask == 0)
-	return TRUE;
-
-    if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem)) {
-        lpItem = NULL;
+    if (phdi->mask & HDI_TEXT)
+    {
+        if (lpItem == NULL) *phdi->pszText = 0;  /* null pointer check */
+        else if (lpItem->pszText == LPSTR_TEXTCALLBACKW) /* covers == TEXTCALLBACKA too */
+        {
+            HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, phdi, lpItem, bUnicode);
+        }
+        else
+        {
+            if (bUnicode)
+                Str_GetPtrW (lpItem->pszText, phdi->pszText, phdi->cchTextMax);
+            else
+                Str_GetPtrWtoA (lpItem->pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
+        }
     }
-    else {
-        lpItem = &infoPtr->items[nItem];
-    }
 
-    if (phdi->mask & HDI_BITMAP)
-	phdi->hbm = (lpItem != NULL) ? lpItem->hbm : 0;
-
-    if (phdi->mask & HDI_FORMAT)
-	phdi->fmt = (lpItem != NULL) ? lpItem->fmt : 0;
-
-    if (phdi->mask & HDI_WIDTH)
-	phdi->cxy = (lpItem != NULL) ? lpItem->cxy : 0;
-
-    if (phdi->mask & HDI_LPARAM)
-	phdi->lParam = (lpItem != NULL) ? lpItem->lParam : 0;
-
-    if (phdi->mask & HDI_TEXT) {
-	if (lpItem == NULL) {
-	    *phdi->pszText = 0;
-	}
-	else if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
-	    if (lpItem->pszText)
-	        lstrcpynW (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
-	    else
-	        *phdi->pszText = 0;
-	}
-	else
-	    phdi->pszText = LPSTR_TEXTCALLBACKW;
-    }
-
-    if (phdi->mask & HDI_IMAGE)
-	phdi->iImage = (lpItem != NULL) ? lpItem->iImage : 0;
-
-    if (phdi->mask & HDI_ORDER)
-	phdi->iOrder = (lpItem != NULL) ? lpItem->iOrder : 0;
-
     return TRUE;
 }
 
@@ -914,13 +947,11 @@
 
 
 static LRESULT
-HEADER_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
+HEADER_InsertItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
 {
     HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
-    HDITEMA   *phdi = (HDITEMA*)lParam;
-    INT       nItem = (INT)wParam;
     HEADER_ITEM *lpItem;
-    INT       len, iOrder;
+    INT       iOrder;
     UINT      i;
 
     if ((phdi == NULL) || (nItem < 0))
@@ -988,150 +1019,49 @@
     if (phdi->mask & HDI_WIDTH)
 	lpItem->cxy = phdi->cxy;
 
-    if (phdi->mask & HDI_TEXT) {
-	if (!phdi->pszText) /* null pointer check */
-	    phdi->pszText = "";
-	if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
-	    len = MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, NULL, 0);
-	    lpItem->pszText = Alloc( len*sizeof(WCHAR) );
-	    MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, lpItem->pszText, len);
-	}
-	else
-	    lpItem->pszText = LPSTR_TEXTCALLBACKW;
-    }
-
     if (phdi->mask & HDI_FORMAT)
 	lpItem->fmt = phdi->fmt;
 
     if (lpItem->fmt == 0)
 	lpItem->fmt = HDF_LEFT;
 
-    if (!(lpItem->fmt & HDF_STRING) && (phdi->mask & HDI_TEXT))
-      {
-	lpItem->fmt |= HDF_STRING;
-      }
     if (phdi->mask & HDI_BITMAP)
         lpItem->hbm = phdi->hbm;
 
     if (phdi->mask & HDI_LPARAM)
         lpItem->lParam = phdi->lParam;
 
-    if (phdi->mask & HDI_IMAGE)
-        lpItem->iImage = phdi->iImage;
-
-    lpItem->iOrder = iOrder;
-
-    HEADER_SetItemBounds (hwnd);
-
-    InvalidateRect(hwnd, NULL, FALSE);
-
-    return nItem;
-}
-
-
-static LRESULT
-HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
-{
-    HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
-    HDITEMW   *phdi = (HDITEMW*)lParam;
-    INT       nItem = (INT)wParam;
-    HEADER_ITEM *lpItem;
-    INT       len, iOrder;
-    UINT      i;
-
-    if ((phdi == NULL) || (nItem < 0))
-	return -1;
-
-    if (nItem > infoPtr->uNumItem)
-        nItem = infoPtr->uNumItem;
-
-    iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
-
-    if (infoPtr->uNumItem == 0) {
-        infoPtr->items = Alloc (sizeof (HEADER_ITEM));
-        infoPtr->order = Alloc(sizeof(INT));
-        infoPtr->uNumItem++;
+    if (phdi->mask & HDI_IMAGE) 
+    {
+        if (phdi->iImage != I_IMAGECALLBACK) 
+        {
+            lpItem->iImage = phdi->iImage;
+        } 
+        else 
+        {
+            lpItem->iImage = phdi->iImage;
+            HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, NULL, lpItem, bUnicode);
+        }
     }
-    else {
-        HEADER_ITEM *oldItems = infoPtr->items;
-        INT *oldOrder = infoPtr->order;
 
-        infoPtr->uNumItem++;
-        infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
-        if (nItem == 0) {
-            memcpy (&infoPtr->items[1], &oldItems[0],
-                    (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
+    if (phdi->mask & HDI_TEXT)
+    {
+	if (!phdi->pszText) phdi->pszText = '\0'; /* null pointer check */
+        if (phdi->pszText != LPSTR_TEXTCALLBACKW) /* covers != TEXTCALLBACKA too */
+        {
+            if (bUnicode)
+                Str_SetPtrW(&lpItem->pszText, phdi->pszText);
+            else
+                Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)phdi->pszText);
         }
-        else
+        else 
         {
-              /* pre insert copy */
-            if (nItem > 0) {
-                 memcpy (&infoPtr->items[0], &oldItems[0],
-                         nItem * sizeof(HEADER_ITEM));
-            }
-
-            /* post insert copy */
-            if (nItem < infoPtr->uNumItem - 1) {
-                memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
-                        (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
-            }
+            lpItem->pszText = phdi->pszText;
+            HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, NULL, lpItem, bUnicode);
         }
-
-        infoPtr->order = Alloc(infoPtr->uNumItem * sizeof(INT));
-        memcpy(infoPtr->order, oldOrder, iOrder * sizeof(INT));
-        infoPtr->order[iOrder] = nItem;
-        memcpy(&infoPtr->order[iOrder + 1], &oldOrder[iOrder],
-               (infoPtr->uNumItem - iOrder - 1) * sizeof(INT));
-
-        Free (oldItems);
-        Free(oldOrder);
+        lpItem->fmt |= HDF_STRING;
     }
 
-    for (i = 0; i < infoPtr->uNumItem; i++)
-    {
-        if (i != iOrder && infoPtr->order[i] >= nItem)
-            infoPtr->order[i]++;
-        infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
-    }
-
-    lpItem = &infoPtr->items[nItem];
-    lpItem->bDown = FALSE;
-
-    if (phdi->mask & HDI_WIDTH)
-	lpItem->cxy = phdi->cxy;
-
-    if (phdi->mask & HDI_TEXT) {
-	WCHAR wide_null_char = 0;
-	if (!phdi->pszText) /* null pointer check */
-	    phdi->pszText = &wide_null_char;
-	if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
-	    len = strlenW (phdi->pszText);
-	    lpItem->pszText = Alloc ((len+1)*sizeof(WCHAR));
-	    strcpyW (lpItem->pszText, phdi->pszText);
-	}
-	else
-	    lpItem->pszText = LPSTR_TEXTCALLBACKW;
-    }
-
-    if (phdi->mask & HDI_FORMAT)
-	lpItem->fmt = phdi->fmt;
-
-    if (lpItem->fmt == 0)
-	lpItem->fmt = HDF_LEFT;
-
-    if (!(lpItem->fmt &HDF_STRING) && (phdi->mask & HDI_TEXT))
-      {
-	lpItem->fmt |= HDF_STRING;
-      }
-    if (phdi->mask & HDI_BITMAP)
-        lpItem->hbm = phdi->hbm;
-
-    if (phdi->mask & HDI_LPARAM)
-        lpItem->lParam = phdi->lParam;
-
-    if (phdi->mask & HDI_IMAGE)
-        lpItem->iImage = phdi->iImage;
-
     lpItem->iOrder = iOrder;
 
     HEADER_SetItemBounds (hwnd);
@@ -1207,11 +1137,9 @@
 }
 
 static LRESULT
-HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
+HEADER_SetItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
 {
     HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
-    HDITEMA *phdi = (HDITEMA*)lParam;
-    INT nItem = (INT)wParam;
     HEADER_ITEM *lpItem;
 
     if (phdi == NULL)
@@ -1221,7 +1149,8 @@
 
     TRACE("[nItem=%d]\n", nItem);
 
-	if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem, phdi->mask))
+    if (HEADER_SendHeaderNotify (hwnd, bUnicode ? HDN_ITEMCHANGINGW : HDN_ITEMCHANGINGA,
+                                 nItem, phdi->mask))
 	return FALSE;
 
     lpItem = &infoPtr->items[nItem];
@@ -1234,113 +1163,46 @@
     if (phdi->mask & HDI_LPARAM)
 	lpItem->lParam = phdi->lParam;
 
-    if (phdi->mask & HDI_TEXT) {
-	if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
-	    if (lpItem->pszText) {
-		Free (lpItem->pszText);
-		lpItem->pszText = NULL;
-	    }
-	    if (phdi->pszText) {
-		INT len = MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,NULL,0);
-		lpItem->pszText = Alloc( len*sizeof(WCHAR) );
-		MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,lpItem->pszText,len);
-	    }
-	}
-	else
-	    lpItem->pszText = LPSTR_TEXTCALLBACKW;
-    }
-
     if (phdi->mask & HDI_WIDTH)
 	lpItem->cxy = phdi->cxy;
 
-    if (phdi->mask & HDI_IMAGE)
-	lpItem->iImage = phdi->iImage;
-
-    if (phdi->mask & HDI_ORDER)
-      {
-        INT i, nMin, nMax;
-        
-        if (lpItem->iOrder < phdi->iOrder)
+    if (phdi->mask & HDI_IMAGE) 
+    {
+        if (phdi->iImage != I_IMAGECALLBACK) 
         {
-            memmove(&infoPtr->order[lpItem->iOrder],
-                   &infoPtr->order[lpItem->iOrder + 1],
-                   (phdi->iOrder - lpItem->iOrder) * sizeof(INT));
-        }
-        if (phdi->iOrder < lpItem->iOrder)
+            lpItem->iImage = phdi->iImage;
+        } 
+        else 
         {
-            memmove(&infoPtr->order[phdi->iOrder + 1],
-                    &infoPtr->order[phdi->iOrder],
-                    (lpItem->iOrder - phdi->iOrder) * sizeof(INT));
+            lpItem->iImage = phdi->iImage;
+            HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, NULL, lpItem, bUnicode);
         }
-        infoPtr->order[phdi->iOrder] = nItem;
-        nMin = min(lpItem->iOrder, phdi->iOrder);
-        nMax = max(lpItem->iOrder, phdi->iOrder);
-        for (i = nMin; i <= nMax; i++)
-        {
-            infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
-        }
-      }
+    }
 
-    HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem, phdi->mask);
-
-    HEADER_SetItemBounds (hwnd);
-
-    InvalidateRect(hwnd, NULL, FALSE);
-
-    return TRUE;
-}
-
-
-static LRESULT
-HEADER_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
-{
-    HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
-    HDITEMW *phdi = (HDITEMW*)lParam;
-    INT nItem = (INT)wParam;
-    HEADER_ITEM *lpItem;
-
-    if (phdi == NULL)
-	return FALSE;
-    if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
-        return FALSE;
-
-    TRACE("[nItem=%d]\n", nItem);
-
-	if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask))
-	return FALSE;
-
-    lpItem = &infoPtr->items[nItem];
-    if (phdi->mask & HDI_BITMAP)
-	lpItem->hbm = phdi->hbm;
-
-    if (phdi->mask & HDI_FORMAT)
-	lpItem->fmt = phdi->fmt;
-
-    if (phdi->mask & HDI_LPARAM)
-	lpItem->lParam = phdi->lParam;
-
-    if (phdi->mask & HDI_TEXT) {
-	if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
-	    if (lpItem->pszText) {
-		Free (lpItem->pszText);
-		lpItem->pszText = NULL;
-	    }
-	    if (phdi->pszText) {
-		INT len = strlenW (phdi->pszText);
-		lpItem->pszText = Alloc ((len+1)*sizeof(WCHAR));
-		strcpyW (lpItem->pszText, phdi->pszText);
-	    }
+    if (phdi->mask & HDI_TEXT)
+    {
+        if (phdi->pszText != LPSTR_TEXTCALLBACKW) /* covers != TEXTCALLBACKA too */
+        {
+            if (lpItem->pszText)
+            {
+                Free(lpItem->pszText);
+                lpItem->pszText = NULL;
+            }
+            if (phdi->pszText)
+            {
+                if (bUnicode)
+                    Str_SetPtrW(&lpItem->pszText, phdi->pszText);
+                else
+                    Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)phdi->pszText);
+            }
 	}
-	else
-	    lpItem->pszText = LPSTR_TEXTCALLBACKW;
+	else 
+	{
+            lpItem->pszText = phdi->pszText;
+            HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, NULL, lpItem, bUnicode);
+        }  
     }
 
-    if (phdi->mask & HDI_WIDTH)
-	lpItem->cxy = phdi->cxy;
-
-    if (phdi->mask & HDI_IMAGE)
-	lpItem->iImage = phdi->iImage;
-
     if (phdi->mask & HDI_ORDER)
       {
         INT i, nMin, nMax;
@@ -1366,7 +1228,8 @@
         }
       }
 
-    HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDW, nItem, phdi->mask);
+    HEADER_SendHeaderNotify (hwnd, bUnicode ? HDN_ITEMCHANGEDW : HDN_ITEMCHANGEDA,
+                             nItem, phdi->mask);
 
     HEADER_SetItemBounds (hwnd);
 
@@ -1889,10 +1752,8 @@
 	    return HEADER_GetImageList (hwnd);
 
 	case HDM_GETITEMA:
-	    return HEADER_GetItemA (hwnd, wParam, lParam);
-
 	case HDM_GETITEMW:
-	    return HEADER_GetItemW (hwnd, wParam, lParam);
+	    return HEADER_GetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_GETITEMW);
 
 	case HDM_GETITEMCOUNT:
 	    return HEADER_GetItemCount (hwnd);
@@ -1910,10 +1771,8 @@
 	    return HEADER_HitTest (hwnd, wParam, lParam);
 
 	case HDM_INSERTITEMA:
-	    return HEADER_InsertItemA (hwnd, wParam, lParam);
-
 	case HDM_INSERTITEMW:
-	    return HEADER_InsertItemW (hwnd, wParam, lParam);
+	    return HEADER_InsertItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_INSERTITEMW);
 
 	case HDM_LAYOUT:
 	    return HEADER_Layout (hwnd, wParam, lParam);
@@ -1932,10 +1791,8 @@
 	    return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
 
 	case HDM_SETITEMA:
-	    return HEADER_SetItemA (hwnd, wParam, lParam);
-
 	case HDM_SETITEMW:
-	    return HEADER_SetItemW (hwnd, wParam, lParam);
+	    return HEADER_SetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_SETITEMW);
 
 	case HDM_SETORDERARRAY:
 	    return HEADER_SetOrderArray(hwnd, wParam, lParam);
@@ -1982,6 +1839,7 @@
         case WM_THEMECHANGED:
             return HEADER_ThemeChanged (hwnd);
 
+        case WM_PRINTCLIENT:
         case WM_PAINT:
             return HEADER_Paint (hwnd, wParam);
 

Modified: trunk/reactos/lib/comctl32/hotkey.c
--- trunk/reactos/lib/comctl32/hotkey.c	2005-11-17 17:34:22 UTC (rev 19295)
+++ trunk/reactos/lib/comctl32/hotkey.c	2005-11-17 19:36:54 UTC (rev 19296)
@@ -516,6 +516,7 @@
 	case WM_NCCREATE:
 	    return HOTKEY_NCCreate (hwnd, (LPCREATESTRUCTW)lParam);
 
+	case WM_PRINTCLIENT:
 	case WM_PAINT:
 	    HOTKEY_Paint(infoPtr, (HDC)wParam);
 	    return 0;

Modified: trunk/reactos/lib/comctl32/imagelist.c
--- trunk/reactos/lib/comctl32/imagelist.c	2005-11-17 17:34:22 UTC (rev 19295)
+++ trunk/reactos/lib/comctl32/imagelist.c	2005-11-17 19:36:54 UTC (rev 19296)
@@ -1581,8 +1581,7 @@
  *
  * Creates an image list from a bitmap, icon or cursor.
  *
- * SEE
- *     ImageList_LoadImageW ()
+ * See ImageList_LoadImageW.
  */
 
 HIMAGELIST WINAPI

Modified: trunk/reactos/lib/comctl32/listview.c
--- trunk/reactos/lib/comctl32/listview.c	2005-11-17 17:34:22 UTC (rev 19295)
+++ trunk/reactos/lib/comctl32/listview.c	2005-11-17 19:36:54 UTC (rev 19296)
@@ -3274,6 +3274,9 @@
 {
     TRACKMOUSEEVENT trackinfo;
 
+    if (!(fwKeys & MK_LBUTTON))
+        infoPtr->bLButtonDown = FALSE;
+
     if (infoPtr->bLButtonDown && DragDetect(infoPtr->hwndSelf, infoPtr->ptClickPos))
     {
         LVHITTESTINFO lvHitTestInfo;
@@ -4189,7 +4192,7 @@
     HDC hdc, hdcOrig;
     HBITMAP hbmp, hOldbmp;
     HIMAGELIST dragList = 0;
-    TRACE("iItem=%d Count=%d \n", iItem, infoPtr->nItemCount);
+    TRACE("iItem=%d Count=%d\n", iItem, infoPtr->nItemCount);
 
     if (iItem < 0 || iItem >= infoPtr->nItemCount)
         return 0;
@@ -5137,7 +5140,7 @@
  *
  * NOTE:
  *   This is the internal 'GetItem' interface -- it tries to
- *   be smart, and avoids text copies, if possible, by modifing
+ *   be smart and avoid text copies, if possible, by modifying
  *   lpLVItem->pszText to point to the text string. Please note
  *   that this is not always possible (e.g. OWNERDATA), so on
  *   entry you *must* supply valid values for pszText, and cchTextMax.
@@ -5612,6 +5615,7 @@
 {
     POINT Position;
     LVITEMW lvItem;
+    INT nColumn = lprc->top;
     
     if (!lprc) return FALSE;
 
@@ -5624,9 +5628,11 @@
 
     if (!LISTVIEW_GetItemPosition(infoPtr, nItem, &Position)) return FALSE;
 
+    if (nColumn < 0 || nColumn >= DPA_GetPtrCount(infoPtr->hdpaColumns)) return FALSE;
+
     lvItem.mask = 0;
     lvItem.iItem = nItem;
-    lvItem.iSubItem = lprc->top;
+    lvItem.iSubItem = nColumn;
     
     if (lvItem.mask && !LISTVIEW_GetItemW(infoPtr, &lvItem)) return FALSE;
     switch(lprc->left)

Modified: trunk/reactos/lib/comctl32/monthcal.c
--- trunk/reactos/lib/comctl32/monthcal.c	2005-11-17 17:34:22 UTC (rev 19295)
+++ trunk/reactos/lib/comctl32/monthcal.c	2005-11-17 19:36:54 UTC (rev 19296)
@@ -2007,6 +2007,7 @@
   case WM_LBUTTONUP:
     return MONTHCAL_LButtonUp(infoPtr, lParam);
 
+  case WM_PRINTCLIENT:
   case WM_PAINT:
     return MONTHCAL_Paint(infoPtr, wParam);
 

Modified: trunk/reactos/lib/comctl32/pager.c
--- trunk/reactos/lib/comctl32/pager.c	2005-11-17 17:34:22 UTC (rev 19295)
+++ trunk/reactos/lib/comctl32/pager.c	2005-11-17 19:36:54 UTC (rev 19296)
@@ -34,6 +34,8 @@
  *      PGS_DRAGNDROP
  *    Notifications:
  *      PGN_HOTITEMCHANGE
+ *    Messages:
+ *      WM_PRINT and/or WM_PRINTCLIENT
  *
  * TESTING:
  *    Tested primarily with the controlspy Pager application.

Modified: trunk/reactos/lib/comctl32/progress.c
--- trunk/reactos/lib/comctl32/progress.c	2005-11-17 17:34:22 UTC (rev 19295)
+++ trunk/reactos/lib/comctl32/progress.c	2005-11-17 19:36:54 UTC (rev 19296)
@@ -627,6 +627,7 @@
     case WM_SETFONT:
         return (LRESULT)PROGRESS_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
 
+    case WM_PRINTCLIENT:
     case WM_PAINT:
         return PROGRESS_Paint (infoPtr, (HDC)wParam);
 

Modified: trunk/reactos/lib/comctl32/propsheet.c
--- trunk/reactos/lib/comctl32/propsheet.c	2005-11-17 17:34:22 UTC (rev 19295)
+++ trunk/reactos/lib/comctl32/propsheet.c	2005-11-17 19:36:54 UTC (rev 19296)
@@ -3455,6 +3455,7 @@
       return TRUE;
     }
 
+    case WM_PRINTCLIENT:
     case WM_PAINT:
       PROPSHEET_Paint(hwnd, (HDC)wParam);
       return TRUE;

Modified: trunk/reactos/lib/comctl32/rebar.c
--- trunk/reactos/lib/comctl32/rebar.c	2005-11-17 17:34:22 UTC (rev 19295)
+++ trunk/reactos/lib/comctl32/rebar.c	2005-11-17 19:36:54 UTC (rev 19296)
@@ -50,7 +50,6 @@
  *   - WM_LBUTTONDBLCLK
  *   - WM_MEASUREITEM
  *   - WM_PALETTECHANGED
- *   - WM_PRINTCLIENT
  *   - WM_QUERYNEWPALETTE
  *   - WM_RBUTTONDOWN
  *   - WM_RBUTTONUP
@@ -4768,11 +4767,11 @@
         case WM_NOTIFYFORMAT:
 	    return REBAR_NotifyFormat (infoPtr, wParam, lParam);
 
+	case WM_PRINTCLIENT:
 	case WM_PAINT:
 	    return REBAR_Paint (infoPtr, wParam, lParam);
 
 /*      case WM_PALETTECHANGED: supported according to ControlSpy */
-/*      case WM_PRINTCLIENT:    supported according to ControlSpy */
 /*      case WM_QUERYNEWPALETTE:supported according to ControlSpy */
 /*      case WM_RBUTTONDOWN:    supported according to ControlSpy */
 /*      case WM_RBUTTONUP:      supported according to ControlSpy */

Modified: trunk/reactos/lib/comctl32/status.c
--- trunk/reactos/lib/comctl32/status.c	2005-11-17 17:34:22 UTC (rev 19295)
+++ trunk/reactos/lib/comctl32/status.c	2005-11-17 19:36:54 UTC (rev 19296)
@@ -1342,6 +1342,7 @@
 	case WM_NOTIFYFORMAT:
 	    return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
 
+	case WM_PRINTCLIENT:
 	case WM_PAINT:
 	    return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
 

Modified: trunk/reactos/lib/comctl32/string.c
--- trunk/reactos/lib/comctl32/string.c	2005-11-17 17:34:22 UTC (rev 19295)
+++ trunk/reactos/lib/comctl32/string.c	2005-11-17 19:36:54 UTC (rev 19296)
@@ -22,6 +22,9 @@
  *
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <stdarg.h>
 #include <string.h>
 #include <stdlib.h> /* atoi */
@@ -171,13 +174,52 @@
   return NULL;
 }
 
+/**************************************************************************
+ * StrCmpNIA [COMCTL32.353]
+ *
+ * Compare two strings, up to a maximum length, ignoring case.
+ *
+ * PARAMS
+ *  lpszStr  [I] First string to compare
+ *  lpszComp [I] Second string to compare
+ *  iLen     [I] Maximum number of chars to compare.
+ *
+ * RETURNS
+ *  An integer less than, equal to or greater than 0, indicating that
+ *  lpszStr is less than, the same, or greater than lpszComp.
+ */
+INT WINAPI StrCmpNIA(LPCSTR lpszStr, LPCSTR lpszComp, INT iLen)
+{
+  INT iRet;
+
+  TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
+
+  iRet = CompareStringA(GetThreadLocale(), NORM_IGNORECASE, lpszStr, iLen, lpszComp, iLen);
+  return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
+}
+
 /*************************************************************************
+ * StrCmpNIW	[COMCTL32.361]
+ *
+ * See StrCmpNIA.
+ */
+INT WINAPI StrCmpNIW(LPCWSTR lpszStr, LPCWSTR lpszComp, INT iLen)
+{
+  INT iRet;
+
+  TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr), debugstr_w(lpszComp), iLen);
+
+  iRet = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, lpszStr, iLen, lpszComp, iLen);
+  return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
+}
+
+/*************************************************************************
  * COMCTL32_StrStrHelperA
  *
  * Internal implementation of StrStrA/StrStrIA
  */
 static LPSTR COMCTL32_StrStrHelperA(LPCSTR lpszStr, LPCSTR lpszSearch,
-                                    int (*pStrCmpFn)(LPCSTR,LPCSTR,size_t))
+                                    INT (WINAPI *pStrCmpFn)(LPCSTR,LPCSTR,INT))
 {
   size_t iLen;
 
@@ -201,7 +243,7 @@
  * Internal implementation of StrStrW/StrStrIW
  */
 static LPWSTR COMCTL32_StrStrHelperW(LPCWSTR lpszStr, LPCWSTR lpszSearch,
-                                     int (*pStrCmpFn)(LPCWSTR,LPCWSTR,int))
+                                     INT (WINAPI *pStrCmpFn)(LPCWSTR,LPCWSTR,INT))
 {
   int iLen;
 
@@ -235,7 +277,7 @@
 {
   TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
 
-  return COMCTL32_StrStrHelperA(lpszStr, lpszSearch, strncasecmp);
+  return COMCTL32_StrStrHelperA(lpszStr, lpszSearch, StrCmpNIA);
 }
 
 /**************************************************************************
@@ -264,7 +306,7 @@
 {
   TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSearch));
 
-  return COMCTL32_StrStrHelperW(lpszStr, lpszSearch, (int (*)(LPCWSTR,LPCWSTR,int)) wcsnicmp);
+  return COMCTL32_StrStrHelperW(lpszStr, lpszSearch, StrCmpNIW);
 }
 
 /**************************************************************************
@@ -365,45 +407,6 @@
 }
 
 /**************************************************************************
- * StrCmpNIA [COMCTL32.353]
- *
- * Compare two strings, up to a maximum length, ignoring case.
- *
- * PARAMS
- *  lpszStr  [I] First string to compare
- *  lpszComp [I] Second string to compare
- *  iLen     [I] Maximum number of chars to compare.
- *
- * RETURNS
- *  An integer less than, equal to or greater than 0, indicating that
- *  lpszStr is less than, the same, or greater than lpszComp.
- */
-int WINAPI StrCmpNIA(LPCSTR lpszStr, LPCSTR lpszComp, int iLen)
-{
-  INT iRet;
-
-  TRACE("(%s,%s,%i)\n", debugstr_a(lpszStr), debugstr_a(lpszComp), iLen);
-
-  iRet = CompareStringA(GetThreadLocale(), NORM_IGNORECASE, lpszStr, iLen, lpszComp, iLen);
-  return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
-}
-
-/*************************************************************************
- * StrCmpNIW	[COMCTL32.361]
- *
- * See StrCmpNIA.
- */
-INT WINAPI StrCmpNIW(LPCWSTR lpszStr, LPCWSTR lpszComp, int iLen)
-{
-  INT iRet;
-
-  TRACE("(%s,%s,%i)\n", debugstr_w(lpszStr), debugstr_w(lpszComp), iLen);
-
-  iRet = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, lpszStr, iLen, lpszComp, iLen);
-  return iRet == CSTR_LESS_THAN ? -1 : iRet == CSTR_GREATER_THAN ? 1 : 0;
-}
-
-/**************************************************************************
  * StrCmpNW [COMCTL32.360]
  *
  * See StrCmpNA.
@@ -501,7 +504,7 @@
 {
   TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
 
[truncated at 1000 lines; 157 more skipped]