[2/3] comctl32/listview: convert header notifications to ANSI in place

Daniel Jelinski djelinski1 at gmail.com
Sat Dec 8 08:08:39 CST 2012


-------------- next part --------------
From 7ec5de21787222fc493afd88cdbed7c722f57ab6 Mon Sep 17 00:00:00 2001
From: Daniel Jelinski <djelinski1 at gmail.com>
Date: Sat, 8 Dec 2012 09:08:02 +0100
Subject: comctl32/listview: convert header notifications to ANSI in place

Listview forwards header notifications to its parent, converting them
from Unicode to ANSI, if it needs to. Native converts the notification
structures in place. This patch causes Wine to do the same.
---
 dlls/comctl32/listview.c       |   47 +++++++++++++++++++--------------------
 dlls/comctl32/tests/listview.c |    2 -
 2 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c
index 4bac508..c85470e 100644
--- a/dlls/comctl32/listview.c
+++ b/dlls/comctl32/listview.c
@@ -774,13 +774,11 @@ static int get_ansi_notification(UINT unicodeNotificationCode)
 }
 
 /* forwards header notifications to listview parent */
-static LRESULT notify_forward_header(const LISTVIEW_INFO *infoPtr, const NMHEADERW *lpnmh)
+static LRESULT notify_forward_header(const LISTVIEW_INFO *infoPtr, NMHEADERW *lpnmhW)
 {
-    NMHEADERA nmhA;
-    HDITEMA hditema;
-    HD_TEXTFILTERA textfilter;
-    LPSTR text = NULL, filter = NULL;
+    LPCWSTR text = NULL, filter = NULL;
     LRESULT ret;
+    NMHEADERA *lpnmh = (NMHEADERA*) lpnmhW;
 
     /* on unicode format exit earlier */
     if (infoPtr->notifyFormat == NFR_UNICODE)
@@ -789,37 +787,38 @@ static LRESULT notify_forward_header(const LISTVIEW_INFO *infoPtr, const NMHEADE
 
     /* header always supplies unicode notifications,
        all we have to do is to convert strings to ANSI */
-    nmhA = *(const NMHEADERA*)lpnmh;
     if (lpnmh->pitem)
     {
-        hditema = *(HDITEMA*)lpnmh->pitem;
-        nmhA.pitem = &hditema;
         /* convert item text */
         if (lpnmh->pitem->mask & HDI_TEXT)
         {
-            hditema.pszText = NULL;
-            Str_SetPtrWtoA(&hditema.pszText, lpnmh->pitem->pszText);
-            text = hditema.pszText;
+            text = (LPCWSTR)lpnmh->pitem->pszText;
+            Str_SetPtrWtoA(&lpnmh->pitem->pszText, text);
         }
         /* convert filter text */
         if ((lpnmh->pitem->mask & HDI_FILTER) && (lpnmh->pitem->type == HDFT_ISSTRING) &&
              lpnmh->pitem->pvFilter)
         {
-            hditema.pvFilter = &textfilter;
-            textfilter = *(HD_TEXTFILTERA*)(lpnmh->pitem->pvFilter);
-            textfilter.pszText = NULL;
-            Str_SetPtrWtoA(&textfilter.pszText, ((HD_TEXTFILTERW*)lpnmh->pitem->pvFilter)->pszText);
-            filter = textfilter.pszText;
+            filter = (LPCWSTR)((HD_TEXTFILTERA*)lpnmh->pitem->pvFilter)->pszText;
+            Str_SetPtrWtoA(&((HD_TEXTFILTERA*)lpnmh->pitem->pvFilter)->pszText, filter);
         }
     }
-    nmhA.hdr.code = get_ansi_notification(lpnmh->hdr.code);
+    lpnmh->hdr.code = get_ansi_notification(lpnmh->hdr.code);
 
-    ret = SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhA.hdr.idFrom,
-                       (LPARAM)&nmhA);
+    ret = SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, lpnmh->hdr.idFrom,
+                       (LPARAM)lpnmh);
 
     /* cleanup */
-    Free(text);
-    Free(filter);
+    if(text)
+    {
+        Free(lpnmh->pitem->pszText);
+        lpnmh->pitem->pszText = (LPSTR)text;
+    }
+    if(filter)
+    {
+        Free(((HD_TEXTFILTERA*)lpnmh->pitem->pvFilter)->pszText);
+        ((HD_TEXTFILTERA*)lpnmh->pitem->pvFilter)->pszText = (LPSTR)filter;
+    }
 
     return ret;
 }
@@ -10236,9 +10235,9 @@ static LRESULT LISTVIEW_NCDestroy(LISTVIEW_INFO *infoPtr)
  * RETURN:
  * Zero
  */
-static LRESULT LISTVIEW_Notify(LISTVIEW_INFO *infoPtr, const NMHDR *lpnmhdr)
+static LRESULT LISTVIEW_Notify(LISTVIEW_INFO *infoPtr, NMHDR *lpnmhdr)
 {
-    const NMHEADERW *lpnmh;
+    NMHEADERW *lpnmh;
     
     TRACE("(lpnmhdr=%p)\n", lpnmhdr);
 
@@ -10246,7 +10245,7 @@ static LRESULT LISTVIEW_Notify(LISTVIEW_INFO *infoPtr, const NMHDR *lpnmhdr)
 
     /* remember: HDN_LAST < HDN_FIRST */
     if (lpnmhdr->code > HDN_FIRST || lpnmhdr->code < HDN_LAST) return 0;
-    lpnmh = (const NMHEADERW *)lpnmhdr;
+    lpnmh = (NMHEADERW *)lpnmhdr;
 
     if (lpnmh->iItem < 0 || lpnmh->iItem >= DPA_GetPtrCount(infoPtr->hdpaColumns)) return 0;
 
diff --git a/dlls/comctl32/tests/listview.c b/dlls/comctl32/tests/listview.c
index 2622cc3..fd31eb8 100644
--- a/dlls/comctl32/tests/listview.c
+++ b/dlls/comctl32/tests/listview.c
@@ -4987,7 +4987,6 @@ static void test_header_notification2(void)
     ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
     ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_click_seq,
                 "header notify, parent", FALSE);
-    todo_wine
     ok(nmhdr.hdr.code == HDN_ITEMCLICKA, "Expected ANSI notification code\n");
     flush_sequences(sequences, NUM_MSG_SEQUENCES);
     nmhdr.hdr.code = HDN_ITEMDBLCLICKW;
@@ -5000,7 +4999,6 @@ static void test_header_notification2(void)
     ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
     ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_divider_dclick_seq,
                 "header notify, parent", TRUE);
-    todo_wine
     ok(nmhdr.hdr.code == HDN_DIVIDERDBLCLICKA, "Expected ANSI notification code\n");
     flush_sequences(sequences, NUM_MSG_SEQUENCES);
     nmhdr.hdr.code = HDN_BEGINTRACKW;
-- 
1.7.5.4


More information about the wine-patches mailing list