Upstream tarball 9964
[amule.git] / src / FileDetailListCtrl.cpp
blob2d26553a1b9d3936e8a1097246ff21c35abbc69e
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-2008 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 #include "muuli_wdr.h" // Needed for ID_CLOSEWNDFD
27 #include "FileDetailListCtrl.h" // Interface declarations
29 #define LVCFMT_LEFT wxLIST_FORMAT_LEFT
30 #define wxLIST_STATE_DESELECTED 0x0000
32 BEGIN_EVENT_TABLE(CFileDetailListCtrl, CMuleListCtrl)
33 EVT_LIST_ITEM_SELECTED(IDC_LISTCTRLFILENAMES, CFileDetailListCtrl::OnSelect) // Care for single selection
34 END_EVENT_TABLE()
37 CFileDetailListCtrl::CFileDetailListCtrl(wxWindow * &parent, int id, const wxPoint & pos, wxSize siz, int flags):CMuleListCtrl(parent, id, pos, siz, flags)
39 // Set sorter function
40 SetSortFunc(SortProc);
42 // Initial sorting: Sources descending
43 InsertColumn(0, _("File Name"), LVCFMT_LEFT, 370);
44 InsertColumn(1, _("Sources"), LVCFMT_LEFT, 70);
46 SetSorting(1, CMuleListCtrl::SORT_DES);
48 SortList();
51 int CFileDetailListCtrl::SortProc(wxUIntPtr param1, wxUIntPtr param2, long sortData)
53 // Comparison for different sortings
54 SourcenameItem *item1 = (SourcenameItem*)param1;
55 SourcenameItem *item2 = (SourcenameItem*)param2;
57 int mod = (sortData & CMuleListCtrl::SORT_DES) ? -1 : 1;
59 switch (sortData & CMuleListCtrl::COLUMN_MASK) {
60 case 1: return mod * (item1->count - item2->count); // Sources descending
61 case 0: return mod * item1->name.CmpNoCase(item2->name); // Name descending
62 default: return 0;
67 void CFileDetailListCtrl::OnSelect(wxListEvent& event)
69 // Damn wxLC_SINGLE_SEL does not work! So we have to care for single selection ourselfs:
70 long realpos = event.m_itemIndex;
71 long pos=-1;
72 for(;;) {
73 // Loop through all selected items
74 pos=GetNextItem(pos,wxLIST_NEXT_ALL,wxLIST_STATE_SELECTED);
75 if(pos==-1) {
76 // No more selected items left
77 break;
78 } else if (pos != realpos) {
79 // Deselect all items except the one we have just clicked
80 SetItemState(pos, wxLIST_STATE_DESELECTED, wxLIST_STATE_SELECTED);
84 event.Skip();
86 // File_checked_for_headers