From 648bec3ef5203f7b06c2bd474ad1f7ca4240adf3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 17 Nov 2001 00:34:46 +0000 Subject: [PATCH] implemented EVT_LIST_ITEM_FOCUSED() for Win32 wxListCtrl git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12454 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/listctrl.cpp | 57 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 6c5d4a3e28..13d2bff72e 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: listctrl.cpp +// Name: src/msw/listctrl.cpp // Purpose: wxListCtrl // Author: Julian Smart // Modified by: @@ -1486,6 +1486,8 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // ----------------- wxListEvent event(wxEVT_NULL, m_windowId); + event.SetEventObject(this); + wxEventType eventType = wxEVT_NULL; NMHDR *nmhdr = (NMHDR *)lParam; @@ -1655,22 +1657,52 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) 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. - if ( (nmLV->uNewState & LVIS_SELECTED) && !(nmLV->uOldState & LVIS_SELECTED) ) - { - eventType = wxEVT_COMMAND_LIST_ITEM_SELECTED; - event.m_itemIndex = nmLV->iItem; - } - else if ( !(nmLV->uNewState & LVIS_SELECTED) && (nmLV->uOldState & LVIS_SELECTED) ) + // 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 + if ( nmLV->uChanged & LVIF_STATE ) { - eventType = wxEVT_COMMAND_LIST_ITEM_DESELECTED; - event.m_itemIndex = nmLV->iItem; + // temp vars for readability + const UINT stOld = nmLV->uOldState; + const UINT stNew = nmLV->uNewState; + + // has the focus changed? + if ( !(stOld & LVIS_FOCUSED) && (stNew & LVIS_FOCUSED) ) + { + eventType = wxEVT_COMMAND_LIST_ITEM_FOCUSED; + event.m_itemIndex = nmLV->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 = nmLV->iItem; + } + + eventType = stNew & LVIS_SELECTED + ? wxEVT_COMMAND_LIST_ITEM_SELECTED + : wxEVT_COMMAND_LIST_ITEM_DESELECTED; + } } - else + + if ( eventType == wxEVT_NULL ) { + // not an interesting event for us return FALSE; } + break; case LVN_KEYDOWN: @@ -1838,7 +1870,6 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // process the event // ----------------- - event.SetEventObject( this ); event.SetEventType(eventType); if ( !GetEventHandler()->ProcessEvent(event) ) -- 2.45.2