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 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 returns 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.
115 void UpdateItemColor(long index
);
118 * Updates the colors of all assosiated items, which means parents and/or siblings.
120 void UpdateAllRelativesColor(CSearchFile
*file
, long index
);
123 * Returns the current Search Id.
125 * @return The Search Id of the displayed results (set through ShowResults()).
127 wxUIntPtr
GetSearchId();
130 * Sets the filter which decides which results should be shown.
132 * @param regExp A regular expression targeting the filenames.
133 * @param invert If true, invert the results of the filter-test.
134 * @param filterKnown Should files that are queued or known be filtered out.
136 * An invalid regExp will result in all results being displayed.
138 void SetFilter(const wxString
& regExp
, bool invert
, bool filterKnown
);
141 * Toggels the use of filtering on and off.
143 void EnableFiltering(bool enabled
);
146 * Returns the number of items hidden due to filtering.
148 size_t GetHiddenItemCount() const;
151 * Attempts to download all selected items, updating color-scheme as needed.
153 * @param category The target category, or -1 to use the drop-down selection.
155 void DownloadSelected(int category
= -1);
158 typedef std::list
<CSearchFile
*> ResultList
;
160 //! List used to store results that are hidden due to matching the filter.
161 ResultList m_filteredOut
;
163 //! The current filter reg-exp.
166 //! The text from which the filter is compiled.
167 wxString m_filterText
;
169 //! Controls if shared/queued results should be shown.
172 //! Controls if the result of filter-hits should be inverted
175 //! Specifies if filtering should be used
176 bool m_filterEnabled
;
179 * Returns true if the filename is filtered.
181 bool IsFiltered(const CSearchFile
* file
);
184 * Sorter function used by wxListCtrl::SortItems function.
186 * @see CMuleListCtrl::SetSortFunc
187 * @see wxListCtrl::SortItems
189 static int wxCALLBACK
SortProc(wxUIntPtr item1
, wxUIntPtr item2
, long sortData
);
191 /** @see CMuleListCtrl::AltSortAllowed */
192 virtual bool AltSortAllowed(unsigned column
) const;
194 /** @see CMuleListCtrl::GetTTSText */
195 virtual wxString
GetTTSText(unsigned item
) const;
198 * Helper function which syncs two lists.
200 * @param src The source list.
201 * @param dst The list to be synced with the source list.
203 * This function syncronises the following settings of two lists:
208 * If either sort column or direction is changed, then the dst list will
209 * be resorted. This function is used to ensure that all results list act
210 * as one, while still allowing individual selection.
212 static void SyncLists( CSearchListCtrl
* src
, CSearchListCtrl
* dst
);
215 * Helper function which syncs all other lists against the specified one.
217 * @param src The list which all other lists should be synced against.
219 * This function just calls SyncLists() on all lists in s_lists, using
220 * the src argument as the src argument of the SyncLists function.
222 static void SyncOtherLists( CSearchListCtrl
* src
);
224 //! This list contains pointers to all current instances of CSearchListCtrl.
225 static std::list
<CSearchListCtrl
*> s_lists
;
227 //! The ID of the search-results which the list is displaying or zero if unset.
228 wxUIntPtr m_nResultsID
;
230 //! Custom drawing, needed to display children of search-results.
231 void OnDrawItem(int item
, wxDC
* dc
, const wxRect
& rect
, const wxRect
& rectHL
, bool highlighted
);
234 * Removes or adds child-entries for the given file.
236 void ShowChildren(CSearchFile
* file
, bool show
);
239 * Event handler for right mouse clicks.
241 void OnRightClick( wxListEvent
& event
);
244 * Event handler for double-clicks or enter.
246 void OnItemActivated( wxListEvent
& event
);
249 * Event handler for left-clicks on the column headers.
251 * This eventhandler takes care of sync'ing all the other lists with this one.
253 void OnColumnLClick( wxListEvent
& event
);
256 * Event handler for resizing of the columns.
258 * This eventhandler takes care of sync'ing all the other lists with this one.
260 void OnColumnResize( wxListEvent
& event
);
263 * Event handler for get-url menu items.
265 void OnPopupGetUrl( wxCommandEvent
& event
);
268 * Event handler for Razorback 2 stats menu items.
270 void OnRazorStatsCheck( wxCommandEvent
& event
);
273 * Event handler for related search.
275 void OnRelatedSearch( wxCommandEvent
& event
);
278 * Event handler for "mark as known".
280 void OnMarkAsKnown( wxCommandEvent
& event
);
283 * Event handler for download-file(s) menu item.
285 void OnPopupDownload( wxCommandEvent
& event
);
287 DECLARE_EVENT_TABLE()
290 #endif // SEARCHLISTCTRL_H
291 // File_checked_for_headers