Upstream tarball 9882
[amule.git] / src / ClientListCtrl.h
blobe6d653ebdf3e20ae2c1f38b8a8d052ed86729625
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
31 #include <wx/brush.h>
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 protected:
138 /// Return old column order.
139 wxString GetOldColumnOrder() const;
141 private:
143 * Custom cell-drawing function.
145 virtual void OnDrawItem(int item, wxDC* dc, const wxRect& rc, const wxRect& rectHL, bool hl);
148 * @see CMuleListCtrl::GetTTSText
150 virtual wxString GetTTSText(unsigned item) const;
154 * Event-handler for displaying a menu at right-clicks.
156 void OnRightClick( wxMouseEvent& event );
159 * Event-handler for displaying the client-details dialog upon middle-clicks.
161 void OnMiddleClick( wxListEvent& event );
164 * Event-handler for switching between the different view-types.
166 void OnChangeView( wxCommandEvent& event );
169 * Event-handler for adding a client on the list to the list of friends.
171 void OnAddFriend( wxCommandEvent& event );
174 * Event-handler for showing details about a client.
176 void OnShowDetails( wxCommandEvent& event );
179 * Event-handler for requesting the sharedfiles-list of a client.
181 void OnViewFiles( wxCommandEvent& event );
184 * Event-handler for sending a message to a specific client.
186 void OnSendMessage( wxCommandEvent& event );
189 * Event-handler for un-banning a client.
191 void OnUnbanClient( wxCommandEvent& event );
194 //! The current view-type. The default value is vtUploading.
195 ViewType m_viewType;
197 //! A pointer to the displayed menu, used to ensure that only one menu is displayed at a time.
198 wxMenu* m_menu;
200 //! One of the two most used brushes, cached for performance reasons.
201 wxBrush m_hilightBrush;
203 //! One of the two most used brushes, cached for performance reasons.
204 wxBrush m_hilightUnfocusBrush;
207 DECLARE_EVENT_TABLE()
213 * This is the default view for the list, representing a list of clients recieving files.
215 * This struct contains the functions needed to realize the uploading-view. It contains
216 * the functions used by the CClientListCtrl to prepare, sort and draw the list when the
217 * Uploading-view is enabled.
219 struct CUploadingView
222 * Initializes the view.
224 * @param list The list which wants to make use of the view.
226 * This function is called when the CClientListCtrl changes to this view-type,
227 * and it is responsible for setting the initial columns and contents. By the
228 * time this function is called, the list will already be completly empty.
230 static void Initialize( CClientListCtrl* list );
233 * Draws a specific cell.
235 * @param client The client used as a reference.
236 * @param column The column to be drawn.
237 * @param dc The device-context to draw onto.
238 * @param rect The rectangle to draw in.
240 * This function is used to draw the contents of each row, and is called for
241 * every visible column.
243 static void DrawCell( CUpDownClient* client, int column, wxDC* dc, const wxRect& rect );
246 * This is the sorter-function used by the listctrl to sort the contents.
248 * @see wxListCtrl::SortItems
250 static int wxCALLBACK SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData);
253 * Helperfunction which draws a simple bar-span over the clients requested file.
255 static void DrawStatusBar( CUpDownClient* client, wxDC* dc, const wxRect &rect );
258 * Return the old column order for this view.
260 static wxString GetOldColumnOrder();
265 * This struct contains the functions needed to realize the Queued-clients view.
267 * @see CUploadingView
269 struct CQueuedView
272 * @see CUploadingView::Initialize
274 static void Initialize( CClientListCtrl* list );
277 * @see CUploadingView::DrawCell
279 static void DrawCell( CUpDownClient* client, int column, wxDC* dc, const wxRect& rect );
282 * @see CUploadingView::SortProc
284 static int wxCALLBACK SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData);
287 * Return the old column order for this view.
289 static wxString GetOldColumnOrder();
294 * This struct contains the functions needed to realize the Clients view.
296 * @see CUploadingView
298 struct CClientsView
301 * @see CUploadingView::Initialize
303 static void Initialize( CClientListCtrl* list );
306 * @see CUploadingView::DrawCell
308 static void DrawCell( CUpDownClient* client, int column, wxDC* dc, const wxRect& rect );
311 * @see CUploadingView::SortProc
313 static int wxCALLBACK SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData);
316 * Return the old column order for this view.
318 static wxString GetOldColumnOrder();
321 #endif
322 // File_checked_for_headers