2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #ifndef GENERICCLIENTLISTCTRL_H
26 #define GENERICCLIENTLISTCTRL_H
28 #include <map> // Needed for std::multimap
29 #include <vector> // Needed for std::vector
32 #include "Types.h" // Needed for uint8
33 #include "Constants.h" // Needed for DownloadItemType
34 #include "MuleListCtrl.h" // Needed for CMuleListCtrl
35 #include "amuleDlg.h" // Needed for CamuleDlg::DialogType
43 struct ClientCtrlItem_Struct
;
45 enum GenericColumnEnum
{
53 ColumnUserQueueRankLocal
,
54 ColumnUserQueueRankRemote
,
60 struct CGenericClientListCtrlColumn
{
61 GenericColumnEnum cid
;
66 struct GenericColumnInfo
{
67 GenericColumnInfo(int n
, CGenericClientListCtrlColumn
* col
) : n_columns(n
), columns(col
) { };
69 CGenericClientListCtrlColumn
* columns
;
72 typedef std::vector
<CKnownFile
*> CKnownFileVector
;
75 * This class is responsible for representing clients in a generic way.
78 class CGenericClientListCtrl
: public CMuleListCtrl
84 * @see CMuleListCtrl::CMuleListCtrl for documentation of parameters.
86 CGenericClientListCtrl(
87 const wxString
& tablename
,
93 const wxValidator
& validator
,
94 const wxString
&name
);
99 virtual ~CGenericClientListCtrl();
102 * Initializes the control. We need a 2-stage initialization so the derived class members can be called.
104 void InitColumnData();
107 * Adds a source belonging to the specified file.
109 * @param owner The owner of this specific source-entry, must be a valid pointer.
110 * @param source The client object to be added, must be a valid pointer.
111 * @param type If the source is a current source, or a A4AF source.
113 * Please note that the specified client will only be added to the list if it's
114 * owner is shown, otherwise the source will simply be ignored.
115 * Duplicates wont be added.
117 void AddSource( CKnownFile
* owner
, CUpDownClient
* source
, SourceItemType type
);
120 * Removes a source from the list.
122 * @param source A pointer to the source to be removed.
123 * @param owner Either a specific file, or NULL to remove the source from all files.
125 void RemoveSource( const CUpDownClient
* source
, const CKnownFile
* owner
);
128 * Shows the clients of specific files.
130 * @param file A valid, sorted vector of files whose clients will be shown.
132 * WARNING: The received vector *MUST* be odered with std::sort.
135 void ShowSources( const CKnownFileVector
& files
);
138 * Updates the state of the specified item, possibly causing a redrawing.
140 * @param toupdate The client to be updated.
141 * @param type If the source is a current source, or a A4AF source.
144 void UpdateItem(const void* toupdate
, SourceItemType type
);
146 void SetShowing( bool status
) { m_showing
= status
; }
147 bool GetShowing() const { return m_showing
; }
150 // The columns with their attributes; MUST be defined by the derived class.
151 GenericColumnInfo m_columndata
;
152 static int wxCALLBACK
SortProc(wxUIntPtr item1
, wxUIntPtr item2
, long sortData
);
157 * Must be overriden by the derived class and return the dialog where this list is.
158 * @see CamuleDlg::DialogType
161 virtual CamuleDlg::DialogType
GetParentDialog() = 0;
164 * Updates the displayed number representing the amount of clients currently shown.
166 void ShowSourcesCount( int diff
);
169 * Overloaded function needed for custom drawing of items.
171 virtual void OnDrawItem( int item
, wxDC
* dc
, const wxRect
& rect
, const wxRect
& rectHL
, bool highlighted
);
174 * Draws a client item.
176 void DrawClientItem( wxDC
* dc
, int nColumn
, const wxRect
& rect
, ClientCtrlItem_Struct
* item
) const;
179 * Draws the download status (chunk) bar for a client.
181 void DrawSourceStatusBar( const CUpDownClient
* source
, wxDC
* dc
, const wxRect
& rect
, bool bFlat
) const;
183 static int Compare( const CUpDownClient
* client1
, const CUpDownClient
* client2
, long lParamColumnSort
);
185 // Event-handlers for clients.
186 void OnSwapSource( wxCommandEvent
& event
);
187 void OnViewFiles( wxCommandEvent
& event
);
188 void OnAddFriend( wxCommandEvent
& event
);
189 void OnSendMessage( wxCommandEvent
& event
);
190 void OnViewClientInfo( wxCommandEvent
& event
);
192 // Misc event-handlers
193 void OnItemActivated( wxListEvent
& event
);
194 void OnMouseRightClick( wxListEvent
& event
);
195 void OnMouseMiddleClick( wxListEvent
& event
);
196 void OnKeyPressed( wxKeyEvent
& event
);
198 //! The type of list used to store items on the listctrl.
199 typedef std::multimap
<const void*,ClientCtrlItem_Struct
*> ListItems
;
200 //! Shortcut to the pair-type used on the list.
201 typedef ListItems::value_type ListItemsPair
;
202 //! This pair is used when searching for equal-ranges.
203 typedef std::pair
< ListItems::iterator
, ListItems::iterator
> ListIteratorPair
;
205 //! This list contains everything shown on the list. Sources are only to
206 //! be found on this list if they are being displayed
207 ListItems m_ListItems
;
209 //! Pointer to the current menu object, used to avoid multiple menus.
211 //! Cached brush object.
212 wxBrush m_hilightBrush
;
213 //! Cached brush object.
214 wxBrush m_hilightUnfocusBrush
;
216 //! The number of displayed sources
219 //! The files being shown, if any.
220 CKnownFileVector m_knownfiles
;
222 DECLARE_EVENT_TABLE()
226 void RawAddSource(CKnownFile
* owner
, CUpDownClient
* source
, SourceItemType type
);
227 void RawRemoveSource( ListItems::iterator
& it
);
231 // File_checked_for_headers