]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxEVT_COMMAND_LIST_ITEM_FOCUSED event and implemented it for the generic version
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 16 Nov 2001 16:31:17 +0000 (16:31 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 16 Nov 2001 16:31:17 +0000 (16:31 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12449 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/latex/wx/listctrl.tex
docs/latex/wx/listevt.tex
include/wx/listctrl.h
samples/listctrl/listtest.cpp
samples/listctrl/listtest.h
src/generic/listctrl.cpp
src/msw/listctrl.cpp

index d3c1678b7fa3232766c7e423c0e42b4537813fa0..1171ba8284aaac669eb7b2e747cfcc91d7006040 100644 (file)
@@ -63,6 +63,7 @@ All (GUI):
 - wxWizard changes: loading from WXR support, help button (Robert Cavanaugh)
 - wxDirSelector() added (Paul A. Thiessen)
 - wxGrid cell editing veto support (Roger Gammans)
+- wxListCtrl ITEM_FOCUSED event added
 
 wxMSW:
 
index f3c0c9b79b9c7a29b3dcd5e36bc91d98ed3531c6..496e78628f86c117eabccf81ca2552d0f48923fe 100644 (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\_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\_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\_KEY\_DOWN(id, func)}}{A key has been pressed.}
 \twocolitem{{\bf EVT\_LIST\_INSERT\_ITEM(id, func)}}{An item has been inserted.}
index b5deec340ceb60a88e4fed9af6d263fd698dc920..003449b9f273fcb07ae49cf9fb4ea5e1ec638ab0 100644 (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\_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\_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\_KEY\_DOWN(id, func)}}{A key has been pressed.}
 \twocolitem{{\bf EVT\_LIST\_INSERT\_ITEM(id, func)}}{An item has been inserted.}
index 6ea87b9abd77898ef9d5348c0e73f9e6ebb34fb4..b6ee6e27efea38c968faca7215fb638972292865 100644 (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_DRAGGING, 719)
     DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG, 720)
+    DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED, 721)
 END_DECLARE_EVENT_TYPES()
 
 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_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_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 ),
 
index 9796a033b7de101a4fd2cbf20831cb684b71dd74..2de2923e3283253a39a5b09988e14a2c4fecf481 100644 (file)
@@ -92,6 +92,7 @@ BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
     EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected)
     EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
     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_RIGHT_CLICK(LIST_CTRL, MyListCtrl::OnColRightClick)
@@ -750,6 +751,11 @@ void MyListCtrl::OnActivated(wxListEvent& event)
     LogEvent(event, _T("OnActivated"));
 }
 
+void MyListCtrl::OnFocused(wxListEvent& event)
+{
+    LogEvent(event, _T("OnFocused"));
+}
+
 void MyListCtrl::OnListKeyDown(wxListEvent& event)
 {
     switch ( event.GetCode() )
index 803fd1396e1ca9f77b7c3b055bb06ea21262b85b..6578e4df761836a4e705bf1377afe24ff57ec9c5 100644 (file)
@@ -49,6 +49,7 @@ public:
     void OnDeselected(wxListEvent& event);
     void OnListKeyDown(wxListEvent& event);
     void OnActivated(wxListEvent& event);
+    void OnFocused(wxListEvent& event);
     void OnCacheHint(wxListEvent& event);
 
     void OnChar(wxKeyEvent& event);
index 16ec1bbabc9686b042a191657bb9abd13750ae26..6008a869de6237c3460f6a503ee8deca35229752 100644 (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_MIDDLE_CLICK)
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED)
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT)
 
 // ----------------------------------------------------------------------------
@@ -684,7 +685,9 @@ public:
     bool IsEmpty() const { return GetItemCount() == 0; }
     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; }
 
     // send out a wxListEvent
@@ -827,12 +830,6 @@ private:
     // delete all items but don't refresh: called from dtor
     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
     wxCoord m_lineHeight;
 
@@ -2865,21 +2862,22 @@ void wxListMainWindow::SendNotify( size_t line,
     // what we're trying to avoid
     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
 
     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( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
+    SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSED);
 }
 
 void wxListMainWindow::EditLabel( long item )
@@ -3086,7 +3084,8 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
         if ( IsSingleSel() || !(event.ControlDown() || event.ShiftDown()) )
         {
             HighlightAll( FALSE );
-            m_current = current;
+
+            ChangeCurrent(current);
 
             ReverseHighlight(m_current);
         }
@@ -3094,13 +3093,13 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
         {
             if (event.ControlDown())
             {
-                m_current = current;
+                ChangeCurrent(current);
 
                 ReverseHighlight(m_current);
             }
             else if (event.ShiftDown())
             {
-                m_current = current;
+                ChangeCurrent(current);
 
                 size_t lineFrom = oldCurrent,
                        lineTo = current;
@@ -3123,8 +3122,6 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
         if (m_current != oldCurrent)
         {
             RefreshLine( oldCurrent );
-            OnUnfocusLine( oldCurrent );
-            OnFocusLine( m_current );
         }
 
         // 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
     if ( event.ShiftDown() && !IsSingleSel() )
     {
-        m_current = newCurrent;
+        ChangeCurrent(newCurrent);
 
         // select all the items between the old and the new one
         if ( oldCurrent > newCurrent )
@@ -3197,7 +3194,7 @@ void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
         if ( !event.ControlDown() )
             HighlightAll(FALSE);
 
-        m_current = newCurrent;
+        ChangeCurrent(newCurrent);
 
         HighlightLine( oldCurrent, FALSE );
         RefreshLine( oldCurrent );
@@ -3208,8 +3205,6 @@ void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
         }
     }
 
-    OnUnfocusLine( oldCurrent );
-    OnFocusLine( m_current );
     RefreshLine( m_current );
 
     MoveToFocus();
@@ -3711,9 +3706,7 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
             // don't do anything if this item is already focused
             if ( item != m_current )
             {
-                OnUnfocusLine( m_current );
-                m_current = item;
-                OnFocusLine( m_current );
+                ChangeCurrent(item);
 
                 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
             if ( item == m_current )
             {
-                OnUnfocusLine( m_current );
-                m_current = (size_t)-1;
+                ResetCurrent();
 
                 RefreshLine( oldCurrent );
             }
@@ -3754,9 +3746,7 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
                 // single sel mode
                 if ( m_current != item )
                 {
-                    OnUnfocusLine( m_current );
-                    m_current = item;
-                    OnFocusLine( m_current );
+                    ChangeCurrent(item);
 
                     if ( oldCurrent != (size_t)-1 )
                     {
@@ -4013,12 +4003,7 @@ void wxListMainWindow::UpdateCurrent()
 {
     if ( !HasCurrent() && !IsEmpty() )
     {
-        m_current = 0;
-    }
-
-    if ( m_current != (size_t)-1 )
-    {
-        OnFocusLine( m_current );
+        ChangeCurrent(0);
     }
 }
 
@@ -4533,9 +4518,6 @@ wxListCtrl::wxListCtrl()
 
 wxListCtrl::~wxListCtrl()
 {
-    if ( m_mainWin )
-        m_mainWin->ResetCurrent();
-
     if (m_ownsImageListNormal)
         delete m_imageListNormal;
     if (m_ownsImageListSmall)
index f16980f75f603e08fb4be590353660920608aba3..6c5d4a3e28ada5ebf8e1cdc2aa53ef0b0d88dabb 100644 (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_MIDDLE_CLICK)
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED)
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT)
 
 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)