]> git.saurik.com Git - wxWidgets.git/commitdiff
use ListView_RedrawItems() to implement wxListCtrl::RefreshItems(); added tests for...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 16 Sep 2007 10:24:45 +0000 (10:24 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 16 Sep 2007 10:24:45 +0000 (10:24 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48717 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

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

index c2502a7096292698b1f353a8773ec5f8fe1119f8..c4c71463accab43a6f9555011915b3a081ad216a 100644 (file)
@@ -881,8 +881,7 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event)
 
     switch ( event.GetKeyCode() )
     {
-        case 'c': // colorize
-        case 'C':
+        case 'C': // colorize
             {
                 wxListItem info;
                 info.m_itemId = event.GetIndex();
@@ -906,8 +905,7 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event)
             }
             break;
 
-        case 'n': // next
-        case 'N':
+        case 'N': // next
             item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
             if ( item++ == GetItemCount() - 1 )
             {
@@ -920,8 +918,7 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event)
             EnsureVisible(item);
             break;
 
-        case 'r': // show bounding Rect
-        case 'R':
+        case 'R': // show bounding rectangle
             {
                 item = event.GetIndex();
                 wxRect r;
@@ -936,6 +933,26 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event)
             }
             break;
 
+        case 'U': // update
+            if ( !IsVirtual() )
+                break;
+
+            if ( m_updated != -1 )
+                RefreshItem(m_updated);
+
+            m_updated = event.GetIndex();
+            if ( m_updated != -1 )
+            {
+                // we won't see changes to this item as it's selected, update
+                // the next one (or the first one if we're on the last item)
+                if ( ++m_updated == GetItemCount() )
+                    m_updated = 0;
+
+                wxLogMessage("Updating colour of the item %ld", m_updated);
+                RefreshItem(m_updated);
+            }
+            break;
+
         case WXK_DELETE:
             item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
             while ( item != -1 )
@@ -981,6 +998,12 @@ void MyListCtrl::OnChar(wxKeyEvent& event)
         case 'N':
         case 'c':
         case 'C':
+        case 'r':
+        case 'R':
+        case 'u':
+        case 'U':
+        case WXK_DELETE:
+        case WXK_INSERT:
             // these are the keys we process ourselves
             break;
 
@@ -1032,7 +1055,7 @@ wxString MyListCtrl::OnGetItemText(long item, long column) const
     {
         return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
     }
-    else
+    else // "big" virtual control
     {
         return wxString::Format(_T("Column %ld of item %ld"), column, item);
     }
@@ -1043,7 +1066,7 @@ int MyListCtrl::OnGetItemColumnImage(long item, long column) const
     if (!column)
         return 0;
 
-    if (!(item %3) && column == 1)
+    if (!(item % 3) && column == 1)
         return 0;
 
     return -1;
@@ -1051,6 +1074,14 @@ int MyListCtrl::OnGetItemColumnImage(long item, long column) const
 
 wxListItemAttr *MyListCtrl::OnGetItemAttr(long item) const
 {
+    // test to check that RefreshItem() works correctly: when m_updated is
+    // set to some item and it is refreshed, we highlight the item
+    if ( item == m_updated )
+    {
+        static wxListItemAttr s_attrHighlight(*wxRED, wxNullColour, wxNullFont);
+        return &s_attrHighlight;
+    }
+
     return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
 }
 
index abc2db98bf0bef3e1d9ce5420e269febf221653a..2126c4b4b7b0252e86d1f6af855b24fbfcb47e20 100644 (file)
@@ -40,6 +40,8 @@ public:
         : wxListCtrl(parent, id, pos, size, style),
           m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont)
         {
+            m_updated = -1;
+
 #ifdef __POCKETPC__
             EnableContextMenu();
 #endif
@@ -88,6 +90,9 @@ private:
 
     wxListItemAttr m_attr;
 
+    long m_updated;
+
+
     DECLARE_NO_COPY_CLASS(MyListCtrl)
     DECLARE_EVENT_TABLE()
 };
index 65fb65b7d0f825b0eec7767840ed9f9aab3b3ca3..221b90cd3b49ef254d00b9ce1e1f1138edca0276 100644 (file)
@@ -2847,30 +2847,12 @@ void wxListCtrl::SetItemCount(long count)
 
 void wxListCtrl::RefreshItem(long item)
 {
-    // strangely enough, ListView_Update() results in much more flicker here
-    // than a dumb Refresh() -- why?
-#if 0
-    if ( !ListView_Update(GetHwnd(), item) )
-    {
-        wxLogLastError(_T("ListView_Update"));
-    }
-#else // 1
-    wxRect rect;
-    GetItemRect(item, rect);
-    RefreshRect(rect);
-#endif // 0/1
+    RefreshItems(item, item);
 }
 
 void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
 {
-    wxRect rect1, rect2;
-    GetItemRect(itemFrom, rect1);
-    GetItemRect(itemTo, rect2);
-
-    wxRect rect = rect1;
-    rect.height = rect2.GetBottom() - rect1.GetTop();
-
-    RefreshRect(rect);
+    ListView_RedrawItems(GetHwnd(), itemFrom, itemTo);
 }
 
 // ----------------------------------------------------------------------------