use ListView_RedrawItems() to implement wxListCtrl::RefreshItems(); added tests for it to the sample
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48717 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -881,8 +881,7 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event)
|
|||||||
|
|
||||||
switch ( event.GetKeyCode() )
|
switch ( event.GetKeyCode() )
|
||||||
{
|
{
|
||||||
case 'c': // colorize
|
case 'C': // colorize
|
||||||
case 'C':
|
|
||||||
{
|
{
|
||||||
wxListItem info;
|
wxListItem info;
|
||||||
info.m_itemId = event.GetIndex();
|
info.m_itemId = event.GetIndex();
|
||||||
@@ -906,8 +905,7 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'n': // next
|
case 'N': // next
|
||||||
case 'N':
|
|
||||||
item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
|
item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
|
||||||
if ( item++ == GetItemCount() - 1 )
|
if ( item++ == GetItemCount() - 1 )
|
||||||
{
|
{
|
||||||
@@ -920,8 +918,7 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event)
|
|||||||
EnsureVisible(item);
|
EnsureVisible(item);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r': // show bounding Rect
|
case 'R': // show bounding rectangle
|
||||||
case 'R':
|
|
||||||
{
|
{
|
||||||
item = event.GetIndex();
|
item = event.GetIndex();
|
||||||
wxRect r;
|
wxRect r;
|
||||||
@@ -936,6 +933,26 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event)
|
|||||||
}
|
}
|
||||||
break;
|
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:
|
case WXK_DELETE:
|
||||||
item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
||||||
while ( item != -1 )
|
while ( item != -1 )
|
||||||
@@ -981,6 +998,12 @@ void MyListCtrl::OnChar(wxKeyEvent& event)
|
|||||||
case 'N':
|
case 'N':
|
||||||
case 'c':
|
case 'c':
|
||||||
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
|
// these are the keys we process ourselves
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1032,7 +1055,7 @@ wxString MyListCtrl::OnGetItemText(long item, long column) const
|
|||||||
{
|
{
|
||||||
return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
|
return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
|
||||||
}
|
}
|
||||||
else
|
else // "big" virtual control
|
||||||
{
|
{
|
||||||
return wxString::Format(_T("Column %ld of item %ld"), column, item);
|
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)
|
if (!column)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!(item %3) && column == 1)
|
if (!(item % 3) && column == 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@@ -1051,6 +1074,14 @@ int MyListCtrl::OnGetItemColumnImage(long item, long column) const
|
|||||||
|
|
||||||
wxListItemAttr *MyListCtrl::OnGetItemAttr(long item) 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;
|
return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -40,6 +40,8 @@ public:
|
|||||||
: wxListCtrl(parent, id, pos, size, style),
|
: wxListCtrl(parent, id, pos, size, style),
|
||||||
m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont)
|
m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont)
|
||||||
{
|
{
|
||||||
|
m_updated = -1;
|
||||||
|
|
||||||
#ifdef __POCKETPC__
|
#ifdef __POCKETPC__
|
||||||
EnableContextMenu();
|
EnableContextMenu();
|
||||||
#endif
|
#endif
|
||||||
@@ -88,6 +90,9 @@ private:
|
|||||||
|
|
||||||
wxListItemAttr m_attr;
|
wxListItemAttr m_attr;
|
||||||
|
|
||||||
|
long m_updated;
|
||||||
|
|
||||||
|
|
||||||
DECLARE_NO_COPY_CLASS(MyListCtrl)
|
DECLARE_NO_COPY_CLASS(MyListCtrl)
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
@@ -2847,30 +2847,12 @@ void wxListCtrl::SetItemCount(long count)
|
|||||||
|
|
||||||
void wxListCtrl::RefreshItem(long item)
|
void wxListCtrl::RefreshItem(long item)
|
||||||
{
|
{
|
||||||
// strangely enough, ListView_Update() results in much more flicker here
|
RefreshItems(item, item);
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
|
void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
|
||||||
{
|
{
|
||||||
wxRect rect1, rect2;
|
ListView_RedrawItems(GetHwnd(), itemFrom, itemTo);
|
||||||
GetItemRect(itemFrom, rect1);
|
|
||||||
GetItemRect(itemTo, rect2);
|
|
||||||
|
|
||||||
wxRect rect = rect1;
|
|
||||||
rect.height = rect2.GetBottom() - rect1.GetTop();
|
|
||||||
|
|
||||||
RefreshRect(rect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user