📄 downloadlistctrl.cpp
字号:
//gather some information
BOOL hasNext = notLast &&
((CtrlItem_Struct*)this->GetItemData(lpDrawItemStruct->itemID + 1))->type != FILE_TYPE;
BOOL isOpenRoot = hasNext && content->type == FILE_TYPE;
BOOL isChild = content->type != FILE_TYPE;
BOOL isExpandable = !isChild && ((CPartFile*)content->value)->GetSourceCount() > 0;
//might as well calculate these now
int treeCenter = tree_start + 3;
int middle = (cur_rec.top + cur_rec.bottom + 1) / 2;
//set up a new pen for drawing the tree
CPen pn, *oldpn;
pn.CreatePen(PS_SOLID, 1, dc->GetTextColor());
oldpn = dc->SelectObject(&pn);
if(isChild) {
//draw the line to the status bar
dc->MoveTo(tree_end, middle);
dc->LineTo(tree_start + 3, middle);
//draw the line to the child node
if(hasNext) {
dc->MoveTo(treeCenter, middle);
dc->LineTo(treeCenter, cur_rec.bottom + 1);
}
} else if(isOpenRoot) {
//draw circle
RECT circle_rec;
COLORREF crBk = dc->GetBkColor();
circle_rec.top = middle - 2;
circle_rec.bottom = middle + 3;
circle_rec.left = treeCenter - 2;
circle_rec.right = treeCenter + 3;
dc->FrameRect(&circle_rec, &CBrush(dc->GetTextColor()));
dc->SetPixelV(circle_rec.left, circle_rec.top, crBk);
dc->SetPixelV(circle_rec.right - 1, circle_rec.top, crBk);
dc->SetPixelV(circle_rec.left, circle_rec.bottom - 1, crBk);
dc->SetPixelV(circle_rec.right - 1, circle_rec.bottom - 1, crBk);
//draw the line to the child node
if(hasNext) {
dc->MoveTo(treeCenter, middle + 3);
dc->LineTo(treeCenter, cur_rec.bottom + 1);
}
} /*else if(isExpandable) {
//draw a + sign
dc->MoveTo(treeCenter, middle - 2);
dc->LineTo(treeCenter, middle + 3);
dc->MoveTo(treeCenter - 2, middle);
dc->LineTo(treeCenter + 3, middle);
}*/
//draw the line back up to parent node
if(notFirst && isChild) {
dc->MoveTo(treeCenter, middle);
dc->LineTo(treeCenter, cur_rec.top - 1);
}
//put the old pen back
dc->SelectObject(oldpn);
pn.DeleteObject();
}
//put the original objects back
dc->SelectObject(pOldFont);
dc->SetTextColor(crOldTextColor);
}
// modifier-keys -view filtering [Ese Juani+xrmb]
void CDownloadListCtrl::HideSources(CPartFile* toCollapse,bool isShift,bool isCtrl,bool isAlt) {
SetRedraw(false);
int pre,post;
pre = post = 0;
for(int i = 0; i < GetItemCount(); i++) {
CtrlItem_Struct* item = (CtrlItem_Struct*)this->GetItemData(i);
if(item->owner == toCollapse) {
pre++;
if(isShift || isCtrl || isAlt){
uint8 ds=((CUpDownClient*)item->value)->GetDownloadState();
if((isShift && ds==DS_DOWNLOADING) ||
(isCtrl && ((CUpDownClient*)item->value)->GetRemoteQueueRank()> 0) ||
(isAlt && ds!=DS_NONEEDEDPARTS)) continue;
}
item->dwUpdated = 0;
item->status.DeleteObject();
DeleteItem(i--);
post++;
}
}
if (pre-post==0) toCollapse->srcarevisible = false;
SetRedraw(true);
}
BEGIN_MESSAGE_MAP(CDownloadListCtrl, CMuleListCtrl)
ON_NOTIFY_REFLECT(LVN_ITEMACTIVATE, OnItemActivate)
ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnListModified)
ON_NOTIFY_REFLECT(LVN_INSERTITEM, OnListModified)
ON_NOTIFY_REFLECT(LVN_DELETEITEM, OnListModified)
ON_WM_CONTEXTMENU()
ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnClick)
END_MESSAGE_MAP()
// CDownloadListCtrl message handlers
void CDownloadListCtrl::OnItemActivate(NMHDR *pNMHDR, LRESULT *pResult){
LPNMITEMACTIVATE pNMIA = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
CtrlItem_Struct* content = (CtrlItem_Struct*)this->GetItemData(pNMIA->iItem);
// modifier-keys -view filtering [Ese Juani+xrmb]
bool isShift=GetAsyncKeyState(VK_SHIFT) < 0;
bool isCtrl=GetAsyncKeyState(VK_CONTROL) < 0;
bool isAlt=GetAsyncKeyState(VK_MENU) < 0;
if (content->type == FILE_TYPE){
CPartFile* partfile = reinterpret_cast<CPartFile*>(content->value);
if (partfile->GetStatus()==PS_COMPLETE) {
char* buffer = new char[MAX_PATH];
sprintf(buffer,"%s",partfile->GetFullName());
ShellOpenFile(buffer);
delete buffer;
*pResult = 0;
return;
}
// Check if the source branch is disable
if(partfile->srcarevisible == false) {
SetRedraw(false);
// Go throught the whole list to finf out the sources for this file
// Remark: don't use GetSourceCount() => UNAVAILABLE_SOURCE
for(ListItems::const_iterator it = m_ListItems.begin(); it != m_ListItems.end(); it++){
const CtrlItem_Struct* cur_item = it->second;
if(cur_item->owner == partfile){
if(isShift || isCtrl || isAlt) {
ASSERT(cur_item->type != FILE_TYPE);
uint8 ds=((CUpDownClient*)cur_item->value)->GetDownloadState();
if(!(isShift && ds==DS_DOWNLOADING ||
isCtrl && ((CUpDownClient*)cur_item->value)->GetRemoteQueueRank()>0 ||
isAlt && ds!=DS_NONEEDEDPARTS))
continue; // skip this source
}
partfile->srcarevisible = true;
InsertItem(LVIF_PARAM,pNMIA->iItem+1,0,0,0,0,(LPARAM)cur_item);
}
}
SetRedraw(true);
}
else {
HideSources(partfile,isShift,isCtrl,isAlt);
}
}
*pResult = 0;
}
void CDownloadListCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
{
if (GetSelectionMark() != (-1)){
CtrlItem_Struct* content = (CtrlItem_Struct*)this->GetItemData(GetSelectionMark());
if (content->type == FILE_TYPE){
CPartFile* file = (CPartFile*)content->value;
bool filedone=(file->GetStatus()==PS_COMPLETE || file->GetStatus()==PS_COMPLETING);
m_FileMenu.EnableMenuItem(MP_PAUSE,((file->GetStatus() != PS_PAUSED && file->GetStatus() != PS_ERROR && !filedone) ? MF_ENABLED:MF_GRAYED));
m_FileMenu.EnableMenuItem(MP_STOP,((!file->IsStopped() && file->GetStatus() != PS_ERROR && !filedone ) ? MF_ENABLED:MF_GRAYED));
m_FileMenu.EnableMenuItem(MP_RESUME,((file->GetStatus() == PS_PAUSED) ? MF_ENABLED:MF_GRAYED));
m_FileMenu.EnableMenuItem(MP_OPEN,((file->GetStatus() == PS_COMPLETE) ? MF_ENABLED:MF_GRAYED)); //<<--9/21/02
m_FileMenu.EnableMenuItem(MP_PREVIEW,((file->PreviewAvailable()) ? MF_ENABLED:MF_GRAYED));
m_FileMenu.EnableMenuItem(MP_CANCEL,((!filedone) ? MF_ENABLED:MF_GRAYED));
m_PrioMenu.CheckMenuItem(MP_PRIOAUTO, ((file->IsAutoDownPriority()) ? MF_CHECKED:MF_UNCHECKED));
m_PrioMenu.CheckMenuItem(MP_PRIOHIGH, ((file->GetDownPriority() == PR_HIGH && !file->IsAutoDownPriority()) ? MF_CHECKED:MF_UNCHECKED));
m_PrioMenu.CheckMenuItem(MP_PRIONORMAL, ((file->GetDownPriority() == PR_NORMAL && !file->IsAutoDownPriority()) ? MF_CHECKED:MF_UNCHECKED));
m_PrioMenu.CheckMenuItem(MP_PRIOLOW, ((file->GetDownPriority() == PR_LOW && !file->IsAutoDownPriority()) ? MF_CHECKED:MF_UNCHECKED));
int counter;
m_Web.CreateMenu();
UpdateURLMenu(m_Web,counter);
UINT flag;
flag=(counter==0) ? MF_GRAYED:MF_STRING;
m_FileMenu.AppendMenu(flag|MF_POPUP,(UINT_PTR)m_Web.m_hMenu, GetResString(IDS_WEBSERVICES) );
// create cat-submenue
CTitleMenu cats;
cats.CreatePopupMenu();
cats.AddMenuTitle(GetResString(IDS_CAT));
flag=(theApp.glob_prefs->GetCatCount()==1) ? MF_GRAYED:MF_STRING;
if (theApp.glob_prefs->GetCatCount()>1) {
for (int i=0;i<theApp.glob_prefs->GetCatCount();i++) {
cats.AppendMenu(MF_STRING,MP_ASSIGNCAT+i, (i==0)?GetResString(IDS_CAT_UNASSIGN):theApp.glob_prefs->GetCategory(i)->title);
}
}
m_FileMenu.AppendMenu(flag|MF_POPUP,(UINT_PTR)cats.m_hMenu, GetResString(IDS_TOCAT) );
m_FileMenu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, point.y, this);
m_FileMenu.RemoveMenu(m_FileMenu.GetMenuItemCount()-1,MF_BYPOSITION);
m_FileMenu.RemoveMenu(m_FileMenu.GetMenuItemCount()-1,MF_BYPOSITION);
m_Web.DestroyMenu();
cats.DestroyMenu();
}else {
m_ClientMenu.CreatePopupMenu();
m_ClientMenu.AddMenuTitle(GetResString(IDS_CLIENTS));
m_ClientMenu.AppendMenu(MF_STRING,MP_DETAIL, GetResString(IDS_SHOWDETAILS));
m_ClientMenu.AppendMenu(MF_STRING,MP_ADDFRIEND, GetResString(IDS_ADDFRIEND));
m_ClientMenu.AppendMenu(MF_STRING,MP_MESSAGE, GetResString(IDS_SEND_MSG));
m_ClientMenu.AppendMenu(MF_STRING,MP_SHOWLIST, GetResString(IDS_VIEWFILES));
m_ClientMenu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, point.y, this);
m_ClientMenu.DestroyMenu();
}
}
else{
m_FileMenu.EnableMenuItem(MP_CANCEL,MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_PAUSE,MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_STOP,MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_RESUME,MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_PREVIEW,MF_GRAYED);
m_FileMenu.EnableMenuItem(MP_OPEN,MF_GRAYED); //<<--9/21/02
m_FileMenu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, point.y, this);
}
}
BOOL CDownloadListCtrl::OnCommand(WPARAM wParam,LPARAM lParam ){
if (GetSelectionMark() != (-1)){
CtrlItem_Struct* content = (CtrlItem_Struct*)this->GetItemData(GetSelectionMark());
/////////////////////////////////////////////////////////////
//for multiple selections
UINT selectedCount = this->GetSelectedCount();
CTypedPtrList<CPtrList, CPartFile*> selectedList;
int index = -1;
POSITION pos = this->GetFirstSelectedItemPosition();
while(pos != NULL)
{
index = this->GetNextSelectedItem(pos);
if(index > -1)
{
if (((CtrlItem_Struct*)this->GetItemData(index))->type == FILE_TYPE)
selectedList.AddTail((CPartFile*)((CtrlItem_Struct*)this->GetItemData(index))->value);
}
}
if (content->type == FILE_TYPE){
CPartFile* file = (CPartFile*)content->value;
if (wParam>=MP_WEBURL && wParam<=MP_WEBURL+99) {
RunURL(file, theApp.webservices.GetAt(wParam-MP_WEBURL) );
}
if (wParam>=MP_ASSIGNCAT && wParam<=MP_ASSIGNCAT+99) {
while(!selectedList.IsEmpty()) {
CPartFile *selected = selectedList.GetHead();
selected->SetCategory(wParam-MP_ASSIGNCAT);
selectedList.RemoveHead();
}
ChangeCategory(curTab);
}
switch (wParam)
{
case MP_CANCEL:
{
//for multiple selections
if(selectedCount > 1)
{
SetRedraw(false);
CString fileList;
for (pos = selectedList.GetHeadPosition() ; pos != 0 ; selectedList.GetNext(pos))
{
fileList += "\n" ;
fileList += selectedList.GetAt(pos)->GetFileName();
}
if (MessageBox((GetResString(IDS_Q_CANCELDL) + fileList),GetResString(IDS_CANCEL),MB_ICONQUESTION|MB_YESNO) == IDYES)
{
while(!selectedList.IsEmpty())
{
HideSources(selectedList.GetHead());
switch(selectedList.GetHead()->GetStatus()) {
case PS_WAITINGFORHASH:
case PS_HASHING:
case PS_COMPLETING:
case PS_COMPLETE:
selectedList.RemoveHead();
break;
case PS_PAUSED:
selectedList.GetHead()->DeleteFile();
selectedList.RemoveHead();
break;
default:
theApp.downloadqueue->StartNextFile();
selectedList.GetHead()->DeleteFile();
selectedList.RemoveHead();
}
}
}
SetRedraw(true);
break;
}
// single selection
switch(file->GetStatus())
{
case PS_WAITINGFORHASH:
case PS_HASHING:
case PS_COMPLETING:
case PS_COMPLETE:
break;
case PS_PAUSED:
if (MessageBox(GetResString(IDS_Q_CANCELDL2),GetResString(IDS_CANCEL),MB_ICONQUESTION|MB_YESNO) == IDYES) {
HideSources(file);
file->DeleteFile();
}
break;
default:
if (MessageBox(GetResString(IDS_Q_CANCELDL2),GetResString(IDS_CANCEL),MB_ICONQUESTION|MB_YESNO) == IDYES) {
HideSources(file);
file->DeleteFile();
theApp.downloadqueue->StartNextFile();
}
break;
}
break;
}
case MP_PRIOHIGH:
if(selectedCount > 1)
{
SetRedraw(false);
while(!selectedList.IsEmpty()) {
selectedList.GetHead()->SetAutoDownPriority(false);
selectedList.GetHead()->SetDownPriority(PR_HIGH);
selectedList.RemoveHead();
}
SetRedraw(true);
break;
}
file->SetAutoDownPriority(false);
file->SetDownPriority(PR_HIGH);
break;
case MP_PRIOLOW:
if(selectedCount > 1)
{
SetRedraw(false);
while(!selectedList.IsEmpty()) {
selectedList.GetHead()->SetAutoDownPriority(false);
selectedList.GetHead()->SetDownPriority(PR_LOW);
selectedList.RemoveHead();
}
SetRedraw(true);
break;
}
file->SetAutoDownPriority(false);
file->SetDownPriority(PR_LOW);
break;
case MP_PRIONORMAL:
if(selectedCount > 1)
{
SetRedraw(false);
while(!selectedList.IsEmpty()) {
selectedList.GetHead()->SetAutoDownPriority(false);
selectedList.GetHead()->SetDownPriority(PR_NORMAL);
selectedList.RemoveHead();
}
SetRedraw(true);
break;
}
file->SetAutoDownPriority(false);
file->SetDownPriority(PR_NORMAL);
break;
case MP_PRIOAUTO:
if(selectedCount > 1)
{
SetRedraw(false);
while(!selectedList.IsEmpty()) {
selectedList.GetHead()->SetAutoDownPriority(true);
selectedList.GetHead()->SetDownPriority(PR_HIGH);
selectedList.RemoveHead();
}
SetRedraw(true);
break;
}
file->SetAutoDownPriority(true);
file->SetDownPriority(PR_HIGH);
break;
case MP_PAUSE:
if(selectedCount > 1)
{
SetRedraw(false);
while(!selectedList.IsEmpty()) {
selectedList.GetHead()->PauseFile();
selectedList.RemoveHead();
}
SetRedraw(true);
break;
}
file->PauseFile();
break;
case MP_RESUME:
if(selectedCount > 1)
{
SetRedraw(false);
while(!selectedList.IsEmpty()) {
selectedList.GetHead()->ResumeFile();
selectedList.RemoveHead();
}
SetRedraw(true);
break;
}
file->ResumeFile();
break;
case MP_STOP:
if(selectedCount > 1)
{
SetRedraw(false);
while(!selectedList.IsEmpty()) {
CPartFile *selected = selectedList.GetHead();
HideSources(selected);
selected->StopFile();
selectedList.RemoveHead();
}
SetRedraw(true);
break;
}
HideSources(file);
file->StopFile();
break;
case MP_CLEARCOMPLETED:
SetRedraw(false);
ClearCompleted();
SetRedraw(true);
break;
case MP_METINFO:
{
CFileDetailDialog dialog(file);
dialog.DoModal();
break;
}
case MP_GETED2KLINK:
if(selectedCount > 1)
{
CString str;
while(!selectedList.IsEmpty()) {
str += theApp.CreateED2kLink(selectedList.GetHead()) + "\n";
selectedList.RemoveHead();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -