1// 2// This file is part of the aMule Project. 3// 4// Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org ) 5// Copyright (c) 2002-2011 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. 10// 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. 15// 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 24// 25 26#include "muuli_wdr.h" // Needed for ID_CLOSEWNDFD 27#include "FileDetailListCtrl.h" // Interface declarations 28 29#define wxLIST_STATE_DESELECTED 0x0000 30 31BEGIN_EVENT_TABLE(CFileDetailListCtrl, CMuleListCtrl) 32 EVT_LIST_ITEM_SELECTED(IDC_LISTCTRLFILENAMES, CFileDetailListCtrl::OnSelect) // Care for single selection 33END_EVENT_TABLE() 34 35 36CFileDetailListCtrl::CFileDetailListCtrl(wxWindow * &parent, int id, const wxPoint & pos, wxSize siz, int flags):CMuleListCtrl(parent, id, pos, siz, flags) 37{ 38 // Set sorter function 39 SetSortFunc(SortProc); 40 41 // Initial sorting: Sources descending 42 InsertColumn(0, _("File Name"), wxLIST_FORMAT_LEFT, 370); 43 InsertColumn(1, _("Sources"), wxLIST_FORMAT_LEFT, 70); 44 45 SetSorting(1, CMuleListCtrl::SORT_DES); 46 47 SortList(); 48} 49 50int CFileDetailListCtrl::SortProc(wxUIntPtr param1, wxUIntPtr param2, long sortData) 51{ 52 // Comparison for different sortings 53 SourcenameItem *item1 = (SourcenameItem*)param1; 54 SourcenameItem *item2 = (SourcenameItem*)param2; 55 56 int mod = (sortData & CMuleListCtrl::SORT_DES) ? -1 : 1; 57 58 switch (sortData & CMuleListCtrl::COLUMN_MASK) { 59 case 1: return mod * (item1->count - item2->count); // Sources descending 60 case 0: return mod * item1->name.CmpNoCase(item2->name); // Name descending 61 default: return 0; 62 } 63} 64 65 66void CFileDetailListCtrl::OnSelect(wxListEvent& event) 67{ 68 // Damn wxLC_SINGLE_SEL does not work! So we have to care for single selection ourselfs: 69 long realpos = event.m_itemIndex; 70 long pos = -1; 71 do { 72 // Loop through all selected items 73 pos = GetNextItem(pos, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); 74 if (pos != realpos && pos != -1) { 75 // Deselect all items except the one we have just clicked 76 SetItemState(pos, wxLIST_STATE_DESELECTED, wxLIST_STATE_SELECTED); 77 } 78 } while (pos != -1); 79 80 event.Skip(); 81} 82// File_checked_for_headers 83