+ case HDN_GETDISPINFOW:
+ {
+ LPNMHDDISPINFOW info = (LPNMHDDISPINFOW) lParam;
+ // This is a fix for a strange bug under XP.
+ // Normally, info->iItem is a valid index, but
+ // sometimes this is a silly (large) number
+ // and when we return FALSE via wxControl::MSWOnNotify
+ // to indicate that it hasn't yet been processed,
+ // there's a GPF in Windows.
+ // By returning TRUE here, we avoid further processing
+ // of this strange message.
+ if ( info->iItem >= GetColumnCount() )
+ return TRUE;
+ }
+ // fall through
+
+ default:
+ return wxControl::MSWOnNotify(idCtrl, lParam, result);
+ }
+ }
+ else
+#endif // defined(HDN_BEGINTRACKA)
+ if ( nmhdr->hwndFrom == GetHwnd() )
+ {
+ // almost all messages use NM_LISTVIEW
+ NM_LISTVIEW *nmLV = (NM_LISTVIEW *)nmhdr;
+
+ const int iItem = nmLV->iItem;
+
+
+ // FreeAllInternalData will cause LVN_ITEMCHANG* messages, which can be
+ // ignored for efficiency. It is done here because the internal data is in the
+ // process of being deleted so we don't want to try and access it below.
+ if ( m_ignoreChangeMessages &&
+ ( (nmLV->hdr.code == LVN_ITEMCHANGED) || (nmLV->hdr.code == LVN_ITEMCHANGING)))
+ {
+ return TRUE;
+ }
+
+
+ // If we have a valid item then check if there is a data value
+ // associated with it and put it in the event.
+ if ( iItem >= 0 && iItem < GetItemCount() )
+ {
+ wxListItemInternalData *internaldata =
+ wxGetInternalData(GetHwnd(), iItem);
+
+ if ( internaldata )
+ event.m_item.m_data = internaldata->lParam;
+ }
+
+
+ switch ( nmhdr->code )
+ {
+ case LVN_BEGINRDRAG:
+ eventType = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
+ // fall through
+
+ case LVN_BEGINDRAG:
+ if ( eventType == wxEVT_NULL )
+ {
+ eventType = wxEVT_COMMAND_LIST_BEGIN_DRAG;
+ }
+
+ event.m_itemIndex = iItem;
+ event.m_pointDrag.x = nmLV->ptAction.x;
+ event.m_pointDrag.y = nmLV->ptAction.y;
+ break;
+
+ // NB: we have to handle both *A and *W versions here because some
+ // versions of comctl32.dll send ANSI message to an Unicode app
+ case LVN_BEGINLABELEDITA:
+ {
+ eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
+ wxLV_ITEM item(((LV_DISPINFOA *)lParam)->item);
+ wxConvertFromMSWListItem(GetHwnd(), event.m_item, item);
+ event.m_itemIndex = event.m_item.m_itemId;
+ }
+ break;
+ case LVN_BEGINLABELEDITW:
+ {
+ eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
+ wxLV_ITEM item(((LV_DISPINFOW *)lParam)->item);
+ wxConvertFromMSWListItem(GetHwnd(), event.m_item, item);
+ event.m_itemIndex = event.m_item.m_itemId;
+ }
+ break;
+
+ case LVN_ENDLABELEDITA:
+ {
+ eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT;
+ wxLV_ITEM item(((LV_DISPINFOA *)lParam)->item);
+ wxConvertFromMSWListItem(NULL, event.m_item, item);
+ if ( ((LV_ITEM)item).pszText == NULL ||
+ ((LV_ITEM)item).iItem == -1 )
+ {
+ // don't keep a stale wxTextCtrl around
+ if ( m_textCtrl )
+ {
+ // EDIT control will be deleted by the list control itself so
+ // prevent us from deleting it as well
+ m_textCtrl->UnsubclassWin();
+ m_textCtrl->SetHWND(0);
+ delete m_textCtrl;
+ m_textCtrl = NULL;
+ }
+ return FALSE;
+ }
+
+ event.m_itemIndex = event.m_item.m_itemId;
+ }
+ break;
+ case LVN_ENDLABELEDITW:
+ {
+ eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT;
+ wxLV_ITEM item(((LV_DISPINFOW *)lParam)->item);
+ wxConvertFromMSWListItem(NULL, event.m_item, item);
+ if ( ((LV_ITEM)item).pszText == NULL ||
+ ((LV_ITEM)item).iItem == -1 )
+ {
+ // don't keep a stale wxTextCtrl around
+ if ( m_textCtrl )
+ {
+ // EDIT control will be deleted by the list control itself so
+ // prevent us from deleting it as well
+ m_textCtrl->UnsubclassWin();
+ m_textCtrl->SetHWND(0);
+ delete m_textCtrl;
+ m_textCtrl = NULL;
+ }
+ return FALSE;
+ }
+
+ event.m_itemIndex = event.m_item.m_itemId;
+ }
+ break;
+
+ case LVN_COLUMNCLICK:
+ eventType = wxEVT_COMMAND_LIST_COL_CLICK;
+ event.m_itemIndex = -1;
+ event.m_col = nmLV->iSubItem;
+ break;
+
+ case LVN_DELETEALLITEMS:
+ m_count = 0;
+ eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
+ event.m_itemIndex = -1;
+ break;
+
+ case LVN_DELETEITEM:
+ if (m_count == 0)
+ // this should be prevented by the post-processing code below,
+ // but "just in case"