📄 ctrluploads.cpp
字号:
return FALSE;
}
//////////////////////////////////////////////////////////////////////////////
// CUploadsCtrl queue / file abstractation layer
POSITION CUploadsCtrl::GetQueueIterator()
{
if ( Settings.Uploads.FilterMask & ULF_TORRENT )
{
return (POSITION)UploadQueues.m_pTorrentQueue;
}
else if ( Settings.Uploads.FilterMask & ( ULF_ACTIVE | ULF_QUEUED ) )
{
return UploadQueues.GetIterator();
}
else if ( Settings.Uploads.FilterMask & ULF_HISTORY )
{
return (POSITION)UploadQueues.m_pHistoryQueue;
}
else
{
return NULL;
}
}
CUploadQueue* CUploadsCtrl::GetNextQueue(POSITION& pos)
{
ASSERT( pos != NULL );
if ( pos == (POSITION)UploadQueues.m_pTorrentQueue )
{
if ( Settings.Uploads.FilterMask & ( ULF_ACTIVE | ULF_QUEUED ) )
{
pos = UploadQueues.GetIterator();
if ( pos == NULL ) pos = (POSITION)UploadQueues.m_pHistoryQueue;
}
else if ( Settings.Uploads.FilterMask & ULF_HISTORY )
{
pos = (POSITION)UploadQueues.m_pHistoryQueue;
}
else
{
pos = NULL;
}
return UploadQueues.m_pTorrentQueue;
}
else if ( pos == (POSITION)UploadQueues.m_pHistoryQueue )
{
pos = NULL;
return UploadQueues.m_pHistoryQueue;
}
else
{
CUploadQueue* pQueue = UploadQueues.GetNext( pos );
if ( pos == NULL )
{
if ( Settings.Uploads.FilterMask & ULF_HISTORY )
{
pos = (POSITION)UploadQueues.m_pHistoryQueue;
}
}
return pQueue;
}
}
POSITION CUploadsCtrl::GetFileIterator(CUploadQueue* pQueue)
{
if ( pQueue == UploadQueues.m_pTorrentQueue )
{
for ( POSITION posNext = UploadFiles.GetIterator() ; posNext ; )
{
POSITION posThis = posNext;
CUploadFile* pFile = UploadFiles.GetNext( posNext );
CUploadTransfer* pTransfer = pFile->GetActive();
if ( pTransfer == NULL || pTransfer->m_nState == upsNull ) continue;
if ( pTransfer->m_nProtocol != PROTOCOL_BT ) continue;
return posThis;
}
return NULL;
}
else if ( pQueue == UploadQueues.m_pHistoryQueue )
{
for ( POSITION posNext = UploadFiles.GetIterator() ; posNext ; )
{
POSITION posThis = posNext;
CUploadFile* pFile = UploadFiles.GetNext( posNext );
CUploadTransfer* pTransfer = pFile->GetActive();
if ( pTransfer != NULL )
{
if ( pTransfer->m_nProtocol == PROTOCOL_BT && pTransfer->m_nState != upsNull ) continue;
if ( pTransfer->m_pQueue != NULL ) continue;
}
return posThis;
}
return NULL;
}
else
{
if ( Settings.Uploads.FilterMask & ULF_ACTIVE )
{
if ( pQueue->m_pActive.GetCount() > 0 )
{
return pQueue->m_pActive.GetHeadPosition();
}
}
if ( Settings.Uploads.FilterMask & ULF_QUEUED )
{
if ( pQueue->m_pQueued.GetCount() > 0 )
{
return (POSITION)1;
}
}
return NULL;
}
}
CUploadFile* CUploadsCtrl::GetNextFile(CUploadQueue* pQueue, POSITION& pos, int* pnPosition)
{
ASSERT( pos != NULL );
if ( pnPosition != NULL ) *pnPosition = -1;
if ( pQueue == UploadQueues.m_pTorrentQueue )
{
CUploadFile* pReturn = UploadFiles.GetNext( pos );
for ( ; pos ; )
{
POSITION posThis = pos;
CUploadFile* pFile = UploadFiles.GetNext( pos );
CUploadTransfer* pTransfer = pFile->GetActive();
if ( pTransfer == NULL || pTransfer->m_nState == upsNull ) continue;
if ( pTransfer->m_nProtocol != PROTOCOL_BT ) continue;
pos = posThis;
break;
}
return pReturn;
}
else if ( pQueue == UploadQueues.m_pHistoryQueue )
{
CUploadFile* pReturn = UploadFiles.GetNext( pos );
for ( ; pos ; )
{
POSITION posThis = pos;
CUploadFile* pFile = UploadFiles.GetNext( pos );
CUploadTransfer* pTransfer = pFile->GetActive();
if ( pTransfer != NULL )
{
if ( pTransfer->m_nProtocol == PROTOCOL_BT && pTransfer->m_nState != upsNull ) continue;
if ( pTransfer->m_pQueue != NULL ) continue;
}
pos = posThis;
break;
}
return pReturn;
}
else if ( (int)pos > pQueue->m_pQueued.GetSize() )
{
CUploadTransfer* pTransfer = (CUploadTransfer*)pQueue->m_pActive.GetNext( pos );
if ( pos == NULL )
{
if ( Settings.Uploads.FilterMask & ULF_QUEUED )
{
if ( pQueue->m_pQueued.GetCount() > 0 )
{
pos = (POSITION)1;
}
}
}
if ( pnPosition != NULL ) *pnPosition = 0;
return pTransfer->m_pBaseFile;
}
else
{
CUploadTransfer* pTransfer = (CUploadTransfer*)pQueue->m_pQueued.GetAt( (int)pos - 1 );
if ( pnPosition != NULL ) *pnPosition = (int)pos;
pos = (POSITION)( (int)pos + 1 );
if ( (int)pos > pQueue->m_pQueued.GetSize() ) pos = NULL;
return pTransfer->m_pBaseFile;
}
}
//////////////////////////////////////////////////////////////////////////////
// CUploadsCtrl presentation message handlers
void CUploadsCtrl::OnSize(UINT nType, int cx, int cy)
{
int nWidth = 0, nHeight = 0;
CRect rcClient;
HDITEM pColumn;
if ( nType != 1982 ) CWnd::OnSize( nType, cx, cy );
GetClientRect( &rcClient );
ZeroMemory( &pColumn, sizeof(pColumn) );
pColumn.mask = HDI_WIDTH;
for ( int nColumn = 0 ; m_wndHeader.GetItem( nColumn, &pColumn ) ; nColumn ++ )
nWidth += pColumn.cxy;
SCROLLINFO pScroll;
ZeroMemory( &pScroll, sizeof(pScroll) );
pScroll.cbSize = sizeof(pScroll);
pScroll.fMask = SIF_RANGE|SIF_PAGE;
pScroll.nMin = 0;
pScroll.nMax = nWidth;
pScroll.nPage = rcClient.right;
SetScrollInfo( SB_HORZ, &pScroll, TRUE );
int nScroll = GetScrollPos( SB_HORZ );
m_wndHeader.SetWindowPos( NULL, -nScroll, 0, rcClient.right + nScroll, HEADER_HEIGHT, SWP_SHOWWINDOW );
CSingleLock pLock( &Transfers.m_pSection, TRUE );
for ( POSITION posQueue = GetQueueIterator() ; posQueue ; )
{
CUploadQueue* pQueue = GetNextQueue( posQueue );
POSITION posFile = GetFileIterator( pQueue );
if ( posFile == NULL )
{
pQueue->m_bSelected = FALSE;
continue;
}
nHeight ++;
if ( ! pQueue->m_bExpanded ) continue;
while ( posFile )
{
if ( GetNextFile( pQueue, posFile ) ) nHeight ++;
}
}
pLock.Unlock();
ZeroMemory( &pScroll, sizeof(pScroll) );
pScroll.cbSize = sizeof(pScroll);
pScroll.fMask = SIF_RANGE|SIF_PAGE;
pScroll.nMin = 0;
pScroll.nMax = nHeight;
pScroll.nPage = ( rcClient.bottom - HEADER_HEIGHT ) / ITEM_HEIGHT + 1;
SetScrollInfo( SB_VERT, &pScroll, TRUE );
m_nFocus = min( m_nFocus, max( 0, nHeight - 1 ) );
Invalidate();
}
//////////////////////////////////////////////////////////////////////////////
// CUploadsCtrl painting
void CUploadsCtrl::OnPaint()
{
CSingleLock pLock( &Transfers.m_pSection, TRUE );
CRect rcClient, rcItem;
CPaintDC dc( this );
GetClientRect( &rcClient );
rcClient.top += HEADER_HEIGHT;
rcItem.CopyRect( &rcClient );
rcItem.left -= GetScrollPos( SB_HORZ );
rcItem.bottom = rcItem.top + ITEM_HEIGHT;
int nScroll = GetScrollPos( SB_VERT );
int nIndex = 0;
CFont* pfOld = (CFont*)dc.SelectObject( &theApp.m_gdiFont );
BOOL bFocus = ( GetFocus() == this );
for ( POSITION posQueue = GetQueueIterator() ; posQueue && rcItem.top < rcClient.bottom ; )
{
CUploadQueue* pQueue = GetNextQueue( posQueue );
POSITION posFile = GetFileIterator( pQueue );
if ( posFile == NULL ) continue;
if ( nScroll > 0 )
{
nScroll --;
}
else
{
PaintQueue( dc, rcItem, pQueue, bFocus && ( m_nFocus == nIndex ) );
rcItem.OffsetRect( 0, ITEM_HEIGHT );
}
nIndex ++;
if ( ! pQueue->m_bExpanded ) continue;
while ( posFile && rcItem.top < rcClient.bottom && rcItem.top < rcClient.bottom )
{
int nPosition;
CUploadFile* pFile = GetNextFile( pQueue, posFile, &nPosition );
if ( pFile == NULL ) continue;
if ( nScroll > 0 )
{
nScroll --;
}
else
{
PaintFile( dc, rcItem, pQueue, pFile, nPosition, bFocus && ( m_nFocus == nIndex ) );
rcItem.OffsetRect( 0, ITEM_HEIGHT );
}
nIndex ++;
}
}
dc.SelectObject( pfOld );
rcClient.top = rcItem.top;
if ( rcClient.top < rcClient.bottom )
dc.FillSolidRect( &rcClient, CoolInterface.m_crWindow );
}
void CUploadsCtrl::PaintQueue(CDC& dc, const CRect& rcRow, CUploadQueue* pQueue, BOOL bFocus)
{
COLORREF crNatural = CoolInterface.m_crWindow;
COLORREF crBack = pQueue->m_bSelected ? CoolInterface.m_crBackSel : crNatural;
dc.SetBkColor( crBack );
dc.SetBkMode( OPAQUE );
if ( pQueue->m_bSelected )
dc.SetTextColor( CoolInterface.m_crText );
else
dc.SetTextColor( CoolInterface.m_crText );
int nTextLeft = rcRow.right, nTextRight = rcRow.left;
HDITEM pColumn;
ZeroMemory( &pColumn, sizeof(pColumn) );
pColumn.mask = HDI_FORMAT | HDI_LPARAM;
dc.SelectObject( &theApp.m_gdiFontBold );
for ( int nColumn = 0 ; m_wndHeader.GetItem( nColumn, &pColumn ) ; nColumn++ )
{
CString strText;
CRect rcCell;
m_wndHeader.GetItemRect( nColumn, &rcCell );
rcCell.left += rcRow.left;
rcCell.right += rcRow.left;
rcCell.top = rcRow.top;
rcCell.bottom = rcRow.bottom;
switch ( pColumn.lParam )
{
case UPLOAD_COLUMN_TITLE:
dc.FillSolidRect( rcCell.left, rcCell.bottom - 1, 32, 1, crNatural );
ImageList_DrawEx( ShellIcons.GetHandle( 16 ), pQueue->m_bExpanded ? SHI_MINUS : SHI_PLUS, dc.GetSafeHdc(),
rcCell.left, rcCell.top, 16, 16, crNatural, CLR_DEFAULT, ILD_NORMAL );
rcCell.left += 16;
if ( pQueue == UploadQueues.m_pTorrentQueue )
{
ImageList_DrawEx( m_pProtocols, PROTOCOL_BT, dc.GetSafeHdc(),
rcCell.left, rcCell.top, 16, 16, crNatural, CLR_DEFAULT, pQueue->m_bSelected ? ILD_SELECTED : ILD_NORMAL );
}
else if ( pQueue->m_nProtocols == ( 1 << PROTOCOL_HTTP ) )
{
ImageList_DrawEx( m_pProtocols, PROTOCOL_HTTP, dc.GetSafeHdc(),
rcCell.left, rcCell.top, 16, 16, crNatural, CLR_DEFAULT, pQueue->m_bSelected ? ILD_SELECTED : ILD_NORMAL );
}
else if ( pQueue->m_nProtocols == ( 1 << PROTOCOL_ED2K ) )
{
ImageList_DrawEx( m_pProtocols, PROTOCOL_ED2K, dc.GetSafeHdc(),
rcCell.left, rcCell.top, 16, 16, crNatural, CLR_DEFAULT, pQueue->m_bSelected ? ILD_SELECTED : ILD_NORMAL );
}
else
{
ImageList_DrawEx( ShellIcons.GetHandle( 16 ), pQueue->m_bExpanded ? SHI_FOLDER_OPEN : SHI_FOLDER_CLOSED, dc.GetSafeHdc(),
rcCell.left, rcCell.top, 16, 16, crNatural, CLR_DEFAULT, pQueue->m_bSelected ? ILD_SELECTED : ILD_NORMAL );
}
rcCell.left += 16;
dc.FillSolidRect( rcCell.left, rcCell.top, 1, rcCell.Height(), crNatural );
rcCell.left += 1;
strText = pQueue->m_sName;
break;
case UPLOAD_COLUMN_SIZE:
if ( pQueue != UploadQueues.m_pTorrentQueue && pQueue != UploadQueues.m_pHistoryQueue )
strText.Format( _T("%i/%i"), pQueue->GetTransferCount(), pQueue->GetQueuedCount() );
break;
case UPLOAD_COLUMN_SPEED:
if ( pQueue != UploadQueues.m_pTorrentQueue && pQueue != UploadQueues.m_pHistoryQueue )
{
strText = Settings.SmartVolume( pQueue->GetMeasuredSpeed() * 8, FALSE, TRUE );
}
break;
}
nTextLeft = min( nTextLeft, rcCell.left );
nTextRight = max( nTextRight, rcCell.right );
if ( rcCell.Width() < 8 ) strText.Empty();
if ( dc.GetTextExtent( strText ).cx > rcCell.Width() - 8 )
{
while ( dc.GetTextExtent( strText + _T("
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -