+ }
+ }
+
+ return wxNOT_FOUND;
+}
+
+bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
+{
+
+ // prepare the event
+ // -----------------
+
+ wxListEvent event(wxEVT_NULL, m_windowId);
+ event.SetEventObject(this);
+
+ wxEventType eventType = wxEVT_NULL;
+
+ NMHDR *nmhdr = (NMHDR *)lParam;
+
+ // if your compiler is as broken as this, you should really change it: this
+ // code is needed for normal operation! #ifdef below is only useful for
+ // automatic rebuilds which are done with a very old compiler version
+#ifdef HDN_BEGINTRACKA
+
+ // check for messages from the header (in report view)
+ HWND hwndHdr = ListView_GetHeader(GetHwnd());
+
+ // is it a message from the header?
+ if ( nmhdr->hwndFrom == hwndHdr )
+ {
+ HD_NOTIFY *nmHDR = (HD_NOTIFY *)nmhdr;
+
+ event.m_itemIndex = -1;
+
+ bool ignore = false;
+ switch ( nmhdr->code )
+ {
+ // yet another comctl32.dll bug: under NT/W2K it sends Unicode
+ // TRACK messages even to ANSI programs: on my system I get
+ // HDN_BEGINTRACKW and HDN_ENDTRACKA!
+ //
+ // work around is to simply catch both versions and hope that it
+ // works (why should this message exist in ANSI and Unicode is
+ // beyond me as it doesn't deal with strings at all...)
+ //
+ // another problem is that HDN_TRACK is not sent at all by header
+ // with HDS_FULLDRAG style which is used by default by wxListCtrl
+ // under recent Windows versions (starting from at least XP) so we
+ // need to use HDN_ITEMCHANGING instead of it
+ case HDN_BEGINTRACKA:
+ case HDN_BEGINTRACKW:
+ eventType = wxEVT_COMMAND_LIST_COL_BEGIN_DRAG;
+ // fall through
+
+ case HDN_ITEMCHANGING:
+ if ( eventType == wxEVT_NULL )
+ {
+ if ( !nmHDR->pitem || !(nmHDR->pitem->mask & HDI_WIDTH) )
+ {
+ // something other than the width is being changed,
+ // ignore it
+ ignore = true;
+ break;
+ }
+
+ // also ignore the events sent when the width didn't really
+ // change: this is not just an optimization but also gets
+ // rid of a useless and unexpected DRAGGING event which
+ // would otherwise be sent after the END_DRAG one as we get
+ // an HDN_ITEMCHANGING after HDN_ENDTRACK for some reason
+ if ( nmHDR->pitem->cxy == GetColumnWidth(nmHDR->iItem) )
+ {
+ ignore = true;
+ break;
+ }
+
+ eventType = wxEVT_COMMAND_LIST_COL_DRAGGING;
+ }
+ // fall through
+
+ case HDN_ENDTRACKA:
+ case HDN_ENDTRACKW:
+ if ( eventType == wxEVT_NULL )
+ eventType = wxEVT_COMMAND_LIST_COL_END_DRAG;
+
+ event.m_item.m_width = nmHDR->pitem->cxy;
+ event.m_col = nmHDR->iItem;
+ break;
+
+#if defined(__WXWINCE__) && !defined(__HANDHELDPC__) && _WIN32_WCE < 400
+ case GN_CONTEXTMENU:
+#endif //__WXWINCE__
+ case NM_RCLICK:
+ {
+ POINT ptClick;
+
+ eventType = wxEVT_COMMAND_LIST_COL_RIGHT_CLICK;
+ event.m_col = wxMSWGetColumnClicked(nmhdr, &ptClick);
+ event.m_pointDrag.x = ptClick.x;
+ event.m_pointDrag.y = ptClick.y;
+ }
+ break;
+
+ case HDN_GETDISPINFOW:
+ // letting Windows XP handle this message results in mysterious
+ // crashes in comctl32.dll seemingly because of bad message
+ // parameters
+ //
+ // I have no idea what is the real cause of the bug (which is,
+ // just to make things interesting, impossible to reproduce
+ // reliably) but ignoring all these messages does fix it and
+ // doesn't seem to have any negative consequences
+ return true;
+
+ default:
+ ignore = true;
+ }
+
+ if ( ignore )
+ 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;
+
+
+ // 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() )
+ {
+ wxMSWListItemData *internaldata =
+ MSWGetItemData(iItem);
+
+ if ( internaldata )
+ event.m_item.m_data = internaldata->lParam;
+ }
+
+ bool processed = true;
+ 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 messages even to the
+ // Unicode windows
+ case LVN_BEGINLABELEDITA:
+ case LVN_BEGINLABELEDITW:
+ {
+ wxLV_ITEM item;
+ if ( nmhdr->code == LVN_BEGINLABELEDITA )
+ {
+ item.Init(((LV_DISPINFOA *)lParam)->item);
+ }
+ else // LVN_BEGINLABELEDITW
+ {
+ item.Init(((LV_DISPINFOW *)lParam)->item);
+ }
+
+ eventType = wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
+ wxConvertFromMSWListItem(GetHwnd(), event.m_item, item);
+ event.m_itemIndex = event.m_item.m_itemId;
+ }
+ break;
+
+ case LVN_ENDLABELEDITA:
+ case LVN_ENDLABELEDITW:
+ {
+ wxLV_ITEM item;
+ if ( nmhdr->code == LVN_ENDLABELEDITA )
+ {
+ item.Init(((LV_DISPINFOA *)lParam)->item);
+ }
+ else // LVN_ENDLABELEDITW
+ {
+ item.Init(((LV_DISPINFOW *)lParam)->item);
+ }
+
+ // was editing cancelled?
+ const LV_ITEM& lvi = (LV_ITEM)item;
+ if ( !lvi.pszText || lvi.iItem == -1 )
+ {
+ // EDIT control will be deleted by the list control
+ // itself so prevent us from deleting it as well
+ DeleteEditControl();
+
+ event.SetEditCanceled(true);
+ }
+
+ eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT;
+ wxConvertFromMSWListItem(NULL, event.m_item, item);
+ 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:
+ 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;
+
+ 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) 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)HandleWindowEvent(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 any modifiers as they have a predefined meaning
+ // then)
+ if ( lItem != -1 &&
+ (wVKey == VK_RETURN || wVKey == VK_SPACE) &&
+ !wxIsAnyModifierDown() )
+ {
+ eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
+ }
+ else
+ {
+ eventType = wxEVT_COMMAND_LIST_KEY_DOWN;
+
+ event.m_code = wxMSWKeyboard::VKToWX(wVKey);
+
+ if ( event.m_code == WXK_NONE )
+ {
+ // We can't translate this to a standard key code,
+ // until support for Unicode key codes is added to
+ // wxListEvent we just ignore them.
+ return false;
+ }
+ }
+
+ 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;
+ }