Upstream tarball 20080414
[amule.git] / src / ClientListCtrl.h
blobb496efaa14365ffe61fa6a184945bab369cae2c0
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 CLIENTLISTCTRL_H
27 #define CLIENTLISTCTRL_H
29 #include "MuleListCtrl.h" // Needed for CMuleListCtrl
30 #include "Constants.h" // Needed for ViewType
33 class CUpDownClient;
36 /**
37 * This class represents a number of ways of displaying clients, currently
38 * supporting 3 different "ViewTypes". In other words, this class superseeds
39 * the 3 widgets that were used to display clients beforehand:
40 * - CUploadListCtrl
41 * - CQueueListCtrl
42 * - CClientListCtrl
44 * This is done in an modular fashion, which means that adding new views is a
45 * rather trivial task. This approch has the advantage that only one widget exists
46 * and thus only one actual list is maintained at a time, even though the number
47 * of calls to the list wont decrease. This however can be trivially fixed if needed.
49 class CClientListCtrl : public CMuleListCtrl
51 public:
52 /**
53 * Constructor.
55 * @see CMuleListCtrl::CMuleListCtrl
57 CClientListCtrl(
58 wxWindow *parent,
59 wxWindowID winid = -1,
60 const wxPoint &pos = wxDefaultPosition,
61 const wxSize &size = wxDefaultSize,
62 long style = wxLC_ICON,
63 const wxValidator& validator = wxDefaultValidator,
64 const wxString &name = wxT("clientlistctrl") );
66 /**
67 * Destructor.
68 */
69 ~CClientListCtrl();
72 /**
73 * Returns the current view-type.
75 * @return The viewtype set by the user or the default value.
77 ViewType GetListView();
79 /**
80 * Sets another view-type.
82 * @param newView A view-mode different from the current view-type.
84 * Calling this function resets the list and re-initializes it to display
85 * clients acording to the specifications of that view-mode. If you wish
86 * to susspend the list, then use vtNone as the argument.
88 void SetListView( ViewType newView );
91 /**
92 * Adds a new client to the list.
94 * @param client The client to be added.
95 * @param view The view where the client should be displayed.
97 * This function adds the specified client to the list, provided that the
98 * view parameter matches the currently selected view-mode.
100 void InsertClient( CUpDownClient* client, ViewType view );
103 * Removes a client from the list.
105 * @param client The client to be removed.
106 * @param view The view where the client is being displayed.
108 * This function removes the specified client from the list, provided that
109 * the view parameter matches the currently selected view-mode.
111 void RemoveClient( CUpDownClient* client, ViewType view );
114 * Updates a client on the list.
116 * @param client The client to be updated.
117 * @param view The view where the client is being displayed.
119 * This function updates (redraws) the specified client on the list, provided
120 * that the view parameter matches the currently selected view-mode. Clients
121 * that are outside the currently visible range will also be ignored.
123 void UpdateClient( CUpDownClient* client, ViewType view );
127 * This function toggles between the different view-types.
129 * Calling this function makes the list switch to the next view-type
130 * available, provided that the current view-type isn't vtNone. The
131 * sequence is as specified in the ViewType enum, with the exception
132 * that vtNone will be skipped.
134 void ToggleView();
137 private:
139 * Custom cell-drawing function.
141 virtual void OnDrawItem(int item, wxDC* dc, const wxRect& rc, const wxRect& rectHL, bool hl);
144 * @see CMuleListCtrl::GetTTSText
146 virtual wxString GetTTSText(unsigned item) const;
150 * Event-handler for displaying a menu at right-clicks.
152 void OnRightClick( wxMouseEvent& event );
155 * Event-handler for displaying the client-details dialog upon middle-clicks.
157 void OnMiddleClick( wxListEvent& event );
160 * Event-handler for switching between the different view-types.
162 void OnChangeView( wxCommandEvent& event );
165 * Event-handler for adding a client on the list to the list of friends.
167 void OnAddFriend( wxCommandEvent& event );
170 * Event-handler for showing details about a client.
172 void OnShowDetails( wxCommandEvent& event );
175 * Event-handler for requesting the sharedfiles-list of a client.
177 void OnViewFiles( wxCommandEvent& event );
180 * Event-handler for sending a message to a specific client.
182 void OnSendMessage( wxCommandEvent& event );
185 * Event-handler for un-banning a client.
187 void OnUnbanClient( wxCommandEvent& event );
190 //! The current view-type. The default value is vtUploading.
191 ViewType m_viewType;
193 //! A pointer to the displayed menu, used to ensure that only one menu is displayed at a time.
194 wxMenu* m_menu;
196 //! A pointer to one of the two most used brushes, cached for performance reasons.
197 wxBrush* m_hilightBrush;
199 //! A pointer to one of the two most used brushes, cached for performance reasons.
200 wxBrush* m_hilightUnfocusBrush;
203 DECLARE_EVENT_TABLE()
209 * This is the default view for the list, representing a list of clients recieving files.
211 * This struct contains the functions needed to realize the uploading-view. It contains
212 * the functions used by the CClientListCtrl to prepare, sort and draw the list when the
213 * Uploading-view is enabled.
215 struct CUploadingView
218 * Initializes the view.
220 * @param list The list which wants to make use of the view.
222 * This function is called when the CClientListCtrl changes to this view-type,
223 * and it is responsible for setting the initial columns and contents. By the
224 * time this function is called, the list will already be completly empty.
226 static void Initialize( CClientListCtrl* list );
229 * Draws a specific cell.
231 * @param client The client used as a reference.
232 * @param column The column to be drawn.
233 * @param dc The device-context to draw onto.
234 * @param rect The rectangle to draw in.
236 * This function is used to draw the contents of each row, and is called for
237 * every visible column.
239 static void DrawCell( CUpDownClient* client, int column, wxDC* dc, const wxRect& rect );
242 * This is the sorter-function used by the listctrl to sort the contents.
244 * @see wxListCtrl::SortItems
246 static int wxCALLBACK SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData);
249 * Helperfunction which draws a simple bar-span over the clients requested file.
251 static void DrawStatusBar( CUpDownClient* client, wxDC* dc, const wxRect &rect );
256 * This struct contains the functions needed to realize the Queued-clients view.
258 * @see CUploadingView
260 struct CQueuedView
263 * @see CUploadingView::Initialize
265 static void Initialize( CClientListCtrl* list );
268 * @see CUploadingView::DrawCell
270 static void DrawCell( CUpDownClient* client, int column, wxDC* dc, const wxRect& rect );
273 * @see CUploadingView::SortProc
275 static int wxCALLBACK SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData);
280 * This struct contains the functions needed to realize the Clients view.
282 * @see CUploadingView
284 struct CClientsView
287 * @see CUploadingView::Initialize
289 static void Initialize( CClientListCtrl* list );
292 * @see CUploadingView::DrawCell
294 static void DrawCell( CUpDownClient* client, int column, wxDC* dc, const wxRect& rect );
297 * @see CUploadingView::SortProc
299 static int wxCALLBACK SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData);
302 #endif
303 // File_checked_for_headers