2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2008 Merkur ( devs@emule-project.net / http://www.emule-project.net )
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
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.
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 SEARCHLISTCTRL_H
27 #define SEARCHLISTCTRL_H
30 #include "wx/colour.h" // Needed for wxColour
31 #include <wx/regex.h> // Needed for wxRegExp
33 #include "MuleListCtrl.h" // Needed for CMuleListCtrl
41 * This class is used to display search results.
43 * Results on added to the list will be colored according to
44 * the number of sources and other parameters (see UpdateColor).
46 * To display results, first use the ShowResults function, which will display
47 * all current results with the specified id and afterwards you can use the
48 * AddResult function to add new results or the UpdateResult function to update
49 * already present results. Please note that it is not possible to add results
50 * with the AddResult function before calling ShowResults.
52 class CSearchListCtrl
: public CMuleListCtrl
58 * @see CMuleListCtrl::CMuleListCtrl for documentation of parameters.
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("mulelistctrl") );
72 virtual ~CSearchListCtrl();
75 * Adds ths specified file to the list.
77 * @param The new result to be shown.
79 * Please note that no duplicates checking is done, so the pointer should
80 * point to a new file in order to avoid problems. Also note that the result
81 * will be inserted sorted according to current sort-type, so there is no
82 * need to resort the list after adding new items.
84 void AddResult(CSearchFile
* toshow
);
87 * Removes the specified file from the list.
89 void RemoveResult(CSearchFile
* toshow
);
92 * Updates the specified source.
94 * @param The search result to be updated.
96 void UpdateResult(CSearchFile
* toupdate
);
99 * Clears the list and inserts all results with the specified Id instead.
101 * @param nResult The ID of the results or Zero to simply reset the list.
103 void ShowResults( long ResultsId
);
106 * Updates the colors of item at the specified index.
108 * @param index The zero-based index of the item.
110 * This function sets the color of the item based on the following:
111 * - Downloading files are marked in red.
112 * - Known (shared/completed) files are marked in green.
113 * - New files are marked in blue depending on the number of sources.
114 * - Canceled files are marked in magenta.
116 void UpdateItemColor(long index
);
119 * Returns the current Search Id.
121 * @return The Search Id of the displayed results (set through ShowResults()).
123 wxUIntPtr
GetSearchId();
126 * Sets the filter which decides which results should be shown.
128 * @param regExp A regular expression targeting the filenames.
129 * @param invert If true, invert the results of the filter-test.
130 * @param filterKnown Should files that are queued or known be filtered out.
132 * An invalid regExp will result in all results being displayed.
134 void SetFilter(const wxString
& regExp
, bool invert
, bool filterKnown
);
137 * Toggles the use of filtering on and off.
139 void EnableFiltering(bool enabled
);
142 * Returns the number of items hidden due to filtering.
144 size_t GetHiddenItemCount() const;
147 * Attempts to download all selected items, updating color-scheme as needed.
149 * @param category The target category, or -1 to use the drop-down selection.
151 void DownloadSelected(int category
= -1);
153 static wxString
DetermineStatusPrintable(CSearchFile
*toshow
);
156 /// Return old column order.
157 wxString
GetOldColumnOrder() const;
160 typedef std::list
<CSearchFile
*> ResultList
;
162 //! List used to store results that are hidden due to matching the filter.
163 ResultList m_filteredOut
;
165 //! The current filter reg-exp.
168 //! The text from which the filter is compiled.
169 wxString m_filterText
;
171 //! Controls if shared/queued results should be shown.
174 //! Controls if the result of filter-hits should be inverted
177 //! Specifies if filtering should be used
178 bool m_filterEnabled
;
181 * Returns true if the filename is filtered.
183 bool IsFiltered(const CSearchFile
* file
);
186 * Sorter function used by wxListCtrl::SortItems function.
188 * @see CMuleListCtrl::SetSortFunc
189 * @see wxListCtrl::SortItems
191 static int wxCALLBACK
SortProc(wxUIntPtr item1
, wxUIntPtr item2
, long sortData
);
193 /** @see CMuleListCtrl::AltSortAllowed */
194 virtual bool AltSortAllowed(unsigned column
) const;
196 /** @see CMuleListCtrl::GetTTSText */
197 virtual wxString
GetTTSText(unsigned item
) const;
200 * Helper function which syncs two lists.
202 * @param src The source list.
203 * @param dst The list to be synced with the source list.
205 * This function syncronises the following settings of two lists:
210 * If either sort column or direction is changed, then the dst list will
211 * be resorted. This function is used to ensure that all results list act
212 * as one, while still allowing individual selection.
214 static void SyncLists( CSearchListCtrl
* src
, CSearchListCtrl
* dst
);
217 * Helper function which syncs all other lists against the specified one.
219 * @param src The list which all other lists should be synced against.
221 * This function just calls SyncLists() on all lists in s_lists, using
222 * the src argument as the src argument of the SyncLists function.
224 static void SyncOtherLists( CSearchListCtrl
* src
);
226 //! This list contains pointers to all current instances of CSearchListCtrl.
227 static std::list
<CSearchListCtrl
*> s_lists
;
229 //! The ID of the search-results which the list is displaying or zero if unset.
230 wxUIntPtr m_nResultsID
;
232 //! Custom drawing, needed to display children of search-results.
233 void OnDrawItem(int item
, wxDC
* dc
, const wxRect
& rect
, const wxRect
& rectHL
, bool highlighted
);
236 * Removes or adds child-entries for the given file.
238 void ShowChildren(CSearchFile
* file
, bool show
);
241 * Event handler for right mouse clicks.
243 void OnRightClick( wxListEvent
& event
);
246 * Event handler for double-clicks or enter.
248 void OnItemActivated( wxListEvent
& event
);
251 * Event handler for left-clicks on the column headers.
253 * This eventhandler takes care of sync'ing all the other lists with this one.
255 void OnColumnLClick( wxListEvent
& event
);
258 * Event handler for resizing of the columns.
260 * This eventhandler takes care of sync'ing all the other lists with this one.
262 void OnColumnResize( wxListEvent
& event
);
265 * Event handler for get-url menu items.
267 void OnPopupGetUrl( wxCommandEvent
& event
);
270 * Event handler for Razorback 2 stats menu items.
272 void OnRazorStatsCheck( wxCommandEvent
& event
);
275 * Event handler for related search.
277 void OnRelatedSearch( wxCommandEvent
& event
);
280 * Event handler for "mark as known".
282 void OnMarkAsKnown( wxCommandEvent
& event
);
285 * Event handler for download-file(s) menu item.
287 void OnPopupDownload( wxCommandEvent
& event
);
289 DECLARE_EVENT_TABLE()
292 #endif // SEARCHLISTCTRL_H
293 // File_checked_for_headers