added wxEVT_COMMAND_LIST_ITEM_FOCUSED event and implemented it for the generic version

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12449 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2001-11-16 16:31:17 +00:00
parent e347320363
commit 0ddefeb07f
8 changed files with 35 additions and 40 deletions

View File

@@ -63,6 +63,7 @@ All (GUI):
- wxWizard changes: loading from WXR support, help button (Robert Cavanaugh) - wxWizard changes: loading from WXR support, help button (Robert Cavanaugh)
- wxDirSelector() added (Paul A. Thiessen) - wxDirSelector() added (Paul A. Thiessen)
- wxGrid cell editing veto support (Roger Gammans) - wxGrid cell editing veto support (Roger Gammans)
- wxListCtrl ITEM_FOCUSED event added
wxMSW: wxMSW:

View File

@@ -77,6 +77,7 @@ functions that take a \helpref{wxListEvent}{wxlistevent} argument.
\twocolitem{{\bf EVT\_LIST\_ITEM\_SELECTED(id, func)}}{The item has been selected.} \twocolitem{{\bf EVT\_LIST\_ITEM\_SELECTED(id, func)}}{The item has been selected.}
\twocolitem{{\bf EVT\_LIST\_ITEM\_DESELECTED(id, func)}}{The item has been deselected.} \twocolitem{{\bf EVT\_LIST\_ITEM\_DESELECTED(id, func)}}{The item has been deselected.}
\twocolitem{{\bf EVT\_LIST\_ITEM\_ACTIVATED(id, func)}}{The item has been activated (ENTER or double click).} \twocolitem{{\bf EVT\_LIST\_ITEM\_ACTIVATED(id, func)}}{The item has been activated (ENTER or double click).}
\twocolitem{{\bf EVT\_LIST\_ITEM\_FOCUSED(id, func)}}{The currently focused item has changed.}
\twocolitem{{\bf EVT\_LIST\_ITEM\_RIGHT\_CLICK(id, func)}}{An item has been right-clicked.} \twocolitem{{\bf EVT\_LIST\_ITEM\_RIGHT\_CLICK(id, func)}}{An item has been right-clicked.}
\twocolitem{{\bf EVT\_LIST\_KEY\_DOWN(id, func)}}{A key has been pressed.} \twocolitem{{\bf EVT\_LIST\_KEY\_DOWN(id, func)}}{A key has been pressed.}
\twocolitem{{\bf EVT\_LIST\_INSERT\_ITEM(id, func)}}{An item has been inserted.} \twocolitem{{\bf EVT\_LIST\_INSERT\_ITEM(id, func)}}{An item has been inserted.}

View File

@@ -31,6 +31,7 @@ functions that take a wxListEvent argument.
\twocolitem{{\bf EVT\_LIST\_ITEM\_SELECTED(id, func)}}{The item has been selected.} \twocolitem{{\bf EVT\_LIST\_ITEM\_SELECTED(id, func)}}{The item has been selected.}
\twocolitem{{\bf EVT\_LIST\_ITEM\_DESELECTED(id, func)}}{The item has been deselected.} \twocolitem{{\bf EVT\_LIST\_ITEM\_DESELECTED(id, func)}}{The item has been deselected.}
\twocolitem{{\bf EVT\_LIST\_ITEM\_ACTIVATED(id, func)}}{The item has been activated (ENTER or double click).} \twocolitem{{\bf EVT\_LIST\_ITEM\_ACTIVATED(id, func)}}{The item has been activated (ENTER or double click).}
\twocolitem{{\bf EVT\_LIST\_ITEM\_FOCUSED(id, func)}}{The currently focused item has changed.}
\twocolitem{{\bf EVT\_LIST\_ITEM\_RIGHT\_CLICK(id, func)}}{An item has been right-clicked.} \twocolitem{{\bf EVT\_LIST\_ITEM\_RIGHT\_CLICK(id, func)}}{An item has been right-clicked.}
\twocolitem{{\bf EVT\_LIST\_KEY\_DOWN(id, func)}}{A key has been pressed.} \twocolitem{{\bf EVT\_LIST\_KEY\_DOWN(id, func)}}{A key has been pressed.}
\twocolitem{{\bf EVT\_LIST\_INSERT\_ITEM(id, func)}}{An item has been inserted.} \twocolitem{{\bf EVT\_LIST\_INSERT\_ITEM(id, func)}}{An item has been inserted.}

View File

@@ -424,6 +424,7 @@ BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, 718) DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, 718)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING, 719) DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING, 719)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG, 720) DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG, 720)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED, 721)
END_DECLARE_EVENT_TYPES() END_DECLARE_EVENT_TYPES()
typedef void (wxEvtHandler::*wxListEventFunction)(wxListEvent&); typedef void (wxEvtHandler::*wxListEventFunction)(wxListEvent&);
@@ -450,6 +451,7 @@ typedef void (wxEvtHandler::*wxListEventFunction)(wxListEvent&);
#define EVT_LIST_ITEM_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ), #define EVT_LIST_ITEM_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
#define EVT_LIST_ITEM_MIDDLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ), #define EVT_LIST_ITEM_MIDDLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
#define EVT_LIST_ITEM_ACTIVATED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ), #define EVT_LIST_ITEM_ACTIVATED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
#define EVT_LIST_ITEM_FOCUSED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_FOCUSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
#define EVT_LIST_CACHE_HINT(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_CACHE_HINT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ), #define EVT_LIST_CACHE_HINT(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_CACHE_HINT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),

View File

@@ -92,6 +92,7 @@ BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected) EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected)
EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown) EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated) EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
EVT_LIST_ITEM_FOCUSED(LIST_CTRL, MyListCtrl::OnFocused)
EVT_LIST_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick) EVT_LIST_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick)
EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, MyListCtrl::OnColRightClick) EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, MyListCtrl::OnColRightClick)
@@ -750,6 +751,11 @@ void MyListCtrl::OnActivated(wxListEvent& event)
LogEvent(event, _T("OnActivated")); LogEvent(event, _T("OnActivated"));
} }
void MyListCtrl::OnFocused(wxListEvent& event)
{
LogEvent(event, _T("OnFocused"));
}
void MyListCtrl::OnListKeyDown(wxListEvent& event) void MyListCtrl::OnListKeyDown(wxListEvent& event)
{ {
switch ( event.GetCode() ) switch ( event.GetCode() )

View File

@@ -49,6 +49,7 @@ public:
void OnDeselected(wxListEvent& event); void OnDeselected(wxListEvent& event);
void OnListKeyDown(wxListEvent& event); void OnListKeyDown(wxListEvent& event);
void OnActivated(wxListEvent& event); void OnActivated(wxListEvent& event);
void OnFocused(wxListEvent& event);
void OnCacheHint(wxListEvent& event); void OnCacheHint(wxListEvent& event);
void OnChar(wxKeyEvent& event); void OnChar(wxKeyEvent& event);

View File

@@ -72,6 +72,7 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK) DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK) DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED) DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT) DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -684,7 +685,9 @@ public:
bool IsEmpty() const { return GetItemCount() == 0; } bool IsEmpty() const { return GetItemCount() == 0; }
void SetItemCount(long count); void SetItemCount(long count);
void ResetCurrent() { m_current = (size_t)-1; } // change the current (== focused) item, send a notification event
void ChangeCurrent(size_t current);
void ResetCurrent() { ChangeCurrent((size_t)-1); }
bool HasCurrent() const { return m_current != (size_t)-1; } bool HasCurrent() const { return m_current != (size_t)-1; }
// send out a wxListEvent // send out a wxListEvent
@@ -827,12 +830,6 @@ private:
// delete all items but don't refresh: called from dtor // delete all items but don't refresh: called from dtor
void DoDeleteAllItems(); void DoDeleteAllItems();
// called when an item is [un]focuded, i.e. becomes [not] current
//
// currently unused
void OnFocusLine( size_t line );
void OnUnfocusLine( size_t line );
// the height of one line using the current font // the height of one line using the current font
wxCoord m_lineHeight; wxCoord m_lineHeight;
@@ -2865,21 +2862,22 @@ void wxListMainWindow::SendNotify( size_t line,
// what we're trying to avoid // what we're trying to avoid
if ( !IsVirtual() && (command != wxEVT_COMMAND_LIST_DELETE_ITEM) ) if ( !IsVirtual() && (command != wxEVT_COMMAND_LIST_DELETE_ITEM) )
{ {
GetLine(line)->GetItem( 0, le.m_item ); if ( line != (size_t)-1 )
{
GetLine(line)->GetItem( 0, le.m_item );
}
//else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
} }
//else: there may be no more such item //else: there may be no more such item
GetParent()->GetEventHandler()->ProcessEvent( le ); GetParent()->GetEventHandler()->ProcessEvent( le );
} }
void wxListMainWindow::OnFocusLine( size_t WXUNUSED(line) ) void wxListMainWindow::ChangeCurrent(size_t current)
{ {
// SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED ); m_current = current;
}
void wxListMainWindow::OnUnfocusLine( size_t WXUNUSED(line) ) SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSED);
{
// SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
} }
void wxListMainWindow::EditLabel( long item ) void wxListMainWindow::EditLabel( long item )
@@ -3086,7 +3084,8 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
if ( IsSingleSel() || !(event.ControlDown() || event.ShiftDown()) ) if ( IsSingleSel() || !(event.ControlDown() || event.ShiftDown()) )
{ {
HighlightAll( FALSE ); HighlightAll( FALSE );
m_current = current;
ChangeCurrent(current);
ReverseHighlight(m_current); ReverseHighlight(m_current);
} }
@@ -3094,13 +3093,13 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
{ {
if (event.ControlDown()) if (event.ControlDown())
{ {
m_current = current; ChangeCurrent(current);
ReverseHighlight(m_current); ReverseHighlight(m_current);
} }
else if (event.ShiftDown()) else if (event.ShiftDown())
{ {
m_current = current; ChangeCurrent(current);
size_t lineFrom = oldCurrent, size_t lineFrom = oldCurrent,
lineTo = current; lineTo = current;
@@ -3123,8 +3122,6 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
if (m_current != oldCurrent) if (m_current != oldCurrent)
{ {
RefreshLine( oldCurrent ); RefreshLine( oldCurrent );
OnUnfocusLine( oldCurrent );
OnFocusLine( m_current );
} }
// forceClick is only set if the previous click was on another item // forceClick is only set if the previous click was on another item
@@ -3180,7 +3177,7 @@ void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
// items anyhow // items anyhow
if ( event.ShiftDown() && !IsSingleSel() ) if ( event.ShiftDown() && !IsSingleSel() )
{ {
m_current = newCurrent; ChangeCurrent(newCurrent);
// select all the items between the old and the new one // select all the items between the old and the new one
if ( oldCurrent > newCurrent ) if ( oldCurrent > newCurrent )
@@ -3197,7 +3194,7 @@ void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
if ( !event.ControlDown() ) if ( !event.ControlDown() )
HighlightAll(FALSE); HighlightAll(FALSE);
m_current = newCurrent; ChangeCurrent(newCurrent);
HighlightLine( oldCurrent, FALSE ); HighlightLine( oldCurrent, FALSE );
RefreshLine( oldCurrent ); RefreshLine( oldCurrent );
@@ -3208,8 +3205,6 @@ void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
} }
} }
OnUnfocusLine( oldCurrent );
OnFocusLine( m_current );
RefreshLine( m_current ); RefreshLine( m_current );
MoveToFocus(); MoveToFocus();
@@ -3711,9 +3706,7 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
// don't do anything if this item is already focused // don't do anything if this item is already focused
if ( item != m_current ) if ( item != m_current )
{ {
OnUnfocusLine( m_current ); ChangeCurrent(item);
m_current = item;
OnFocusLine( m_current );
if ( oldCurrent != (size_t)-1 ) if ( oldCurrent != (size_t)-1 )
{ {
@@ -3733,8 +3726,7 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
// don't do anything if this item is not focused // don't do anything if this item is not focused
if ( item == m_current ) if ( item == m_current )
{ {
OnUnfocusLine( m_current ); ResetCurrent();
m_current = (size_t)-1;
RefreshLine( oldCurrent ); RefreshLine( oldCurrent );
} }
@@ -3754,9 +3746,7 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
// single sel mode // single sel mode
if ( m_current != item ) if ( m_current != item )
{ {
OnUnfocusLine( m_current ); ChangeCurrent(item);
m_current = item;
OnFocusLine( m_current );
if ( oldCurrent != (size_t)-1 ) if ( oldCurrent != (size_t)-1 )
{ {
@@ -4013,12 +4003,7 @@ void wxListMainWindow::UpdateCurrent()
{ {
if ( !HasCurrent() && !IsEmpty() ) if ( !HasCurrent() && !IsEmpty() )
{ {
m_current = 0; ChangeCurrent(0);
}
if ( m_current != (size_t)-1 )
{
OnFocusLine( m_current );
} }
} }
@@ -4533,9 +4518,6 @@ wxListCtrl::wxListCtrl()
wxListCtrl::~wxListCtrl() wxListCtrl::~wxListCtrl()
{ {
if ( m_mainWin )
m_mainWin->ResetCurrent();
if (m_ownsImageListNormal) if (m_ownsImageListNormal)
delete m_imageListNormal; delete m_imageListNormal;
if (m_ownsImageListSmall) if (m_ownsImageListSmall)

View File

@@ -153,6 +153,7 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK) DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK) DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED) DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT) DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT)
IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)