+ case NM_RCLICK:
+ {
+ eventType = wxEVT_COMMAND_LIST_COL_RIGHT_CLICK;
+ event.m_col = -1;
+
+ // find the column clicked: we have to search for it
+ // ourselves as the notification message doesn't provide
+ // this info
+
+ // where did the click occur?
+ POINT ptClick;
+ if ( !::GetCursorPos(&ptClick) )
+ {
+ wxLogLastError(_T("GetCursorPos"));
+ }
+
+ if ( !::ScreenToClient(hwndHdr, &ptClick) )
+ {
+ wxLogLastError(_T("ScreenToClient(listctrl header)"));
+ }
+
+ event.m_pointDrag.x = ptClick.x;
+ event.m_pointDrag.y = ptClick.y;
+
+ int colCount = Header_GetItemCount(hwndHdr);
+
+ RECT rect;
+ for ( int col = 0; col < colCount; col++ )
+ {
+ if ( Header_GetItemRect(hwndHdr, col, &rect) )
+ {
+ if ( ::PtInRect(&rect, ptClick) )
+ {
+ event.m_col = col;
+ break;
+ }
+ }
+ }
+ }
+ break;
+
+ 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: