--- listview.c.orig Fri Jan 18 19:05:35 2002 +++ listview.c Mon Jan 28 22:38:45 2002 @@ -292,7 +292,7 @@ pnmh->idFrom = GetWindowLongW(self, GWL_ID); pnmh->code = code; return (BOOL)SendMessageW(GetParent(self), WM_NOTIFY, - (WPARAM)pnmh->code, (LPARAM)pnmh); + (WPARAM)pnmh->idFrom, (LPARAM)pnmh); } static inline BOOL hdr_notify(HWND self, INT code) @@ -306,46 +306,80 @@ return notify(self, code, (LPNMHDR)plvnm); } -static BOOL dispinfo_notifyT(HWND self, INT code, LPNMLVDISPINFOW pdi, BOOL isW) +static int get_ansi_notification(INT unicodeNotificationCode) +{ + if (unicodeNotificationCode == LVN_ENDLABELEDITW) + return LVN_ENDLABELEDITA; + if (unicodeNotificationCode == LVN_BEGINLABELEDITW) + return LVN_BEGINLABELEDITA; + if (unicodeNotificationCode == LVN_GETDISPINFOW) + return LVN_GETDISPINFOA; + + return unicodeNotificationCode; +} + +static BOOL dispinfo_notifyT(HWND self, INT notificationCode, LPNMLVDISPINFOW pdi, BOOL isW) { LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(self, 0); BOOL bResult = FALSE; NMLVDISPINFOW diw; + BOOL convertToAnsi = FALSE, convertToUnicode = FALSE; + INT notifCode; - TRACE("(self=%x, code=%x, pdi=%p, isW=%d)\n", self, code, pdi, isW); + TRACE("(self=%x, code=%x, pdi=%p, isW=%d)\n", self, notificationCode, pdi, isW); TRACE(" notifyFormat=%s\n", infoPtr->notifyFormat == NFR_UNICODE ? "NFR_UNICODE" : infoPtr->notifyFormat == NFR_ANSI ? "NFR_ANSI" : "(not set)"); - if (isW && infoPtr->notifyFormat == NFR_UNICODE) - return notify(self, code, (LPNMHDR)pdi); - if (!isW && infoPtr->notifyFormat == NFR_ANSI) - return notify(self, code, (LPNMHDR)pdi); - if (!is_textT(pdi->item.pszText, isW)) - return notify(self, code, (LPNMHDR)pdi); - if (isW && *pdi->item.pszText == 0) - return notify(self, code, (LPNMHDR)pdi); - if (!isW && *((LPCSTR)pdi->item.pszText) == 0) + if (infoPtr->notifyFormat == NFR_ANSI) + notifCode = get_ansi_notification(notificationCode); + else + notifCode = notificationCode; + + if (is_textT(pdi->item.pszText, isW)) { - *pdi->item.pszText = 0; /* make sure we have enough zeros... */ - return notify(self, code, (LPNMHDR)pdi); + if (isW && infoPtr->notifyFormat == NFR_ANSI) + convertToAnsi = TRUE; + if (!isW && infoPtr->notifyFormat == NFR_UNICODE) + convertToUnicode = TRUE; } - if (infoPtr->notifyFormat == 0) - return FALSE; - TRACE(" we have to convert the text to the correct format\n"); - ZeroMemory(&diw, sizeof(diw)); - memcpy(&diw, pdi, sizeof(diw)); - diw.item.cchTextMax = isW ? - WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText, -1, NULL, 0, NULL, NULL) : - MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pdi->item.pszText, -1, NULL, 0); - diw.item.pszText = HeapAlloc(GetProcessHeap(), 0, (isW ? sizeof(WCHAR) : sizeof(CHAR)) * diw.item.cchTextMax); - if (!diw.item.pszText) return FALSE; - if (isW) - WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText, -1, (LPSTR)diw.item.pszText, diw.item.cchTextMax, NULL, NULL); + + if (convertToAnsi || convertToUnicode) + { + TRACE(" we have to convert the text to the correct format\n"); + ZeroMemory(&diw, sizeof(diw)); + memcpy(&diw, pdi, sizeof(diw)); + if (notificationCode != LVN_GETDISPINFOW) + { + diw.item.cchTextMax = convertToUnicode ? + WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText, -1, NULL, 0, NULL, NULL) : + MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pdi->item.pszText, -1, NULL, 0); + } + diw.item.pszText = HeapAlloc(GetProcessHeap(), 0, + (convertToUnicode ? sizeof(WCHAR) : sizeof(CHAR)) * diw.item.cchTextMax); + if (!diw.item.pszText) return FALSE; + if (convertToUnicode) + WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText, -1, (LPSTR)diw.item.pszText, + diw.item.cchTextMax, NULL, NULL); + else + MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pdi->item.pszText, -1, + diw.item.pszText, diw.item.cchTextMax); + TRACE(" text=%s\n", debugstr_t(diw.item.pszText, convertToUnicode)); + + bResult = notify(self, notifCode, (LPNMHDR)&diw); + } else - MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pdi->item.pszText, -1, diw.item.pszText, diw.item.cchTextMax); - TRACE(" text=%s\n", debugstr_t(diw.item.pszText, isW)); - bResult = notify(self, code, (LPNMHDR)&diw); - HeapFree(GetProcessHeap(), 0, diw.item.pszText); + bResult = notify(self, notifCode, (LPNMHDR)pdi); + + if (convertToUnicode || convertToAnsi) + { + if (convertToUnicode) + WideCharToMultiByte(CP_ACP, 0, diw.item.pszText, -1, (LPSTR) pdi->item.pszText, + pdi->item.cchTextMax, NULL, NULL); + else + MultiByteToWideChar(CP_ACP, 0, (LPSTR) diw.item.pszText, -1, + pdi->item.pszText, pdi->item.cchTextMax); + HeapFree(GetProcessHeap(), 0, diw.item.pszText); + } return bResult; } @@ -4229,7 +4263,7 @@ dispInfo.item.iImage = lpItem->iImage; dispInfo.item.lParam = lpItem->lParam; - if (dispinfo_notifyT(hwnd, isW ? LVN_BEGINLABELEDITW : LVN_BEGINLABELEDITA, &dispInfo, isW)) + if (dispinfo_notifyT(hwnd, LVN_BEGINLABELEDITW, &dispInfo, isW)) return 0; rect.left = LVIR_LABEL; @@ -4971,7 +5005,7 @@ if (lpLVItem->mask & ~LVIF_STATE) { memcpy(&dispInfo.item, lpLVItem, sizeof(LVITEMW)); - dispinfo_notifyT(hwnd, LVN_GETDISPINFOT(isW), &dispInfo, isW); + dispinfo_notifyT(hwnd, LVN_GETDISPINFOW, &dispInfo, isW); memcpy(lpLVItem, &dispInfo.item, sizeof(LVITEMW)); TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem, isW)); } @@ -5028,6 +5062,8 @@ dispInfo.item.cchTextMax = lpLVItem->cchTextMax; if (dispInfo.item.pszText && lpLVItem->cchTextMax > 0) *dispInfo.item.pszText = 0; + if (*ppszText == NULL) + *dispInfo.item.pszText = '\0'; } if (dispInfo.item.mask != 0) @@ -5036,7 +5072,7 @@ dispInfo.item.iItem = lpLVItem->iItem; dispInfo.item.iSubItem = lpLVItem->iSubItem; dispInfo.item.lParam = lpItem->lParam; - dispinfo_notifyT(hwnd, LVN_GETDISPINFOT(isW), &dispInfo, isW); + dispinfo_notifyT(hwnd, LVN_GETDISPINFOW, &dispInfo, isW); TRACE(" getdispinfo(2):lpLVItem=%s\n", debuglvitem_t(&dispInfo.item, isW)); } @@ -5073,8 +5109,6 @@ if (lpLVItem->pszText != dispInfo.item.pszText) textcpynT(lpLVItem->pszText, isW, dispInfo.item.pszText, isW, lpLVItem->cchTextMax); - if (*ppszText == NULL) - *lpLVItem->pszText = '\0'; } else if (lpLVItem->mask & LVIF_TEXT) {