]> git.saurik.com Git - wxWidgets.git/commitdiff
added missing refresh when changing focus in wxListCtrl, added test for it in the...
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 13 Aug 2001 15:41:18 +0000 (15:41 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 13 Aug 2001 15:41:18 +0000 (15:41 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11368 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/listctrl/listtest.cpp
samples/listctrl/listtest.h
src/generic/listctrl.cpp

index dbac0985fb5a2ce82f1b3f49762344b4eaa19621..8fc8a10781223d1a445d5d7293bfb9a9b87c25f5 100644 (file)
@@ -60,6 +60,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView)
     EVT_MENU(LIST_VIRTUAL_VIEW, MyFrame::OnVirtualView)
 
+    EVT_MENU(LIST_FOCUS_LAST, MyFrame::OnFocusLast)
     EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel)
     EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll)
     EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll)
@@ -180,6 +181,7 @@ MyFrame::MyFrame(const wxChar *title, int x, int y, int w, int h)
     menuView->Append(LIST_VIRTUAL_VIEW, _T("Virtual view\tF7"));
 
     wxMenu *menuList = new wxMenu;
+    menuList->Append(LIST_FOCUS_LAST, _T("&Make last item current\tCtrl-L"));
     menuList->Append(LIST_TOGGLE_FIRST, _T("&Toggle first item\tCtrl-T"));
     menuList->Append(LIST_DESELECT_ALL, _T("&Deselect All\tCtrl-D"));
     menuList->Append(LIST_SELECT_ALL, _T("S&elect All\tCtrl-A"));
@@ -252,6 +254,18 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
     dialog.ShowModal();
 }
 
+void MyFrame::OnFocusLast(wxCommandEvent& WXUNUSED(event))
+{
+    long index = m_listCtrl->GetItemCount() - 1;
+    if ( index == -1 )
+    {
+        return;
+    }
+
+    m_listCtrl->SetItemState(index, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
+    m_listCtrl->EnsureVisible(index);
+}
+
 void MyFrame::OnToggleFirstSel(wxCommandEvent& WXUNUSED(event))
 {
     m_listCtrl->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
index 005fb3f0e974b7a1b414b4e0a1feec779a5f7b00..f649e03a7960c75a0eb134b613180940c2e8c72d 100644 (file)
@@ -84,6 +84,7 @@ public:
     void OnSmallIconTextView(wxCommandEvent& event);
     void OnVirtualView(wxCommandEvent& event);
 
+    void OnFocusLast(wxCommandEvent& event);
     void OnToggleFirstSel(wxCommandEvent& event);
     void OnDeselectAll(wxCommandEvent& event);
     void OnSelectAll(wxCommandEvent& event);
@@ -144,6 +145,7 @@ enum
     LIST_TOGGLE_FIRST,
     LIST_SHOW_COL_INFO,
     LIST_SHOW_SEL_INFO,
+    LIST_FOCUS_LAST,
 
     LIST_CTRL                   = 1000
 };
index e4fc11143e1ee8011ff2ac0df0f0c8c64e08766b..8f641d4537b665a8c23a75cbb8c213e9255349ba 100644 (file)
@@ -3497,8 +3497,9 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
                   _T("invalid list ctrl item index in SetItem") );
 
     size_t oldCurrent = m_current;
-    size_t item = (size_t)litem;    // sdafe because of the check above
+    size_t item = (size_t)litem;    // safe because of the check above
 
+    // do we need to change the focus?
     if ( stateMask & wxLIST_STATE_FOCUSED )
     {
         if ( state & wxLIST_STATE_FOCUSED )
@@ -3510,9 +3511,13 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
                 m_current = item;
                 OnFocusLine( m_current );
 
-                if ( IsSingleSel() && (oldCurrent != (size_t)-1) )
+                if ( oldCurrent != (size_t)-1 )
                 {
-                    HighlightLine(oldCurrent, FALSE);
+                    if ( IsSingleSel() )
+                    {
+                        HighlightLine(oldCurrent, FALSE);
+                    }
+
                     RefreshLine(oldCurrent);
                 }
 
@@ -3526,10 +3531,13 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
             {
                 OnUnfocusLine( m_current );
                 m_current = (size_t)-1;
+
+                RefreshLine( oldCurrent );
             }
         }
     }
 
+    // do we need to change the selection state?
     if ( stateMask & wxLIST_STATE_SELECTED )
     {
         bool on = (state & wxLIST_STATE_SELECTED) != 0;