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:
parent
6dd25d20be
commit
ebc9b89d52
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user