📄 searchlistctrl.cpp
字号:
if ((pGetInfoTip->dwFlags & LVGIT_UNFOLDED) == 0 && pGetInfoTip->cchTextMax > 0 && pGetInfoTip->pszText[0] != '\0')
pGetInfoTip->pszText[0] = '\0';
}
return;
}
if (GetSelectedCount() == 1)
{
const CSearchFile* file = (CSearchFile*)GetItemData(pGetInfoTip->iItem);
if (file && pGetInfoTip->pszText && pGetInfoTip->cchTextMax > 0){
CString strInfo;
const CArray<CTag*,CTag*>& tags = file->GetTags();
for (int i = 0; i < tags.GetSize(); i++){
const CTag* tag = tags[i];
if (tag){
CString strTag;
switch (tag->GetNameID()){
case FT_FILENAME:
strTag.Format(_T("%s: %s"), GetResString(IDS_SW_NAME), tag->GetStr());
break;
case FT_FILESIZE:
strTag.Format(_T("%s: %s"), GetResString(IDS_DL_SIZE), CastItoXBytes(tag->GetInt(), false, false));
break;
case FT_FILETYPE:
strTag.Format(_T("%s: %s"), GetResString(IDS_TYPE), tag->GetStr());
break;
case FT_FILEFORMAT:
strTag.Format(_T("%s: %s"), GetResString(IDS_SEARCHEXTENTION), tag->GetStr());
break;
case FT_SOURCES:
strTag.Format(_T("%s: %u"), GetResString(IDS_SEARCHAVAIL), tag->GetInt());
break;
case 0x13: // remote client's upload file priority (tested with Hybrid 0.47)
if (tag->GetInt() == 0)
strTag = GetResString(IDS_PRIORITY) + _T(": ") + GetResString(IDS_PRIONORMAL);
else if (tag->GetInt() == 2)
strTag = GetResString(IDS_PRIORITY) + _T(": ") + GetResString(IDS_PRIOHIGH);
else if (tag->GetInt() == -2)
strTag = GetResString(IDS_PRIORITY) + _T(": ") + GetResString(IDS_PRIOLOW);
#ifdef _DEBUG
else
strTag.Format(_T("%s: %d (***Unknown***)"), GetResString(IDS_PRIORITY), tag->GetInt());
#endif
break;
default:{
bool bUnkTag = false;
if (tag->GetName()){
strTag.Format(_T("%s: "), tag->GetName());
strTag = strTag.Left(1).MakeUpper() + strTag.Mid(1);
}
else{
extern CString GetName(const CTag* pTag);
CString strTagName = GetName(tag);
if (!strTagName.IsEmpty()){
strTag.Format(_T("%s: "), strTagName);
}
else{
#ifdef _DEBUG
strTag.Format(_T("Unknown tag #%02X: "), tag->GetNameID());
#else
bUnkTag = true;
#endif
}
}
if (!bUnkTag){
if (tag->IsStr())
strTag += tag->GetStr();
else if (tag->IsInt()){
if (tag->GetNameID() == FT_MEDIA_LENGTH){
CString strTemp;
SecToTimeLength(tag->GetInt(), strTemp);
strTag += strTemp;
}
else{
TCHAR szBuff[16];
_itot(tag->GetInt(), szBuff, 10);
strTag += szBuff;
}
}
else if (tag->IsFloat()){
TCHAR szBuff[32];
_sntprintf(szBuff, ARRSIZE(szBuff), _T("%f"), tag->GetFloat());
strTag += szBuff;
}
else{
#ifdef _DEBUG
CString strBuff;
strBuff.Format(_T("Unknown value type=#%02X"), tag->GetType());
strTag += strBuff;
#else
strTag.Empty();
#endif
}
}
}
}
if (!strTag.IsEmpty()){
if (!strInfo.IsEmpty())
strInfo += _T("\n");
strInfo += strTag;
if (strInfo.GetLength() >= pGetInfoTip->cchTextMax)
break;
}
}
}
#ifdef _DEBUG
if (file->GetClientsCount()){
CString strSource;
if (file->GetClientID() && file->GetClientPort()){
uint32 uClientIP = file->GetClientID();
uint32 uServerIP = file->GetClientServerIP();
strSource.Format(_T("Source: %u.%u.%u.%u:%u Server: %u.%u.%u.%u:%u"),
(uint8)uClientIP,(uint8)(uClientIP>>8),(uint8)(uClientIP>>16),(uint8)(uClientIP>>24), file->GetClientPort(),
(uint8)uServerIP,(uint8)(uServerIP>>8),(uint8)(uServerIP>>16),(uint8)(uServerIP>>24), file->GetClientServerPort());
if (!strInfo.IsEmpty())
strInfo += _T("\n");
strInfo += strSource;
}
const CSimpleArray<CSearchFile::SClient>& aClients = file->GetClients();
for (int i = 0; i < aClients.GetSize(); i++){
uint32 uClientIP = aClients[i].m_nIP;
uint32 uServerIP = aClients[i].m_nServerIP;
strSource.Format(_T("Source: %u.%u.%u.%u:%u Server: %u.%u.%u.%u:%u"),
(uint8)uClientIP,(uint8)(uClientIP>>8),(uint8)(uClientIP>>16),(uint8)(uClientIP>>24), aClients[i].m_nPort,
(uint8)uServerIP,(uint8)(uServerIP>>8),(uint8)(uServerIP>>16),(uint8)(uServerIP>>24), aClients[i].m_nServerPort);
if (!strInfo.IsEmpty())
strInfo += _T("\n");
strInfo += strSource;
if (strInfo.GetLength() >= pGetInfoTip->cchTextMax)
break;
}
}
if (file->GetServers().GetSize()){
CString strServer;
const CSimpleArray<CSearchFile::SServer>& aServers = file->GetServers();
for (int i = 0; i < aServers.GetSize(); i++){
uint32 uServerIP = aServers[i].m_nIP;
strServer.Format(_T("Server: %u.%u.%u.%u:%u Avail: %u"),
(uint8)uServerIP,(uint8)(uServerIP>>8),(uint8)(uServerIP>>16),(uint8)(uServerIP>>24), aServers[i].m_nPort, aServers[i].m_uAvail);
if (!strInfo.IsEmpty())
strInfo += _T("\n");
strInfo += strServer;
if (strInfo.GetLength() >= pGetInfoTip->cchTextMax)
break;
}
}
#endif
_tcsncpy(pGetInfoTip->pszText, strInfo, pGetInfoTip->cchTextMax);
pGetInfoTip->pszText[pGetInfoTip->cchTextMax-1] = _T('\0');
}
}
else
{
int iSelected = 0;
ULONGLONG ulTotalSize = 0;
POSITION pos = GetFirstSelectedItemPosition();
while (pos)
{
const CSearchFile* pFile = (CSearchFile*)GetItemData(GetNextSelectedItem(pos));
if (pFile)
{
iSelected++;
ulTotalSize += pFile->GetFileSize();
}
}
if (iSelected > 0)
{
CString strInfo;
strInfo.Format(_T("%s: %u\r\n%s: %s"), GetResString(IDS_FILES), iSelected, GetResString(IDS_DL_SIZE), CastItoXBytes(ulTotalSize));
_tcsncpy(pGetInfoTip->pszText, strInfo, pGetInfoTip->cchTextMax);
pGetInfoTip->pszText[pGetInfoTip->cchTextMax-1] = _T('\0');
}
}
}
*pResult = 0;
}
void CSearchListCtrl::ExpandCollapseItem(int item)
{
if (item == -1)
return;
CSearchFile* searchfile = (CSearchFile*)GetItemData(item);
if (searchfile->GetListParent() != NULL)
{
searchfile = searchfile->GetListParent();
LVFINDINFO find;
find.flags = LVFI_PARAM;
find.lParam = (LPARAM)searchfile;
item = FindItem(&find);
if (item == -1)
return;
}
if (!searchfile)
return;
// Check if the source branch is disable
if (!searchfile->GetListIsExpanded())
{
// only expand when more than one child (more than the original entry itself)
if (searchfile->GetListChildCount() < 2)
return;
// Go through the whole list to find out the sources for this file
SetRedraw(FALSE);
for (POSITION pos = theApp.searchlist->list.GetHeadPosition(); pos != NULL; ){
const CSearchFile* cur_file = theApp.searchlist->list.GetNext(pos);
if(cur_file->GetListParent() == searchfile){
searchfile->SetListIsExpanded(true);
InsertItem(LVIF_PARAM|LVIF_TEXT,item+1,cur_file->GetFileName(),0,0,0,(LPARAM)cur_file);
}
}
SetRedraw(TRUE);
}
else {
HideSources(searchfile);
}
Update(item);
}
void CSearchListCtrl::HideSources(CSearchFile* toCollapse)
{
SetRedraw(FALSE);
int pre,post;
pre = post = 0;
for(int i = 0; i < GetItemCount(); i++) {
const CSearchFile* item = (CSearchFile*)GetItemData(i);
if(item->GetListParent() == toCollapse) {
pre++;
DeleteItem(i--);
post++;
}
}
if (pre - post == 0)
toCollapse->SetListIsExpanded(false);
SetRedraw(TRUE);
}
void CSearchListCtrl::OnClick(NMHDR *pNMHDR, LRESULT *pResult)
{
POINT point;
::GetCursorPos(&point);
CPoint p = point;
ScreenToClient(&p);
LPNMITEMACTIVATE pNMIA = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
if (p.x<10)
ExpandCollapseItem(pNMIA->iItem);
}
void CSearchListCtrl::OnDblClick(NMHDR *pNMHDR, LRESULT *pResult)
{
POINT point;
::GetCursorPos(&point);
CPoint p = point;
ScreenToClient(&p);
if (p.x > 10){
if (GetKeyState(VK_MENU) & 0x8000){
int iSel = GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED);
if (iSel != -1){
const CSearchFile* file = (CSearchFile*)GetItemData(iSel);
if (file){
CSearchResultFileDetailSheet sheet(file);
sheet.DoModal();
}
}
}
else
theApp.emuledlg->searchwnd->DownloadSelected();
}
}
void CSearchListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if (!theApp.emuledlg->IsRunning())
return;
if (!lpDrawItemStruct->itemData)
return;
CDC* odc = CDC::FromHandle(lpDrawItemStruct->hDC);
CSearchFile* content = (CSearchFile*)lpDrawItemStruct->itemData;
BOOL bCtrlFocused = ((GetFocus() == this) || (GetStyle() & LVS_SHOWSELALWAYS));
if (content->GetListParent()==NULL && (lpDrawItemStruct->itemAction | ODA_SELECT) && (lpDrawItemStruct->itemState & ODS_SELECTED))
{
if (bCtrlFocused)
odc->SetBkColor(m_crHighlight);
else
odc->SetBkColor(m_crNoHighlight);
}
else
odc->SetBkColor(GetBkColor());
CMemDC dc(odc, &lpDrawItemStruct->rcItem);
CFont *pOldFont = dc->SelectObject(GetFont());
COLORREF crOldTextColor = dc->SetTextColor(m_crWindowText);
int iOldBkMode;
if (m_crWindowTextBk == CLR_NONE)
{
DefWindowProc(WM_ERASEBKGND, (WPARAM)(HDC)dc, 0);
iOldBkMode = dc.SetBkMode(TRANSPARENT);
}
else
iOldBkMode = OPAQUE;
BOOL notLast = lpDrawItemStruct->itemID + 1 != GetItemCount();
BOOL notFirst = lpDrawItemStruct->itemID != 0;
int tree_start = 0;
int tree_end = 0;
CRect cur_rec(lpDrawItemStruct->rcItem);
//offset was 4, now it's the standard 2 spaces
int iOffset = dc->GetTextExtent(_T(" "), 1 ).cx*2;
CHeaderCtrl *pHeaderCtrl = GetHeaderCtrl();
int iCount = pHeaderCtrl->GetItemCount();
cur_rec.right = cur_rec.left;
cur_rec.right -= iOffset;
cur_rec.left += iOffset;
// icon
int ofs;
if (content->GetListParent()!=NULL)
ofs = 14; // indent child items
else
ofs = 6;
int iImage = theApp.GetFileTypeSystemImageIdx(content->GetFileName());
ImageList_Draw(theApp.GetSystemImageList(), iImage, dc, cur_rec.left+ofs, cur_rec.top, ILD_NORMAL|ILD_TRANSPARENT);
// Parent entries
if (content->GetListParent() == NULL)
{
for (int iCurrent = 0; iCurrent < iCount; iCurrent++)
{
int iColumn = pHeaderCtrl->OrderToIndex(iCurrent);
if (!IsColumnHidden(iColumn))
{
int cx = CListCtrl::GetColumnWidth(iColumn);
if (iColumn == 0)
{
int iNextLeft = cur_rec.left + cx;
//set up tree vars
cur_rec.left = cur_rec.right + iOffset;
cur_rec.right = cur_rec.left + min(8, cx);
tree_start = cur_rec.left + 1;
tree_end = cur_rec.right;
//normal column stuff
cur_rec.left = cur_rec.right + 1;
cur_rec.right = tree_start + cx - iOffset;
DrawSourceParent(dc, 0, &cur_rec, content);
cur_rec.left = iNextLeft;
}
else
{
cur_rec.right += cx;
DrawSourceParent(dc, iColumn, &cur_rec, content);
cur_rec.left += cx;
}
}
}
}
else
{
for (int iCurrent = 0; iCurrent < iCount; iCurrent++)
{
int iColumn = pHeaderCtrl->OrderToIndex(iCurrent);
if (!IsColumnHidden(iColumn))
{
int cx = CListCtrl::GetColumnWidth(iColumn);
if (iColumn == 0)
{
int iNextLeft = cur_rec.left + cx;
//set up tree vars
cur_rec.left = cur_rec.right + iOffset;
cur_rec.right = cur_rec.left + min(8, cx);
tree_start = cur_rec.left + 1;
tree_end = cur_rec.right;
//normal column stuff
cur_rec.left = cur_rec.right + 1;
cur_rec.right = tree_start + cx - iOffset;
DrawSourceChild(dc, 0, &cur_rec, content);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -