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 #include "SearchListCtrl.h" // Interface declarations
28 #include <common/MenuIDs.h>
30 #include "amule.h" // Needed for theApp
31 #include "KnownFileList.h" // Needed for CKnownFileList
32 #include "SearchList.h" // Needed for CSearchFile
33 #include "SearchDlg.h" // Needed for CSearchDlg
34 #include "amuleDlg.h" // Needed for CamuleDlg
35 #include "muuli_wdr.h" // Needed for clientImages
36 #include "Preferences.h" // Needed for thePrefs
37 #include "GuiEvents.h" // Needed for CoreNotify_Search_Add_Download
38 #include "MuleColour.h"
40 BEGIN_EVENT_TABLE(CSearchListCtrl
, CMuleListCtrl
)
41 EVT_LIST_ITEM_RIGHT_CLICK(-1, CSearchListCtrl::OnRightClick
)
42 EVT_LIST_COL_CLICK( -1, CSearchListCtrl::OnColumnLClick
)
43 EVT_LIST_COL_END_DRAG( -1, CSearchListCtrl::OnColumnResize
)
45 EVT_MENU( MP_GETED2KLINK
, CSearchListCtrl::OnPopupGetUrl
)
46 EVT_MENU( MP_RAZORSTATS
, CSearchListCtrl::OnRazorStatsCheck
)
47 EVT_MENU( MP_SEARCHRELATED
, CSearchListCtrl::OnRelatedSearch
)
48 EVT_MENU( MP_MARK_AS_KNOWN
, CSearchListCtrl::OnMarkAsKnown
)
49 EVT_MENU( MP_RESUME
, CSearchListCtrl::OnPopupDownload
)
50 EVT_MENU_RANGE( MP_ASSIGNCAT
, MP_ASSIGNCAT
+ 99, CSearchListCtrl::OnPopupDownload
)
52 EVT_LIST_ITEM_ACTIVATED( -1, CSearchListCtrl::OnItemActivated
)
56 std::list
<CSearchListCtrl
*> CSearchListCtrl::s_lists
;
59 enum SearchListColumns
{
60 ID_SEARCH_COL_NAME
= 0,
62 ID_SEARCH_COL_SOURCES
,
69 CSearchListCtrl::CSearchListCtrl(
75 const wxValidator
&validator
,
78 CMuleListCtrl(parent
, winid
, pos
, size
, style
| wxLC_OWNERDRAW
, validator
, name
),
81 m_filterEnabled(false)
83 // Setting the sorter function.
84 SetSortFunc( SortProc
);
86 InsertColumn( ID_SEARCH_COL_NAME
, _("File Name"), wxLIST_FORMAT_LEFT
, 500, wxT("N") );
87 InsertColumn( ID_SEARCH_COL_SIZE
, _("Size"), wxLIST_FORMAT_LEFT
, 100, wxT("Z") );
88 InsertColumn( ID_SEARCH_COL_SOURCES
, _("Sources"), wxLIST_FORMAT_LEFT
, 50, wxT("u") );
89 InsertColumn( ID_SEARCH_COL_TYPE
, _("Type"), wxLIST_FORMAT_LEFT
, 65, wxT("Y") );
90 InsertColumn( ID_SEARCH_COL_FILEID
, _("FileID"), wxLIST_FORMAT_LEFT
, 280, wxT("I") );
91 InsertColumn( ID_SEARCH_COL_STATUS
, _("Status"), wxLIST_FORMAT_LEFT
, 100, wxT("S") );
95 // Only load settings for first list, otherwise sync with current lists
96 if ( s_lists
.empty() ) {
97 // Set the name to enable loading of settings
98 SetTableName( wxT("Search") );
102 // Unset the name to avoid the settings getting saved every time a list is closed
103 SetTableName( wxEmptyString
);
105 // Sync this list with one of the others
106 SyncLists( s_lists
.front(), this );
109 // Add the list so that it will be synced with the other lists
110 s_lists
.push_back( this );
114 wxString
CSearchListCtrl::GetOldColumnOrder() const
116 return wxT("N,Z,u,Y,I,S");
120 CSearchListCtrl::~CSearchListCtrl()
122 std::list
<CSearchListCtrl
*>::iterator it
= std::find( s_lists
.begin(), s_lists
.end(), this );
124 if ( it
!= s_lists
.end() )
127 // We only save the settings if the last list was closed
128 if ( s_lists
.empty() ) {
129 // In order to get the settings saved, we need to set the name
130 SetTableName( wxT("Search") );
135 void CSearchListCtrl::AddResult(CSearchFile
* toshow
)
137 wxCHECK_RET(toshow
->GetSearchID() == m_nResultsID
, wxT("Wrong search-id for result-list"));
139 const wxUIntPtr toshowdata
= reinterpret_cast<wxUIntPtr
>(toshow
);
141 // Check if the result should be shown
142 if (FindItem(-1, toshowdata
) != -1) {
144 } else if (toshow
->GetParent() && !toshow
->GetParent()->ShowChildren()) {
146 } else if (!IsFiltered(toshow
)) {
147 if (toshow
->HasChildren() && toshow
->ShowChildren()) {
148 // Only filter the parent if none of the children are shown.
149 bool foundChild
= false;
150 const CSearchResultList
& children
= toshow
->GetChildren();
151 for (size_t i
= 0; i
< children
.size(); ++i
) {
152 if (IsFiltered(children
.at(i
))) {
159 // No children left, and the parent is filtered.
160 m_filteredOut
.push_back(toshow
);
164 m_filteredOut
.push_back(toshow
);
169 // Insert the item before the item found by the search
170 uint32 newid
= InsertItem(GetInsertPos(toshowdata
), toshow
->GetFileName().GetPrintable());
172 // Sanity checks to ensure that results/children are properly positioned.
175 CSearchFile
* parent
= toshow
->GetParent();
178 CSearchFile
* before
= (CSearchFile
*)GetItemData(newid
- 1);
181 wxASSERT((before
->GetParent() == parent
) || (before
== parent
));
183 wxASSERT(before
->GetParent() != toshow
);
187 if ((int)newid
< GetItemCount() - 1) {
188 CSearchFile
* after
= (CSearchFile
*)GetItemData(newid
+ 1);
191 wxASSERT((after
->GetParent() == parent
) || (!after
->GetParent()));
193 wxASSERT((after
->GetParent() == toshow
) || (!after
->GetParent()));
199 SetItemPtrData(newid
, toshowdata
);
202 SetItem(newid
, ID_SEARCH_COL_SIZE
, CastItoXBytes( toshow
->GetFileSize() ) );
205 wxString temp
= CFormat(wxT("%d")) % toshow
->GetSourceCount();
206 if (toshow
->GetCompleteSourceCount()) {
207 temp
+= CFormat(wxT(" (%d)")) % toshow
->GetCompleteSourceCount();
209 if (toshow
->GetClientsCount()) {
210 temp
+= CFormat(wxT(" [%d]")) % toshow
->GetClientsCount();
212 #if defined(__DEBUG__) && !defined(CLIENT_GUI)
213 if (toshow
->GetKadPublishInfo() == 0) {
216 temp
+= CFormat(wxT(" | N:%u, P:%u, T:%0.2f"))
217 % ((toshow
->GetKadPublishInfo() & 0xFF000000) >> 24)
218 % ((toshow
->GetKadPublishInfo() & 0x00FF0000) >> 16)
219 % ((toshow
->GetKadPublishInfo() & 0x0000FFFF) / 100.0);
222 SetItem( newid
, ID_SEARCH_COL_SOURCES
, temp
);
225 SetItem( newid
, ID_SEARCH_COL_TYPE
, GetFiletypeByName( toshow
->GetFileName() ) );
228 SetItem(newid
, ID_SEARCH_COL_FILEID
, toshow
->GetFileHash().Encode() );
231 SetItem(newid
, ID_SEARCH_COL_STATUS
, DetermineStatusPrintable(toshow
));
233 // Set the color of the item
234 UpdateItemColor( newid
);
238 void CSearchListCtrl::RemoveResult(CSearchFile
* toremove
)
240 ShowChildren(toremove
, false);
242 long index
= FindItem(-1, reinterpret_cast<wxUIntPtr
>(toremove
));
246 ResultList::iterator it
= std::find(m_filteredOut
.begin(), m_filteredOut
.end(), toremove
);
247 if ( it
!= m_filteredOut
.end()) {
248 m_filteredOut
.erase(it
);
254 void CSearchListCtrl::UpdateResult(CSearchFile
* toupdate
)
256 long index
= FindItem(-1, reinterpret_cast<wxUIntPtr
>(toupdate
));
258 // Update the filename, which may be changed in case of multiple variants.
259 SetItem(index
, ID_SEARCH_COL_NAME
, toupdate
->GetFileName().GetPrintable());
261 wxString temp
= CFormat(wxT("%d")) % toupdate
->GetSourceCount();
262 if (toupdate
->GetCompleteSourceCount()) {
263 temp
+= CFormat(wxT(" (%d)")) % toupdate
->GetCompleteSourceCount();
265 if (toupdate
->GetClientsCount()) {
266 temp
+= CFormat(wxT(" [%d]")) % toupdate
->GetClientsCount();
268 #if defined(__DEBUG__) && !defined(CLIENT_GUI)
269 if (toupdate
->GetKadPublishInfo() == 0) {
272 temp
+= CFormat(wxT(" | N:%u, P:%u, T:%0.2f"))
273 % ((toupdate
->GetKadPublishInfo() & 0xFF000000) >> 24)
274 % ((toupdate
->GetKadPublishInfo() & 0x00FF0000) >> 16)
275 % ((toupdate
->GetKadPublishInfo() & 0x0000FFFF) / 100.0);
278 SetItem(index
, ID_SEARCH_COL_SOURCES
, temp
);
280 SetItem(index
, ID_SEARCH_COL_STATUS
, DetermineStatusPrintable(toupdate
));
282 UpdateItemColor(index
);
284 // Deletions of items causes rather large amount of flicker, so to
285 // avoid this, we resort the list to ensure correct ordering.
286 if (!IsItemSorted(index
)) {
293 void CSearchListCtrl::UpdateItemColor(long index
)
297 item
.SetColumn( ID_SEARCH_COL_SIZE
);
307 CMuleColour
newcol(wxSYS_COLOUR_WINDOWTEXT
);
309 CSearchFile
* file
= (CSearchFile
*)GetItemData(index
);
311 int red
= newcol
.Red();
312 int green
= newcol
.Green();
313 int blue
= newcol
.Blue();
315 switch (file
->GetDownloadStatus()) {
316 case CSearchFile::DOWNLOADED
:
317 // File has already been downloaded. Mark as green.
320 case CSearchFile::QUEUED
:
321 // File is downloading.
322 case CSearchFile::QUEUEDCANCELED
:
323 // File is downloading and has been canceled before.
327 case CSearchFile::CANCELED
:
328 // File has been canceled. Mark as magenta.
333 // File is new, colour after number of files
334 blue
+= file
->GetSourceCount() * 5;
340 // don't forget to set the item data back...
342 newitem
.SetId( index
);
343 newitem
.SetTextColour( wxColour( red
, green
, blue
) );
349 void CSearchListCtrl::ShowResults( long ResultsID
)
352 m_nResultsID
= ResultsID
;
354 const CSearchResultList
& list
= theApp
->searchlist
->GetSearchResults(ResultsID
);
355 for (unsigned int i
= 0; i
< list
.size(); ++i
) {
356 AddResult( list
[i
] );
362 wxUIntPtr
CSearchListCtrl::GetSearchId()
368 void CSearchListCtrl::SetFilter(const wxString
& regExp
, bool invert
, bool filterKnown
)
370 if (regExp
.IsEmpty()) {
372 m_filterText
= wxT(".*");
374 m_filterText
= regExp
;
377 m_filter
.Compile(m_filterText
, wxRE_DEFAULT
| wxRE_ICASE
);
378 m_filterKnown
= filterKnown
;
381 if (m_filterEnabled
) {
382 // Swap the list of filtered results so we can freely add new items to the list
383 ResultList curFiltered
;
384 std::swap(curFiltered
, m_filteredOut
);
386 // Filter items already on the list
387 for (int i
= 0; i
< GetItemCount();) {
388 CSearchFile
* file
= (CSearchFile
*)GetItemData(i
);
390 if (IsFiltered(file
)) {
393 m_filteredOut
.push_back(file
);
398 // Check the previously filtered items.
399 ResultList::iterator it
= curFiltered
.begin();
400 for (; it
!= curFiltered
.end(); ++it
) {
401 if (IsFiltered(*it
)) {
404 m_filteredOut
.push_back(*it
);
411 void CSearchListCtrl::EnableFiltering(bool enabled
)
413 if (enabled
!= m_filterEnabled
) {
414 m_filterEnabled
= enabled
;
417 SetFilter(m_filterText
, m_invert
, m_filterKnown
);
419 ResultList::iterator it
= m_filteredOut
.begin();
420 for (; it
!= m_filteredOut
.end(); ++it
) {
424 m_filteredOut
.clear();
430 size_t CSearchListCtrl::GetHiddenItemCount() const
432 return m_filteredOut
.size();
436 bool CSearchListCtrl::IsFiltered(const CSearchFile
* file
)
438 // By default, everything is displayed
441 if (m_filterEnabled
&& m_filter
.IsValid()) {
442 result
= m_filter
.Matches(file
->GetFileName().GetPrintable());
443 result
= ((result
&& !m_invert
) || (!result
&& m_invert
));
444 if (result
&& m_filterKnown
) {
445 result
= file
->GetDownloadStatus() == CSearchFile::NEW
;
453 int CSearchListCtrl::SortProc(wxUIntPtr item1
, wxUIntPtr item2
, long sortData
)
455 CSearchFile
* file1
= (CSearchFile
*)item1
;
456 CSearchFile
* file2
= (CSearchFile
*)item2
;
458 // Modifies the result, 1 for ascending, -1 for decending
459 int modifier
= (sortData
& CMuleListCtrl::SORT_DES
) ? -1 : 1;
460 bool alternate
= (sortData
& CMuleListCtrl::SORT_ALT
) != 0;
462 // Decide if which should files we should sort by.
463 wxUIntPtr parent1
= reinterpret_cast<wxUIntPtr
>(file1
->GetParent());
464 wxUIntPtr parent2
= reinterpret_cast<wxUIntPtr
>(file2
->GetParent());
465 wxUIntPtr filePtr1
= reinterpret_cast<wxUIntPtr
>(file1
);
466 wxUIntPtr filePtr2
= reinterpret_cast<wxUIntPtr
>(file2
);
467 if (parent1
&& parent2
) {
468 if (parent1
!= parent2
) {
469 return SortProc(parent1
, parent2
, sortData
);
471 } else if (parent1
) {
472 if (parent1
== filePtr2
) {
475 return SortProc(parent1
, filePtr2
, sortData
);
477 } else if (parent2
) {
478 if (parent2
== filePtr1
) {
481 return SortProc(filePtr1
, parent2
, sortData
);
486 switch (sortData
& CMuleListCtrl::COLUMN_MASK
) {
488 case ID_SEARCH_COL_NAME
:
489 result
= CmpAny(file1
->GetFileName(), file2
->GetFileName());
493 case ID_SEARCH_COL_SIZE
:
494 result
= CmpAny( file1
->GetFileSize(), file2
->GetFileSize() );
498 case ID_SEARCH_COL_SOURCES
: {
499 int cmp
= CmpAny( file1
->GetSourceCount(), file2
->GetSourceCount() );
500 int cmp2
= CmpAny( file1
->GetCompleteSourceCount(), file2
->GetCompleteSourceCount() );
517 // Sort by file-types
518 case ID_SEARCH_COL_TYPE
: {
519 result
= GetFiletypeByName(file1
->GetFileName()).Cmp(GetFiletypeByName(file2
->GetFileName()));
521 // Same file-type, sort by extension
522 result
= CmpAny(file1
->GetFileName().GetExt(), file2
->GetFileName().GetExt());
529 case ID_SEARCH_COL_FILEID
:
530 result
= CmpAny(file2
->GetFileHash(), file1
->GetFileHash());
533 // Sort by file status
534 case ID_SEARCH_COL_STATUS
:
535 result
= CmpAny(DetermineStatusPrintable(file2
), DetermineStatusPrintable(file1
));
539 return modifier
* result
;
543 void CSearchListCtrl::SyncLists( CSearchListCtrl
* src
, CSearchListCtrl
* dst
)
545 wxCHECK_RET(src
&& dst
, wxT("NULL argument in SyncLists"));
548 for ( int i
= 0; i
< src
->GetColumnCount(); i
++ ) {
549 // We do this check since just setting the width causes a redraw
550 if ( dst
->GetColumnWidth( i
) != src
->GetColumnWidth( i
) ) {
551 dst
->SetColumnWidth( i
, src
->GetColumnWidth( i
) );
556 unsigned column
= src
->GetSortColumn();
557 unsigned order
= src
->GetSortOrder();
558 if (column
!= dst
->GetSortColumn() || order
!= dst
->GetSortOrder()) {
559 dst
->SetSorting(column
, order
);
564 void CSearchListCtrl::SyncOtherLists(CSearchListCtrl
*src
)
566 std::list
<CSearchListCtrl
*>::iterator it
;
568 for (it
= s_lists
.begin(); it
!= s_lists
.end(); ++it
) {
570 SyncLists( src
, *it
);
576 void CSearchListCtrl::OnRightClick(wxListEvent
& event
)
578 CheckSelection(event
);
580 if (GetSelectedItemCount()) {
581 // Create the popup-menu
582 wxMenu
menu(_("File"));
583 menu
.Append(MP_RESUME
, _("Download"));
585 wxMenu
* cats
= new wxMenu(_("Category"));
586 cats
->Append(MP_ASSIGNCAT
, _("Main"));
587 for (unsigned i
= 1; i
< theApp
->glob_prefs
->GetCatCount(); i
++) {
588 cats
->Append(MP_ASSIGNCAT
+ i
,
589 theApp
->glob_prefs
->GetCategory(i
)->title
);
592 menu
.Append(MP_MENU_CATS
, _("Download in category"), cats
);
593 menu
.AppendSeparator();
594 /* Commented out while it's gone
595 menu.Append(MP_RAZORSTATS, _("Get Razorback 2's stats for this file"));
596 menu.AppendSeparator();
598 menu
.Append(MP_SEARCHRELATED
, _("Search related files (eD2k, local server)"));
599 menu
.AppendSeparator();
601 //#warning Uncomment this here to test the MP_MARK_AS_KNOWN feature. Beware! You are on your own here, this might break "known.met"
603 menu
.Append(MP_MARK_AS_KNOWN
, _("Mark as known file"));
604 menu
.AppendSeparator();
607 menu
.Append(MP_GETED2KLINK
, _("Copy eD2k link to clipboard"));
609 // These should only be enabled for single-selections
610 bool enable
= (GetSelectedItemCount() == 1);
611 menu
.Enable(MP_GETED2KLINK
, enable
);
612 menu
.Enable(MP_MENU_CATS
, (theApp
->glob_prefs
->GetCatCount() > 1));
614 PopupMenu(&menu
, event
.GetPoint());
621 void CSearchListCtrl::OnColumnLClick( wxListEvent
& event
)
623 // Let the real event handler do its work first
624 CMuleListCtrl::OnColumnLClick( event
);
626 SyncOtherLists( this );
630 void CSearchListCtrl::OnColumnResize( wxListEvent
& WXUNUSED(event
) )
632 SyncOtherLists( this );
636 void CSearchListCtrl::OnPopupGetUrl( wxCommandEvent
& WXUNUSED(event
) )
640 long index
= GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
642 while (index
!= -1) {
643 CSearchFile
* file
= (CSearchFile
*)GetItemData( index
);
645 URIs
+= theApp
->CreateED2kLink( file
) + wxT("\n");
647 index
= GetNextItem( index
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
650 if (!URIs
.IsEmpty()) {
651 theApp
->CopyTextToClipboard( URIs
.RemoveLast() );
656 void CSearchListCtrl::OnRazorStatsCheck( wxCommandEvent
& WXUNUSED(event
) )
658 int item
= GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
663 CSearchFile
* file
= (CSearchFile
*)GetItemData( item
);
664 theApp
->amuledlg
->LaunchUrl(wxT("http://stats.razorback2.com/ed2khistory?ed2k=") + file
->GetFileHash().Encode());
668 void CSearchListCtrl::OnRelatedSearch( wxCommandEvent
& WXUNUSED(event
) )
670 int item
= GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
675 CSearchFile
* file
= (CSearchFile
*)GetItemData( item
);
676 theApp
->searchlist
->StopSearch(true);
677 theApp
->amuledlg
->m_searchwnd
->ResetControls();
678 CastByID( IDC_SEARCHNAME
, theApp
->amuledlg
->m_searchwnd
, wxTextCtrl
)->
679 SetValue(wxT("related::") + file
->GetFileHash().Encode());
680 theApp
->amuledlg
->m_searchwnd
->StartNewSearch();
684 void CSearchListCtrl::OnMarkAsKnown( wxCommandEvent
& WXUNUSED(event
) )
687 long index
= GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
689 CSearchFile
*searchFile
= (CSearchFile
*)GetItemData(index
);
690 CKnownFile
*knownFile(new CKnownFile(*searchFile
));
691 theApp
->knownfiles
->SafeAddKFile(knownFile
);
692 index
= GetNextItem(index
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
698 void CSearchListCtrl::OnPopupDownload(wxCommandEvent
& event
)
700 if (event
.GetId() == MP_RESUME
) {
701 // Via the "Download" menu-item, use category specified in drop-down menu
704 // Via an "Download in category" item
705 DownloadSelected(event
.GetId() - MP_ASSIGNCAT
);
710 void CSearchListCtrl::OnItemActivated(wxListEvent
& event
)
712 CSearchFile
* file
= ((CSearchFile
*)GetItemData(event
.GetIndex()));
713 if (file
->HasChildren()) {
714 ShowChildren(file
, !file
->ShowChildren());
721 bool CSearchListCtrl::AltSortAllowed(unsigned column
) const
724 case ID_SEARCH_COL_SOURCES
:
732 void CSearchListCtrl::DownloadSelected(int category
)
734 FindWindowById(IDC_SDOWNLOAD
)->Enable(FALSE
);
736 // Either the "Download" menu-item, the download-button, double-click or enter
737 if (category
== -1) {
738 // Defaults to main category
741 if (CastByID(IDC_EXTENDEDSEARCHCHECK
, NULL
, wxCheckBox
)->GetValue()) {
742 category
= CastByID(ID_AUTOCATASSIGN
, NULL
, wxChoice
)->GetSelection();
746 // Process all selections
747 long index
= GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
749 CSearchFile
* file
= (CSearchFile
*)GetItemData(index
);
750 CoreNotify_Search_Add_Download(file
, category
);
751 index
= GetNextItem(index
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
753 // Listcontrol gets updated by notification when download is started
757 const wxBrush
& GetBrush(wxSystemColour index
)
759 return CMuleColour(index
).GetBrush();
763 void CSearchListCtrl::OnDrawItem(
764 int item
, wxDC
* dc
, const wxRect
& rect
, const wxRect
& rectHL
, bool highlighted
)
766 CSearchFile
* file
= (CSearchFile
*)GetItemData(item
);
768 // Define text-color and background
771 dc
->SetBackground(GetBrush(wxSYS_COLOUR_HIGHLIGHT
));
772 dc
->SetTextForeground(CMuleColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
774 dc
->SetBackground(GetBrush(wxSYS_COLOUR_BTNSHADOW
));
775 dc
->SetTextForeground(CMuleColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
778 dc
->SetBackground(GetBrush(wxSYS_COLOUR_LISTBOX
));
779 dc
->SetTextForeground(CMuleColour(wxSYS_COLOUR_WINDOWTEXT
));
782 // Define the border of the drawn area
784 dc
->SetPen(*(wxThePenList
->FindOrCreatePen(CMuleColour(dc
->GetBackground().GetColour()).Blend(65), 1, wxSOLID
)));
786 dc
->SetPen(*wxTRANSPARENT_PEN
);
787 dc
->SetTextForeground(GetItemTextColour(item
));
790 // Clear the background, not done automatically since the drawing is buffered.
791 dc
->SetBrush( dc
->GetBackground() );
792 dc
->DrawRectangle( rectHL
.x
, rectHL
.y
, rectHL
.width
, rectHL
.height
);
794 // Various constant values we use
795 const int iTextOffset
= ( rect
.GetHeight() - dc
->GetCharHeight() ) / 2;
796 const int iOffset
= 4;
797 const int treeOffset
= 11;
798 const int treeCenter
= 6;
799 bool tree_show
= false;
801 wxRect
cur_rec(iOffset
, rect
.y
, 0, rect
.height
);
802 for (int i
= 0; i
< GetColumnCount(); i
++) {
804 GetColumn(i
, listitem
);
806 if ( listitem
.GetWidth() > 0 ) {
807 cur_rec
.width
= listitem
.GetWidth() - 2*iOffset
;
809 // Make a copy of the current rectangle so we can apply specific tweaks
810 wxRect target_rec
= cur_rec
;
812 // will ensure that text is about in the middle ;)
813 target_rec
.y
+= iTextOffset
;
816 if (file
->HasChildren() || file
->GetParent()) {
817 tree_show
= (listitem
.GetWidth() > 0);
818 target_rec
.x
+= treeOffset
;
819 target_rec
.width
-= treeOffset
;
821 // Children are indented a bit
822 if (file
->GetParent()) {
824 target_rec
.width
-= 4;
828 // Check if the rating icon should be drawn
829 if (file
->HasRating()) {
830 int image
= Client_InvalidRating_Smiley
+ file
->UserRating() - 1;
834 theApp
->amuledlg
->m_imagelist
.Draw(image
, *dc
, target_rec
.GetX(),
835 target_rec
.GetY() - 1, wxIMAGELIST_DRAW_TRANSPARENT
);
837 // Move the text past the icon.
838 target_rec
.x
+= imgWidth
+ 4;
839 target_rec
.width
-= imgWidth
+ 4;
844 cellitem
.SetColumn(i
);
845 cellitem
.SetId(item
);
847 // Force clipper (clip 2 px more than the rectangle from the right side)
848 wxDCClipper
clipper(*dc
, target_rec
.x
, target_rec
.y
, target_rec
.width
- 2, target_rec
.height
);
850 if (GetItem(cellitem
)) {
851 dc
->DrawText(cellitem
.GetText(), target_rec
.GetX(), target_rec
.GetY());
853 dc
->DrawText(wxT("GetItem failed!"), target_rec
.GetX(), target_rec
.GetY());
856 // Increment to the next column
857 cur_rec
.x
+= listitem
.GetWidth();
861 // Draw tree last so it draws over selected and focus (looks better)
863 // Gather some information
864 const bool notLast
= (item
+ 1 < GetItemCount());
865 const bool notFirst
= (item
!= 0);
866 const bool hasNext
= notLast
&& ((CSearchFile
*)GetItemData(item
+ 1))->GetParent();
867 const int middle
= cur_rec
.y
+ ( cur_rec
.height
+ 1 ) / 2;
869 // Set up a new pen for drawing the tree
870 dc
->SetPen( *(wxThePenList
->FindOrCreatePen(dc
->GetTextForeground(), 1, wxSOLID
)) );
872 if (file
->GetParent()) {
873 // Draw the line to the filename
874 dc
->DrawLine(treeCenter
, middle
, treeOffset
+ 4, middle
);
876 // Draw the line to the child node
878 dc
->DrawLine(treeCenter
, middle
, treeCenter
, cur_rec
.y
+ cur_rec
.height
+ 1);
881 // Draw the line back up to parent node
883 dc
->DrawLine(treeCenter
, middle
, treeCenter
, cur_rec
.y
- 1);
885 } else if (file
->HasChildren()) {
886 if (file
->ShowChildren()) {
888 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
890 dc
->SetBrush(*(wxTheBrushList
->FindOrCreateBrush(GetItemTextColour(item
))));
893 dc
->DrawCircle( treeCenter
, middle
, 3 );
895 // Draw the line to the child node if there are any children
896 if (hasNext
&& file
->ShowChildren()) {
897 dc
->DrawLine(treeCenter
, middle
+ 3, treeCenter
, cur_rec
.y
+ cur_rec
.height
+ 1);
902 // Sanity checks to ensure that results/children are properly positioned.
905 CSearchFile
* parent
= file
->GetParent();
908 CSearchFile
* before
= (CSearchFile
*)GetItemData(item
- 1);
911 wxASSERT((before
->GetParent() == parent
) || (before
== parent
));
913 wxASSERT(before
->GetParent() != file
);
917 if (item
< GetItemCount() - 1) {
918 CSearchFile
* after
= (CSearchFile
*)GetItemData(item
+ 1);
921 wxASSERT((after
->GetParent() == parent
) || (!after
->GetParent()));
923 wxASSERT((after
->GetParent() == file
) || (!after
->GetParent()));
931 void CSearchListCtrl::ShowChildren(CSearchFile
* file
, bool show
)
935 file
->SetShowChildren(show
);
937 const CSearchResultList
& results
= file
->GetChildren();
938 for (size_t i
= 0; i
< results
.size(); ++i
) {
940 AddResult(results
[i
]);
942 RemoveResult(results
[i
]);
950 wxString
CSearchListCtrl::GetTTSText(unsigned item
) const
952 return GetItemText(item
);
956 wxString
CSearchListCtrl::DetermineStatusPrintable(CSearchFile
*toshow
)
958 switch (toshow
->GetDownloadStatus()) {
959 case CSearchFile::DOWNLOADED
:
960 // File has already been downloaded.
961 return _("Downloaded");
962 case CSearchFile::QUEUED
:
963 // File is downloading.
964 case CSearchFile::QUEUEDCANCELED
:
965 // File is downloading and has been canceled before.
967 case CSearchFile::CANCELED
:
968 // File has been canceled.
969 return _("Canceled");
975 // File_checked_for_headers