- break;
-
- case LVN_BEGINLABELEDIT:
- {
- eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
- LV_DISPINFO *info = (LV_DISPINFO *)lParam;
- wxConvertFromMSWListItem(this, event.m_item, info->item, (HWND) GetHWND());
- break;
- }
-
- case LVN_COLUMNCLICK:
- {
- eventType = wxEVT_COMMAND_LIST_COL_CLICK;
- NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
- event.m_itemIndex = -1;
- event.m_col = hdr->iSubItem;
- break;
- }
- case LVN_DELETEALLITEMS:
- {
- eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
-// NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
- event.m_itemIndex = -1;
- break;
- }
- case LVN_DELETEITEM:
- {
- eventType = wxEVT_COMMAND_LIST_DELETE_ITEM;
- NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
- event.m_itemIndex = hdr->iItem;
- break;
- }
- case LVN_ENDLABELEDIT:
- {
- eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT;
- LV_DISPINFO *info = (LV_DISPINFO *)lParam;
- wxConvertFromMSWListItem(this, event.m_item, info->item, (HWND) GetHWND());
- if ( info->item.pszText == NULL || info->item.iItem == -1 )
- event.m_cancelled = TRUE;
- break;
- }
- case LVN_GETDISPINFO:
- {
-// return FALSE;
- // TODO: some text buffering here, I think
- // TODO: API for getting Windows to retrieve values
- // on demand.
- eventType = wxEVT_COMMAND_LIST_GET_INFO;
- LV_DISPINFO *info = (LV_DISPINFO *)lParam;
- wxConvertFromMSWListItem(this, event.m_item, info->item, (HWND) GetHWND());
- break;
- }
- case LVN_INSERTITEM:
- {
- eventType = wxEVT_COMMAND_LIST_INSERT_ITEM;
- NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
- event.m_itemIndex = hdr->iItem;
- break;
- }
- case LVN_ITEMCHANGED:
- {
- // This needs to be sent to wxListCtrl as a rather more
- // concrete event. For now, just detect a selection
- // or deselection.
- NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
- if ( (hdr->uNewState & LVIS_SELECTED) && !(hdr->uOldState & LVIS_SELECTED) )
- {
- eventType = wxEVT_COMMAND_LIST_ITEM_SELECTED;
- event.m_itemIndex = hdr->iItem;
- }
- else if ( !(hdr->uNewState & LVIS_SELECTED) && (hdr->uOldState & LVIS_SELECTED) )
- {
- eventType = wxEVT_COMMAND_LIST_ITEM_DESELECTED;
- event.m_itemIndex = hdr->iItem;
- }
- else
+
+
+ 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"
+ return FALSE;
+
+ eventType = wxEVT_COMMAND_LIST_DELETE_ITEM;
+ event.m_itemIndex = iItem;
+ // delete the assoicated internal data
+ wxDeleteInternalData(this, iItem);
+ break;
+
+ case LVN_SETDISPINFO:
+ {
+ eventType = wxEVT_COMMAND_LIST_SET_INFO;
+ LV_DISPINFO *info = (LV_DISPINFO *)lParam;
+ wxConvertFromMSWListItem(GetHwnd(), event.m_item, info->item);
+ }
+ break;
+
+ 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) wxWindows 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;
+
+ 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);
+
+ ::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;
+
+#if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
+ && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
+ case NM_CUSTOMDRAW:
+ *result = OnCustomDraw(lParam);
+
+ return TRUE;
+#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;
+
+ 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);
+ }
+
+#if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
+ && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
+ if ( lvi.mask & LVIF_IMAGE )
+ {
+ lvi.iImage = OnGetItemImage(item);
+ }
+#endif
+
+ // 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:
+ return wxControl::MSWOnNotify(idCtrl, lParam, result);
+ }
+ }
+ else
+ {
+ // where did this one come from?