📄 ctrluploads.cpp
字号:
//
// CtrlUploads.cpp
//
// Copyright (c) Shareaza Development Team, 2002-2004.
// This file is part of SHAREAZA (www.shareaza.com)
//
// Shareaza is free software; you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// Shareaza is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Shareaza; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#include "StdAfx.h"
#include "Shareaza.h"
#include "Settings.h"
#include "Transfers.h"
#include "UploadQueues.h"
#include "UploadQueue.h"
#include "UploadFiles.h"
#include "UploadFile.h"
#include "UploadTransfer.h"
#include "UploadTransferBT.h"
#include "CoolInterface.h"
#include "ShellIcons.h"
#include "FragmentBar.h"
#include "Skin.h"
#include "CtrlUploads.h"
IMPLEMENT_DYNAMIC(CUploadsCtrl, CWnd)
BEGIN_MESSAGE_MAP(CUploadsCtrl, CWnd)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_SIZE()
ON_WM_PAINT()
ON_WM_VSCROLL()
ON_WM_HSCROLL()
ON_WM_MOUSEWHEEL()
ON_NOTIFY(HDN_ITEMCHANGEDW, AFX_IDW_PANE_FIRST, OnChangeHeader)
ON_NOTIFY(HDN_ITEMCHANGEDA, AFX_IDW_PANE_FIRST, OnChangeHeader)
ON_NOTIFY(HDN_ENDDRAG, AFX_IDW_PANE_FIRST, OnChangeHeader)
ON_WM_KEYDOWN()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
ON_WM_LBUTTONDBLCLK()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_RBUTTONUP()
ON_WM_SETFOCUS()
ON_WM_KILLFOCUS()
END_MESSAGE_MAP()
#define HEADER_HEIGHT 20
#define ITEM_HEIGHT 17
#define UPLOAD_COLUMN_TITLE 0
#define UPLOAD_COLUMN_USER 1
#define UPLOAD_COLUMN_SIZE 2
#define UPLOAD_COLUMN_PROGRESS 3
#define UPLOAD_COLUMN_SPEED 4
#define UPLOAD_COLUMN_CLIENT 5
//////////////////////////////////////////////////////////////////////////////
// CUploadsCtrl construction
CUploadsCtrl::CUploadsCtrl()
{
}
CUploadsCtrl::~CUploadsCtrl()
{
}
//////////////////////////////////////////////////////////////////////////////
// CUploadsCtrl operations
BOOL CUploadsCtrl::Create(CWnd* pParentWnd, UINT nID)
{
CRect rect( 0, 0, 0, 0 );
return CWnd::Create( NULL, NULL, WS_CHILD|WS_CLIPSIBLINGS, rect, pParentWnd, nID, NULL );
}
BOOL CUploadsCtrl::Update()
{
OnSize( 1982, 0, 0 );
return TRUE;
}
//////////////////////////////////////////////////////////////////////////////
// CUploadsCtrl system message handlers
int CUploadsCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if ( CWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
CRect rect( 0, 0, 0, 0 );
m_wndHeader.Create( WS_CHILD|HDS_DRAGDROP|HDS_HOTTRACK|HDS_FULLDRAG, rect, this, AFX_IDW_PANE_FIRST );
m_wndHeader.SetFont( &theApp.m_gdiFont );
m_wndTip.Create( this, &Settings.Interface.TipUploads );
InsertColumn( UPLOAD_COLUMN_TITLE, _T("Uploaded File"), LVCFMT_LEFT, 210 );
InsertColumn( UPLOAD_COLUMN_USER, _T("Remote User"), LVCFMT_LEFT, 100 );
InsertColumn( UPLOAD_COLUMN_SIZE, _T("Size"), LVCFMT_CENTER, 80 );
InsertColumn( UPLOAD_COLUMN_PROGRESS, _T("Progress"), LVCFMT_CENTER, 130 );
InsertColumn( UPLOAD_COLUMN_SPEED, _T("Speed"), LVCFMT_CENTER, 80 );
InsertColumn( UPLOAD_COLUMN_CLIENT, _T("Client"), LVCFMT_CENTER, 100 );
Skin.Translate( _T("CUploadCtrl"), &m_wndHeader );
LoadColumnState();
CBitmap bmImages;
bmImages.LoadBitmap( IDB_PROTOCOLS );
m_pProtocols.Create( 16, 16, ILC_COLOR16|ILC_MASK, 7, 1 );
m_pProtocols.Add( &bmImages, RGB( 0, 255, 0 ) );
m_nFocus = 0;
m_pDeselect = NULL;
return 0;
}
void CUploadsCtrl::OnDestroy()
{
SaveColumnState();
CWnd::OnDestroy();
}
//////////////////////////////////////////////////////////////////////////////
// CUploadsCtrl column helpers
void CUploadsCtrl::InsertColumn(int nColumn, LPCTSTR pszCaption, int nFormat, int nWidth)
{
HDITEM pColumn;
ZeroMemory( &pColumn, sizeof(pColumn) );
pColumn.mask = HDI_FORMAT | HDI_LPARAM | HDI_TEXT | HDI_WIDTH;
pColumn.cxy = nWidth;
pColumn.pszText = (LPTSTR)pszCaption;
pColumn.fmt = nFormat;
pColumn.lParam = nColumn;
m_wndHeader.InsertItem( m_wndHeader.GetItemCount(), &pColumn );
}
void CUploadsCtrl::SaveColumnState()
{
HDITEM pItem = { HDI_WIDTH|HDI_ORDER };
CString strOrdering, strWidths, strItem;
for ( int nColumns = 0 ; m_wndHeader.GetItem( nColumns, &pItem ) ; nColumns++ )
{
m_wndHeader.GetItem( nColumns, &pItem );
strItem.Format( _T("%.2x"), pItem.iOrder );
strOrdering += strItem;
strItem.Format( _T("%.4x"), pItem.cxy );
strWidths += strItem;
}
theApp.WriteProfileString( _T("ListStates"), _T("CUploadCtrl.Ordering"), strOrdering );
theApp.WriteProfileString( _T("ListStates"), _T("CUploadCtrl.Widths"), strWidths );
}
BOOL CUploadsCtrl::LoadColumnState()
{
CString strOrdering, strWidths, strItem;
strOrdering = theApp.GetProfileString( _T("ListStates"), _T("CUploadCtrl.Ordering"), _T("") );
strWidths = theApp.GetProfileString( _T("ListStates"), _T("CUploadCtrl.Widths"), _T("") );
HDITEM pItem = { HDI_WIDTH|HDI_ORDER };
if ( _tcsncmp( strWidths, _T("0000"), 4 ) == 0 &&
_tcsncmp( strOrdering, _T("00"), 2 ) == 0 )
{
strWidths = strWidths.Mid( 4 );
strOrdering = strOrdering.Mid( 2 );
}
for ( int nColumns = 0 ; m_wndHeader.GetItem( nColumns, &pItem ) ; nColumns++ )
{
if ( strWidths.GetLength() < 4 || strOrdering.GetLength() < 2 ) return FALSE;
_stscanf( strWidths.Left( 4 ), _T("%x"), &pItem.cxy );
_stscanf( strOrdering.Left( 2 ), _T("%x"), &pItem.iOrder );
strWidths = strWidths.Mid( 4 );
strOrdering = strOrdering.Mid( 2 );
m_wndHeader.SetItem( nColumns, &pItem );
}
return TRUE;
}
//////////////////////////////////////////////////////////////////////////////
// CUploadsCtrl item helpers
void CUploadsCtrl::SelectTo(int nIndex)
{
CSingleLock pLock( &Transfers.m_pSection, TRUE );
BOOL bShift = GetAsyncKeyState( VK_SHIFT ) & 0x8000;
BOOL bControl = GetAsyncKeyState( VK_CONTROL ) & 0x8000;
BOOL bRight = GetAsyncKeyState( VK_RBUTTON ) & 0x8000;
if ( ! bShift && ! bControl && ! bRight && m_pDeselect == NULL ) DeselectAll();
Update();
INT nMin, nMax;
GetScrollRange( SB_VERT, &nMin, &nMax );
nIndex = max( 0, min( nIndex, nMax - 1 ) );
CUploadFile* pFile;
CUploadQueue* pQueue;
if ( bShift )
{
if ( m_nFocus < nIndex )
{
for ( m_nFocus ++ ; m_nFocus <= nIndex ; m_nFocus ++ )
{
GetAt( m_nFocus, &pQueue, &pFile );
if ( pQueue != NULL ) pQueue->m_bSelected = TRUE;
if ( pFile != NULL ) pFile->m_bSelected = TRUE;
}
}
else if ( m_nFocus > nIndex )
{
for ( m_nFocus -- ; m_nFocus >= nIndex ; m_nFocus -- )
{
GetAt( m_nFocus, &pQueue, &pFile );
if ( pQueue != NULL ) pQueue->m_bSelected = TRUE;
if ( pFile != NULL ) pFile->m_bSelected = TRUE;
}
}
m_nFocus = nIndex;
}
else
{
m_nFocus = nIndex;
GetAt( m_nFocus, &pQueue, &pFile );
if ( bControl )
{
if ( pQueue != NULL ) pQueue->m_bSelected = ! pQueue->m_bSelected;
if ( pFile != NULL ) pFile->m_bSelected = ! pFile->m_bSelected;
}
else
{
if ( pQueue != NULL ) pQueue->m_bSelected = TRUE;
if ( pFile != NULL ) pFile->m_bSelected = TRUE;
}
}
CRect rcClient;
GetClientRect( &rcClient );
int nScroll = GetScrollPos( SB_VERT );
int nHeight = ( rcClient.bottom - HEADER_HEIGHT ) / ITEM_HEIGHT - 1;
nHeight = max( 0, nHeight );
if ( m_nFocus < nScroll )
{
SetScrollPos( SB_VERT, m_nFocus );
Update();
}
else if ( m_nFocus > nScroll + nHeight )
{
SetScrollPos( SB_VERT, max( 0, m_nFocus - nHeight ) );
Update();
}
else
{
Invalidate();
}
}
void CUploadsCtrl::DeselectAll(CUploadFile* pExcept)
{
CSingleLock pLock( &Transfers.m_pSection, TRUE );
POSITION pos;
UploadQueues.m_pTorrentQueue->m_bSelected = FALSE;
UploadQueues.m_pHistoryQueue->m_bSelected = FALSE;
for ( pos = UploadQueues.GetIterator() ; pos ; )
{
CUploadQueue* pQueue = UploadQueues.GetNext( pos );
pQueue->m_bSelected = FALSE;
}
for ( pos = UploadFiles.GetIterator() ; pos ; )
{
CUploadFile* pFile = UploadFiles.GetNext( pos );
pFile->m_bSelected = FALSE;
}
Invalidate();
}
BOOL CUploadsCtrl::HitTest(const CPoint& point, CUploadQueue** ppQueue, CUploadFile** ppFile, int* pnIndex, RECT* prcItem)
{
CRect rcClient, rcItem;
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;
if ( ppQueue != NULL ) *ppQueue = NULL;
if ( ppFile != NULL ) *ppFile = NULL;
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
{
if ( rcItem.PtInRect( point ) )
{
if ( ppQueue != NULL ) *ppQueue = pQueue;
if ( pnIndex != NULL ) *pnIndex = nIndex;
if ( prcItem != NULL ) *prcItem = rcItem;
return TRUE;
}
rcItem.OffsetRect( 0, ITEM_HEIGHT );
}
nIndex ++;
if ( ! pQueue->m_bExpanded ) continue;
while ( posFile && rcItem.top < rcClient.bottom )
{
CUploadFile* pFile = GetNextFile( pQueue, posFile );
if ( pFile == NULL ) continue;
if ( nScroll > 0 )
{
nScroll --;
}
else
{
if ( rcItem.PtInRect( point ) )
{
if ( ppFile != NULL ) *ppFile = pFile;
if ( pnIndex != NULL ) *pnIndex = nIndex;
if ( prcItem != NULL ) *prcItem = rcItem;
return TRUE;
}
rcItem.OffsetRect( 0, ITEM_HEIGHT );
}
nIndex ++;
}
}
return FALSE;
}
BOOL CUploadsCtrl::GetAt(int nSelect, CUploadQueue** ppQueue, CUploadFile** ppFile)
{
int nScroll = GetScrollPos( SB_VERT );
int nIndex = 0;
if ( ppQueue != NULL ) *ppQueue = NULL;
if ( ppFile != NULL ) *ppFile = NULL;
for ( POSITION posQueue = GetQueueIterator() ; posQueue ; )
{
CUploadQueue* pQueue = GetNextQueue( posQueue );
POSITION posFile = GetFileIterator( pQueue );
if ( posFile == NULL ) continue;
if ( nIndex++ == nSelect )
{
if ( ppQueue != NULL ) *ppQueue = pQueue;
return TRUE;
}
if ( ! pQueue->m_bExpanded ) continue;
while ( posFile )
{
CUploadFile* pFile = GetNextFile( pQueue, posFile );
if ( pFile == NULL ) continue;
if ( nIndex++ == nSelect )
{
if ( ppFile != NULL ) *ppFile = pFile;
return TRUE;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -