listview: fix notify_dispinfoT for notify msg format

Dimitrie O. Paun dpaun at rogers.com
Sun Oct 31 18:38:03 CST 2004


ChangeLog
    Send notification messages in the format dictated by
    infoPtr->notifyFormat. This in effect reverts to the 
    behaviour we had before this patch by Aric:
        http://cvs.winehq.com/patch.py?id=6394


Index: dlls/comctl32/listview.c
===================================================================
RCS file: /var/cvs/wine/dlls/comctl32/listview.c,v
retrieving revision 1.394
diff -u -r1.394 listview.c
--- dlls/comctl32/listview.c	2 Sep 2004 23:00:53 -0000	1.394
+++ dlls/comctl32/listview.c	1 Nov 2004 00:21:13 -0000
@@ -818,10 +818,8 @@
 }
 
 /*
-  With testing on Windows 2000 it looks like the notify format
-  has nothing to do with this message. It ALWAYS seems to be
-  in ansi format.
-
+  Send notification. depends on dispinfoW having same
+  structure as dispinfoA.
   infoPtr : listview struct
   notificationCode : *Unicode* notification code
   pdi : dispinfo structure (can be unicode or ansi)
@@ -830,32 +828,40 @@
 static BOOL notify_dispinfoT(LISTVIEW_INFO *infoPtr, INT notificationCode, LPNMLVDISPINFOW pdi, BOOL isW)
 {
     BOOL bResult = FALSE;
-    BOOL convertToAnsi = FALSE;
-    INT cchTempBufMax = 0, savCchTextMax = 0;
+    BOOL convertToAnsi = FALSE, convertToUnicode = FALSE;
+    INT cchTempBufMax = 0, savCchTextMax = 0, realNotifCode;
     LPWSTR pszTempBuf = NULL, savPszText = NULL;
 
     if ((pdi->item.mask & LVIF_TEXT) && is_textT(pdi->item.pszText, isW))
-	    convertToAnsi = isW;
+    {
+	convertToAnsi = (isW && infoPtr->notifyFormat == NFR_ANSI);
+	convertToUnicode = (!isW && infoPtr->notifyFormat == NFR_UNICODE);
+    }
 
-    if (convertToAnsi)
+    if (convertToAnsi || convertToUnicode)
     {
 	if (notificationCode != LVN_GETDISPINFOW)
-	{
-            cchTempBufMax = WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText,
-                                                -1, NULL, 0, NULL, NULL);
-        }
-	else
-	{
-	    cchTempBufMax = pdi->item.cchTextMax;
-	    *pdi->item.pszText = 0; /* make sure we don't process garbage */
-	}
+ 	{
+ 	    cchTempBufMax = convertToUnicode ?
+       		MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pdi->item.pszText, -1, NULL, 0):
+       		WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText, -1, NULL, 0, NULL, NULL);
+	}
+ 	else
+ 	{
+ 	    cchTempBufMax = pdi->item.cchTextMax;
+ 	    *pdi->item.pszText = 0; /* make sure we don't process garbage */
+ 	}
 
-        pszTempBuf = HeapAlloc(GetProcessHeap(), 0, sizeof(CHAR) *
-                               cchTempBufMax);
+	pszTempBuf = HeapAlloc(GetProcessHeap(), 0,
+	    (convertToUnicode ? sizeof(WCHAR) : sizeof(CHAR)) * cchTempBufMax);
         if (!pszTempBuf) return FALSE;
 
-        WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText, -1, (LPSTR)
-                             pszTempBuf, cchTempBufMax, NULL, NULL);
+	if (convertToUnicode)
+	    MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pdi->item.pszText, -1,
+	                        pszTempBuf, cchTempBufMax);
+	else
+	    WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText, -1, (LPSTR) pszTempBuf,
+	                        cchTempBufMax, NULL, NULL);
 
         savCchTextMax = pdi->item.cchTextMax;
         savPszText = pdi->item.pszText;
@@ -863,16 +869,21 @@
         pdi->item.cchTextMax = cchTempBufMax;
     }
 
-    TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi->item, infoPtr->notifyFormat !=
-           NFR_ANSI));
-
-    bResult = notify_hdr(infoPtr, get_ansi_notification(notificationCode),
-                        (LPNMHDR)pdi);
-
-    if (convertToAnsi)
-    {
-        MultiByteToWideChar(CP_ACP, 0, (LPSTR) pdi->item.pszText, -1,
-                            savPszText, savCchTextMax);
+    if (infoPtr->notifyFormat == NFR_ANSI)
+	realNotifCode = get_ansi_notification(notificationCode);
+    else
+	realNotifCode = notificationCode;
+    TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi->item, infoPtr->notifyFormat != NFR_ANSI));
+    bResult = notify_hdr(infoPtr, realNotifCode, &pdi->hdr);
+
+    if (convertToUnicode || convertToAnsi)
+    {
+	if (convertToUnicode) /* note : pointer can be changed by app ! */
+ 	    WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText, -1, (LPSTR) savPszText,
+                                savCchTextMax, NULL, NULL);
+	else
+	    MultiByteToWideChar(CP_ACP, 0, (LPSTR) pdi->item.pszText, -1,
+	                        savPszText, savCchTextMax);
         pdi->item.pszText = savPszText; /* restores our buffer */
         pdi->item.cchTextMax = savCchTextMax;
         HeapFree(GetProcessHeap(), 0, pszTempBuf);



More information about the wine-patches mailing list