From 8be21b668b5a81e3fef3513d7ceebce5582c2974 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 3 Aug 2007 20:46:02 +0000 Subject: [PATCH] reduce flicker in the torrent list --- wx/torrent-list.cc | 34 +++++++++++++++++++++++++--------- wx/torrent-list.h | 6 +++++- wx/xmission.cc | 10 ++++++---- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/wx/torrent-list.cc b/wx/torrent-list.cc index 9d32a6eaf..743b33d8f 100644 --- a/wx/torrent-list.cc +++ b/wx/torrent-list.cc @@ -3,7 +3,7 @@ * * This file is licensed by the GPL version 2. Works owned by the * Transmission project are granted a special exemption to clause 2(b) - * so that the bulk of its code can remain under the MIT license. + * so that the bulk of its code can remain under the MIT license. * This exemption does not extend to derived works not owned by * the Transmission project. */ @@ -171,6 +171,8 @@ BEGIN_EVENT_TABLE(TorrentListCtrl, wxListCtrl) EVT_LIST_ITEM_DESELECTED( TORRENT_LIST_CTRL, TorrentListCtrl::OnItemDeselected ) END_EVENT_TABLE() + + TorrentListCtrl :: TorrentListCtrl( tr_handle_t * handle, wxConfig * config, wxWindow * parent, @@ -194,6 +196,18 @@ TorrentListCtrl :: ~TorrentListCtrl() { } +void +TorrentListCtrl :: SetCell( int item, int column, const wxString& xstr ) +{ + wxListItem i; + i.SetId( item ); + i.SetColumn( column ); + i.SetMask( wxLIST_MASK_TEXT ); + GetItem( i ); + if( i.GetText() != xstr ) + SetItem( item, column, xstr ); +} + void TorrentListCtrl :: RefreshTorrent( tr_torrent_t * tor, int myTorrents_index, @@ -247,7 +261,7 @@ TorrentListCtrl :: RefreshTorrent( tr_torrent_t * tor, break; case COL_PEERS: - xstr = wxString::Format( _("%d of %d"), s->peersConnected, s->leechers ); + xstr = wxString::Format( _("%d (%d)"), s->peersConnected, s->leechers ); break; case COL_RATIO: @@ -307,7 +321,7 @@ TorrentListCtrl :: RefreshTorrent( tr_torrent_t * tor, } if( col ) - SetItem( row, col++, xstr ); + SetCell( row, col++, xstr ); else { // first column... find the right row to put the info in. // if the torrent's in the list already, update that row. @@ -319,7 +333,7 @@ TorrentListCtrl :: RefreshTorrent( tr_torrent_t * tor, } } if( row >= 0 ) { - SetItem( row, col++, xstr ); + SetCell( row, col++, xstr ); } else { row = InsertItem( GetItemCount(), xstr ); @@ -602,7 +616,7 @@ TorrentListCtrl :: Rebuild() InsertColumn( i++, h, format, width ); } - Repopulate (); + Repopulate( ); } typedef std::set torrent_set; @@ -614,11 +628,14 @@ TorrentListCtrl :: Assign( const torrents_t& torrents ) torrents_v added; prev.insert( myTorrents.begin(), myTorrents.end() ); cur.insert( torrents.begin(), torrents.end() ); - std::set_difference (prev.begin(), prev.end(), cur.begin(), cur.end(), inserter(removed, removed.begin())); - std::set_difference (cur.begin(), cur.end(), prev.begin(), prev.end(), inserter(added, added.begin())); + std::set_difference (prev.begin(), prev.end(), + cur.begin(), cur.end(), inserter(removed, removed.begin())); + std::set_difference (cur.begin(), cur.end(), + prev.begin(), prev.end(), inserter(added, added.begin())); Remove( removed ); Add( added ); - Refresh (); + Refresh( ); + Resort( ); } void @@ -629,7 +646,6 @@ TorrentListCtrl :: Add( const torrents_v& add ) myTorrents.insert( myTorrents.end(), add.begin(), add.end() ); for( torrents_v::const_iterator it(add.begin()), end(add.end()); it!=end; ++it ) RefreshTorrent( *it, i++, cols ); - Resort( ); } void diff --git a/wx/torrent-list.h b/wx/torrent-list.h index 9a33fdcc3..a66a39286 100644 --- a/wx/torrent-list.h +++ b/wx/torrent-list.h @@ -79,10 +79,10 @@ class TorrentListCtrl: public wxListCtrl public: typedef std::vector torrents_v; - void Add( const torrents_v& torrents ); void Assign( const torrents_v& torrents ); private: + void Add( const torrents_v& torrents ); void Sort( int column ); void Resort( ); void RefreshTorrent( tr_torrent_t*, int, const std::vector& ); @@ -93,6 +93,9 @@ class TorrentListCtrl: public wxListCtrl typedef std::map str2int_t; str2int_t myHashToItem; + private: + void SetCell( int item, int col, const wxString& xstr ); + private: struct TorStat { time_t time; @@ -108,6 +111,7 @@ class TorrentListCtrl: public wxListCtrl void OnItemSelected( wxListEvent& ); void OnItemDeselected( wxListEvent& ); + private: tr_handle_t * myHandle; wxConfig * myConfig; diff --git a/wx/xmission.cc b/wx/xmission.cc index 6a16bd232..672cd9589 100755 --- a/wx/xmission.cc +++ b/wx/xmission.cc @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -442,6 +443,7 @@ MyFrame :: OnPulse(wxTimerEvent& WXUNUSED(event) ) } RefreshFilterCounts( ); + ApplyCurrentFilter( ); mySpeedStats->Update( handle ); @@ -541,8 +543,8 @@ MyFrame :: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size wxIcon drop_icon( minus_xpm ); wxBitmap bitmap; - wxToolBar* toolbar = CreateToolBar( wxNO_BORDER | wxTB_HORIZONTAL | wxTB_FLAT | wxTB_TEXT ); - toolbar->SetToolBitmapSize( wxSize( 16, 16 ) ); + wxToolBar* toolbar = CreateToolBar( wxTB_FLAT ); + toolbar->SetToolBitmapSize( wxSize( 24, 24 ) ); bitmap.CopyFromIcon( open_icon ); toolbar->AddTool( wxID_OPEN, _T("Open"), bitmap ); bitmap.CopyFromIcon( exec_icon ); @@ -557,7 +559,7 @@ MyFrame :: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size *** Row 1 **/ - wxSplitterWindow * hsplit = new wxSplitterWindow( this ); + wxSplitterWindow * hsplit = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3DSASH ); #if wxCHECK_VERSION(2,5,4) hsplit->SetSashGravity( 0.8 ); #endif @@ -582,6 +584,7 @@ MyFrame :: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size myTorrentList->AddListener( this ); wxBoxSizer * panelSizer = new wxBoxSizer( wxVERTICAL ); + panelSizer->Add( new wxStaticLine( panel_1 ), 0, wxEXPAND, 0 ); panelSizer->Add( buttonSizer, 0, 0, 0 ); panelSizer->Add( myTorrentList, 1, wxEXPAND, 0 ); @@ -630,7 +633,6 @@ MyFrame :: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size int count = 0; tr_torrent_t ** torrents = tr_loadTorrents ( handle, mySavePath.c_str(), flags, &count ); myTorrents.insert( myTorrents.end(), torrents, torrents+count ); - myTorrentList->Add( myTorrents ); tr_free( torrents ); wxTimerEvent dummy;