Improve speed of category tab title updates
[amule.git] / src / DownloadListCtrl.h
blob41baa92865e01bf424c0a28a61932b1931cb4ba7
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #ifndef DOWNLOADLISTCTRL_H
27 #define DOWNLOADLISTCTRL_H
29 #include <map> // Needed for std::multimap
30 #include <wx/brush.h>
32 #include "Types.h" // Needed for uint8
33 #include "Constants.h" // Needed for DownloadItemType
34 #include "MuleListCtrl.h" // Needed for CMuleListCtrl
37 class CPartFile;
38 class wxBitmap;
39 class wxRect;
40 class wxDC;
42 struct FileCtrlItem_Struct;
44 /**
45 * This class is responsible for representing the download queue.
47 * The CDownlodListCtrl class is responsible for drawing files being downloaded.
48 * It is in many ways primary widget within the application, since it is here that
49 * users can inspect and manipulate their current downloads.
52 class CDownloadListCtrl : public CMuleListCtrl
54 public:
55 /**
56 * Constructor.
58 * @see CMuleListCtrl::CMuleListCtrl for documentation of parameters.
60 CDownloadListCtrl(
61 wxWindow *parent,
62 wxWindowID winid = -1,
63 const wxPoint &pos = wxDefaultPosition,
64 const wxSize &size = wxDefaultSize,
65 long style = wxLC_ICON,
66 const wxValidator& validator = wxDefaultValidator,
67 const wxString &name = wxT("downloadlistctrl") );
69 /**
70 * Destructor.
71 */
72 virtual ~CDownloadListCtrl();
75 /**
76 * Adds a file to the list, but it wont show unless it matches the current category.
78 * @param A valid pointer to a new partfile.
80 * Please note that duplicates wont be added.
82 void AddFile( CPartFile* file );
84 /**
85 * Removes the specified file from the list.
87 * @param file A valid pointer of the file to be removed.
89 * This function also removes any sources assosiated with the file.
91 void RemoveFile( CPartFile* file );
93 /**
94 * Shows or hides the sources of a specific file.
96 * @param file A valid pointer to the file to be shown/hidden.
97 * @param show Whenever or not to show the file.
99 * If the file is hidden, then its sources will also be hidden.
101 void ShowFile( CPartFile* file, bool show );
105 * Updates the state of the specified item, possibly causing a redrawing.
107 * @param toupdate The source or file to be updated.
109 * Calling this function with a file as the argument will ensure that the
110 * file is hidden/shown depending on its state and the currently selected
111 * category.
113 void UpdateItem(const void* toupdate);
116 * Returns the current category.
118 uint8 GetCategory() const;
121 * Changes the displayed category and updates the list of shown files.
123 * @param newCategory The new category to display.
125 void ChangeCategory( int newCategory );
129 * Clears all completed files from the list.
131 void ClearCompleted();
133 protected:
134 /// Return old column order.
135 wxString GetOldColumnOrder() const;
137 private:
139 * Updates the displayed number representing the amount of files currently shown.
141 void ShowFilesCount( int diff );
145 * @see CMuleListCtrl::GetTTSText
147 virtual wxString GetTTSText(unsigned item) const;
151 * Overloaded function needed for custom drawing of items.
153 virtual void OnDrawItem( int item, wxDC* dc, const wxRect& rect, const wxRect& rectHL, bool highlighted );
156 * Draws a file item.
158 void DrawFileItem( wxDC* dc, int nColumn, const wxRect& rect, FileCtrlItem_Struct* item ) const;
161 * Draws the status (chunk) bar for a file.
163 void DrawFileStatusBar( const CPartFile* file, wxDC* dc, const wxRect& rect, bool bFlat ) const;
165 static int wxCALLBACK SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData);
166 static int Compare( const CPartFile* file1, const CPartFile* file2, long lParamSort );
168 // Event-handlers for files
169 void OnCancelFile( wxCommandEvent& event );
170 void OnSetPriority( wxCommandEvent& event );
171 void OnSwapSources( wxCommandEvent& event );
172 void OnSetCategory( wxCommandEvent& event );
173 void OnSetStatus( wxCommandEvent& event );
174 void OnClearCompleted( wxCommandEvent& event );
175 void OnGetLink( wxCommandEvent& event );
176 void OnGetFeedback( wxCommandEvent& event );
177 void OnViewFileInfo( wxCommandEvent& event );
178 void OnViewFileComments( wxCommandEvent& event );
179 void OnPreviewFile( wxCommandEvent& event );
181 // Misc event-handlers
182 void OnItemActivated( wxListEvent& event );
183 void OnMouseRightClick( wxListEvent& event );
184 void OnMouseMiddleClick( wxListEvent& event );
185 void OnKeyPressed( wxKeyEvent& event );
186 void OnItemSelectionChanged( wxListEvent& event );
189 * Executes the user-selected preview command on the specified file.
191 * @file The file to be previewed.
193 void PreviewFile(CPartFile* file);
196 //! The type of list used to store items on the listctrl.
197 typedef std::multimap<const void*,FileCtrlItem_Struct*> ListItems;
198 //! Shortcut to the pair-type used on the list.
199 typedef ListItems::value_type ListItemsPair;
200 //! This pair is used when searching for equal-ranges.
201 typedef std::pair< ListItems::iterator, ListItems::iterator > ListIteratorPair;
203 //! This list contains everything shown on the list. Sources are only to
204 //! be found on this list if they are being displayed, whereas files can
205 //! always be found on this list, even if they are currently hidden.
206 ListItems m_ListItems;
209 //! Pointer to the current menu object, used to avoid multiple menus.
210 wxMenu* m_menu;
211 //! Cached brush object.
212 wxBrush m_hilightBrush;
213 //! Cached brush object.
214 wxBrush m_hilightUnfocusBrush;
216 //! The currently displayed category
217 uint8 m_category;
219 //! The number of displayed files
220 int m_filecount;
222 DECLARE_EVENT_TABLE()
226 #endif
227 // File_checked_for_headers