+#if WXWIN_COMPATIBILITY_2_4
+ case LVN_SETDISPINFO:
+ {
+ eventType = wxEVT_COMMAND_LIST_SET_INFO;
+ LV_DISPINFO *info = (LV_DISPINFO *)lParam;
+ wxConvertFromMSWListItem(GetHwnd(), event.m_item, info->item);
+ }
+ break;
+#endif
+
+ case LVN_INSERTITEM:
+ eventType = wxEVT_COMMAND_LIST_INSERT_ITEM;
+ event.m_itemIndex = iItem;
+ break;
+
+ case LVN_ITEMCHANGED:
+ // we translate this catch all message into more interesting
+ // (and more easy to process) wxWidgets events
+
+ // first of all, we deal with the state change events only and
+ // only for valid items (item == -1 for the virtual list
+ // control)
+ if ( nmLV->uChanged & LVIF_STATE && iItem != -1 )
+ {
+ // temp vars for readability
+ const UINT stOld = nmLV->uOldState;
+ const UINT stNew = nmLV->uNewState;
+
+ event.m_item.SetId(iItem);
+ event.m_item.SetMask(wxLIST_MASK_TEXT |
+ wxLIST_MASK_IMAGE |
+ wxLIST_MASK_DATA);
+ GetItem(event.m_item);
+
+ // has the focus changed?
+ if ( !(stOld & LVIS_FOCUSED) && (stNew & LVIS_FOCUSED) )
+ {
+ eventType = wxEVT_COMMAND_LIST_ITEM_FOCUSED;
+ event.m_itemIndex = iItem;
+ }
+
+ if ( (stNew & LVIS_SELECTED) != (stOld & LVIS_SELECTED) )
+ {
+ if ( eventType != wxEVT_NULL )
+ {
+ // focus and selection have both changed: send the
+ // focus event from here and the selection one
+ // below
+ event.SetEventType(eventType);
+ (void)GetEventHandler()->ProcessEvent(event);
+ }
+ else // no focus event to send
+ {
+ // then need to set m_itemIndex as it wasn't done
+ // above
+ event.m_itemIndex = iItem;
+ }
+
+ eventType = stNew & LVIS_SELECTED
+ ? wxEVT_COMMAND_LIST_ITEM_SELECTED
+ : wxEVT_COMMAND_LIST_ITEM_DESELECTED;
+ }
+ }
+
+ if ( eventType == wxEVT_NULL )
+ {
+ // not an interesting event for us
+ return false;
+ }
+
+ break;
+
+ case LVN_KEYDOWN:
+ {
+ LV_KEYDOWN *info = (LV_KEYDOWN *)lParam;
+ WORD wVKey = info->wVKey;
+
+ // get the current selection
+ long lItem = GetNextItem(-1,
+ wxLIST_NEXT_ALL,
+ wxLIST_STATE_SELECTED);
+
+ // <Enter> or <Space> activate the selected item if any (but
+ // not with Shift and/or Ctrl as then they have a predefined
+ // meaning for the list view)
+ if ( lItem != -1 &&
+ (wVKey == VK_RETURN || wVKey == VK_SPACE) &&
+ !(wxIsShiftDown() || wxIsCtrlDown()) )
+ {
+ eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
+ }
+ else
+ {
+ eventType = wxEVT_COMMAND_LIST_KEY_DOWN;
+
+ // wxCharCodeMSWToWX() returns 0 if the key is an ASCII
+ // value which should be used as is
+ int code = wxCharCodeMSWToWX(wVKey);
+ event.m_code = code ? code : wVKey;
+ }
+
+ event.m_itemIndex =
+ event.m_item.m_itemId = lItem;
+
+ if ( lItem != -1 )
+ {
+ // fill the other fields too
+ event.m_item.m_text = GetItemText(lItem);
+ event.m_item.m_data = GetItemData(lItem);
+ }
+ }
+ break;
+
+ case NM_DBLCLK:
+ // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
+ // anything else
+ if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
+ {
+ return true;
+ }
+
+ // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
+ // if it happened on an item (and not on empty place)
+ if ( iItem == -1 )
+ {
+ // not on item
+ return false;
+ }
+
+ eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
+ event.m_itemIndex = iItem;
+ event.m_item.m_text = GetItemText(iItem);
+ event.m_item.m_data = GetItemData(iItem);
+ break;
+
+#if defined(__WXWINCE__) && !defined(__HANDHELDPC__) && _WIN32_WCE < 400
+ case GN_CONTEXTMENU:
+#endif //__WXWINCE__
+ case NM_RCLICK:
+ // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
+ // don't do anything else
+ if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
+ {
+ return true;
+ }
+
+ // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
+ LV_HITTESTINFO lvhti;
+ wxZeroMemory(lvhti);
+
+#if defined(__WXWINCE__) && !defined(__HANDHELDPC__) && _WIN32_WCE < 400
+ if(nmhdr->code == GN_CONTEXTMENU) {
+ lvhti.pt = ((NMRGINFO*)nmhdr)->ptAction;
+ } else
+#endif //__WXWINCE__
+ ::GetCursorPos(&(lvhti.pt));
+ ::ScreenToClient(GetHwnd(),&(lvhti.pt));
+ if ( ListView_HitTest(GetHwnd(),&lvhti) != -1 )
+ {
+ if ( lvhti.flags & LVHT_ONITEM )
+ {
+ eventType = wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK;
+ event.m_itemIndex = lvhti.iItem;
+ event.m_pointDrag.x = lvhti.pt.x;
+ event.m_pointDrag.y = lvhti.pt.y;
+ }
+ }
+ break;
+
+#ifdef NM_CUSTOMDRAW
+ case NM_CUSTOMDRAW:
+ *result = OnCustomDraw(lParam);
+
+ return *result != CDRF_DODEFAULT;
+#endif // _WIN32_IE >= 0x300
+
+ case LVN_ODCACHEHINT:
+ {
+ const NM_CACHEHINT *cacheHint = (NM_CACHEHINT *)lParam;
+
+ eventType = wxEVT_COMMAND_LIST_CACHE_HINT;
+
+ // we get some really stupid cache hints like ones for
+ // items in range 0..0 for an empty control or, after
+ // deleting an item, for items in invalid range -- filter
+ // this garbage out
+ if ( cacheHint->iFrom > cacheHint->iTo )
+ return false;
+
+ event.m_oldItemIndex = cacheHint->iFrom;
+
+ const long iMax = GetItemCount();
+ event.m_itemIndex = cacheHint->iTo < iMax ? cacheHint->iTo
+ : iMax - 1;
+ }
+ break;
+
+#ifdef HAVE_NMLVFINDITEM
+ case LVN_ODFINDITEM:
+ // this message is only used with the virtual list control but
+ // even there we don't want to always use it: in a control with
+ // sufficiently big number of items (defined as > 1000 here),
+ // accidentally pressing a key could result in hanging an
+ // application waiting while it performs linear search
+ if ( IsVirtual() && GetItemCount() <= 1000 )
+ {
+ NMLVFINDITEM* pFindInfo = (NMLVFINDITEM*)lParam;
+
+ // no match by default
+ *result = -1;
+
+ // we only handle string-based searches here
+ //
+ // TODO: what about LVFI_PARTIAL, should we handle this?
+ if ( !(pFindInfo->lvfi.flags & LVFI_STRING) )
+ {
+ return false;
+ }
+
+ const wxChar * const searchstr = pFindInfo->lvfi.psz;
+ const size_t len = wxStrlen(searchstr);
+
+ // this is the first item we should examine, search from it
+ // wrapping if necessary
+ const int startPos = pFindInfo->iStart;
+ const int maxPos = GetItemCount();
+ wxCHECK_MSG( startPos <= maxPos, false,
+ _T("bad starting position in LVN_ODFINDITEM") );
+
+ int currentPos = startPos;
+ do
+ {
+ // wrap to the beginning if necessary
+ if ( currentPos == maxPos )
+ {
+ // somewhat surprizingly, LVFI_WRAP isn't set in
+ // flags but we still should wrap
+ currentPos = 0;
+ }
+
+ // does this item begin with searchstr?
+ if ( wxStrnicmp(searchstr,
+ GetItemText(currentPos), len) == 0 )
+ {
+ *result = currentPos;
+ break;
+ }
+ }
+ while ( ++currentPos != startPos );
+
+ if ( *result == -1 )
+ {
+ // not found
+ return false;
+ }
+
+ SetItemState(*result,
+ wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
+ wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
+ EnsureVisible(*result);
+ return true;
+ }
+ else
+ {
+ processed = false;
+ }
+ break;
+#endif // HAVE_NMLVFINDITEM
+
+ case LVN_GETDISPINFO:
+ if ( IsVirtual() )
+ {
+ LV_DISPINFO *info = (LV_DISPINFO *)lParam;
+
+ LV_ITEM& lvi = info->item;
+ long item = lvi.iItem;
+
+ if ( lvi.mask & LVIF_TEXT )
+ {
+ wxString text = OnGetItemText(item, lvi.iSubItem);
+ wxStrncpy(lvi.pszText, text, lvi.cchTextMax);
+ }
+
+ // see comment at the end of wxListCtrl::GetColumn()
+#ifdef NM_CUSTOMDRAW
+ if ( lvi.mask & LVIF_IMAGE )
+ {
+ lvi.iImage = OnGetItemColumnImage(item, lvi.iSubItem);
+ }
+#endif // NM_CUSTOMDRAW
+
+ // a little dose of healthy paranoia: as we never use
+ // LVM_SETCALLBACKMASK we're not supposed to get these ones
+ wxASSERT_MSG( !(lvi.mask & LVIF_STATE),
+ _T("we don't support state callbacks yet!") );
+
+ return true;
+ }
+ // fall through
+
+ default:
+ processed = false;
+ }
+
+ if ( !processed )
+ return wxControl::MSWOnNotify(idCtrl, lParam, result);
+ }
+ else
+ {
+ // where did this one come from?
+ return false;
+ }
+
+ // process the event
+ // -----------------
+
+ event.SetEventType(eventType);
+
+ bool processed = GetEventHandler()->ProcessEvent(event);
+
+ // post processing
+ // ---------------
+ switch ( nmhdr->code )
+ {
+ case LVN_DELETEALLITEMS:
+ // always return true to suppress all additional LVN_DELETEITEM
+ // notifications - this makes deleting all items from a list ctrl
+ // much faster
+ *result = TRUE;
+
+ // also, we may free all user data now (couldn't do it before as
+ // the user should have access to it in OnDeleteAllItems() handler)
+ FreeAllInternalData();
+
+ // the control is empty now, synchronize the cached number of items
+ // with the real one
+ m_count = 0;
+ return true;
+
+ case LVN_ENDLABELEDITA:
+ case LVN_ENDLABELEDITW:
+ // logic here is inverted compared to all the other messages
+ *result = event.IsAllowed();
+
+ // don't keep a stale wxTextCtrl around
+ if ( m_textCtrl )