1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 08:43:27 +00:00

reduce flicker in the torrent list

This commit is contained in:
Charles Kerr 2007-08-03 20:46:02 +00:00
parent 03845215de
commit 8be21b668b
3 changed files with 36 additions and 14 deletions

View file

@ -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<tr_torrent_t*> 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

View file

@ -79,10 +79,10 @@ class TorrentListCtrl: public wxListCtrl
public:
typedef std::vector<tr_torrent_t*> 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<int>& );
@ -93,6 +93,9 @@ class TorrentListCtrl: public wxListCtrl
typedef std::map<std::string,int> 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;

View file

@ -29,6 +29,7 @@
#include <wx/notebook.h>
#include <wx/snglinst.h>
#include <wx/splitter.h>
#include <wx/statline.h>
#include <wx/taskbar.h>
#include <wx/tglbtn.h>
#include <wx/toolbar.h>
@ -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;