📄 wndmonitor.cpp
字号:
//
// WndMonitor.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 "GraphItem.h"
#include "CoolInterface.h"
#include "SkinWindow.h"
#include "Skin.h"
#include "WndMonitor.h"
#include "CtrlMonitorBar.h"
#include "CtrlMediaFrame.h"
IMPLEMENT_DYNAMIC(CRemoteWnd, CWnd)
BEGIN_MESSAGE_MAP(CRemoteWnd, CWnd)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_WINDOWPOSCHANGING()
ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)
ON_WM_TIMER()
ON_WM_SIZE()
ON_WM_PAINT()
ON_WM_NCPAINT()
ON_WM_NCACTIVATE()
ON_WM_NCCALCSIZE()
ON_WM_NCHITTEST()
ON_WM_SETCURSOR()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_NCLBUTTONDBLCLK()
ON_WM_RBUTTONDOWN()
END_MESSAGE_MAP()
LPCTSTR CRemoteWnd::m_hClass = NULL;
#define SNAP_PIXELS 6
/////////////////////////////////////////////////////////////////////////////
// CRemoteWnd construction
CRemoteWnd::CRemoteWnd()
{
if ( m_hClass == NULL ) m_hClass = AfxRegisterWndClass( 0 );
m_pMonitor = NULL;
m_pSkin = NULL;
m_pCmdHover = NULL;
m_pCmdDown = NULL;
m_nTimer = 0;
m_bScaler = FALSE;
m_bMediaSeek = FALSE;
m_nMediaSeek = -1;
m_bMediaVol = FALSE;
m_nMediaVol = -1;
}
CRemoteWnd::~CRemoteWnd()
{
for ( POSITION pos = m_pButtons.GetHeadPosition() ; pos ; ) delete m_pButtons.GetNext( pos );
}
/////////////////////////////////////////////////////////////////////////////
// CRemoteWnd system message handlers
BOOL CRemoteWnd::Create(CMonitorBarCtrl* pMonitor)
{
ASSERT( m_hWnd == NULL );
m_pMonitor = pMonitor;
m_pSkin = NULL;
return CreateEx( WS_EX_TOOLWINDOW, m_hClass, _T("Shareaza Remote"),
WS_OVERLAPPED|WS_CLIPCHILDREN, 0, 0, 0, 0, NULL, 0 );
}
BOOL CRemoteWnd::IsVisible()
{
return ( m_hWnd != NULL );
}
int CRemoteWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if ( CWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
OnSkinChange();
EnableToolTips();
int nWindowX = AfxGetApp()->GetProfileInt( _T("Windows"), _T("CRemoteWnd.Left"), 0 );
int nWindowY = AfxGetApp()->GetProfileInt( _T("Windows"), _T("CRemoteWnd.Top"), 0 );
SetWindowPos( &wndTopMost, nWindowX, nWindowY, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW );
SetTimer( 1, 50, NULL );
return 0;
}
void CRemoteWnd::OnDestroy()
{
KillTimer( 1 );
Settings.SaveWindow( NULL, this );
CWnd::OnDestroy();
}
/////////////////////////////////////////////////////////////////////////////
// CRemoteWnd window movement message handlers
void CRemoteWnd::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
CWnd::OnWindowPosChanging( lpwndpos );
CRect rcWork;
SystemParametersInfo( SPI_GETWORKAREA, 0, &rcWork, 0 );
if ( abs( lpwndpos->x ) <= ( rcWork.left + SNAP_PIXELS ) )
{
lpwndpos->x = rcWork.left;
}
else if ( ( lpwndpos->x + lpwndpos->cx ) >= ( rcWork.right - SNAP_PIXELS ) &&
( lpwndpos->x + lpwndpos->cx ) <= ( rcWork.right + SNAP_PIXELS ) )
{
lpwndpos->x = rcWork.right - lpwndpos->cx;
}
if ( abs( lpwndpos->y ) <= ( rcWork.top + SNAP_PIXELS ) )
{
lpwndpos->y = rcWork.top;
}
else if ( ( lpwndpos->y + lpwndpos->cy ) >= ( rcWork.bottom - SNAP_PIXELS) &&
( lpwndpos->y + lpwndpos->cy ) <= ( rcWork.bottom + SNAP_PIXELS ) )
{
lpwndpos->y = rcWork.bottom - lpwndpos->cy;
}
}
/////////////////////////////////////////////////////////////////////////////
// CRemoteWnd command UI
LONG CRemoteWnd::OnIdleUpdateCmdUI(WPARAM wParam, LPARAM lParam)
{
UpdateCmdButtons();
return 0;
}
void CRemoteWnd::OnTimer(UINT nIDEvent)
{
if ( m_nTimer++ >= 10 )
{
m_nTimer = 0;
UpdateCmdButtons();
if ( m_pCmdHover != NULL )
{
CPoint point;
GetCursorPos( &point );
ScreenToClient( &point );
if ( HitTestButtons( point ) != m_pCmdHover ) m_pCmdHover = NULL;
}
CString strFormat;
LoadString( strFormat, IDS_TRAY_TIP );
m_sStatus.Format( strFormat,
(int)CGraphItem::GetValue( GRC_GNUTELLA_CONNECTIONS, 0 ),
(LPCTSTR)Settings.SmartVolume( CGraphItem::GetValue( GRC_TOTAL_BANDWIDTH_IN ), FALSE, TRUE ),
(LPCTSTR)Settings.SmartVolume( CGraphItem::GetValue( GRC_TOTAL_BANDWIDTH_OUT ), FALSE, TRUE ),
(int)CGraphItem::GetValue( GRC_DOWNLOADS_TRANSFERS ),
(int)CGraphItem::GetValue( GRC_UPLOADS_TRANSFERS ) );
}
Invalidate();
}
/////////////////////////////////////////////////////////////////////////////
// CRemoteWnd command buttons
CRemoteWnd::CmdButton* CRemoteWnd::HitTestButtons(const CPoint& ptIn, BOOL bAll) const
{
if ( m_pSkin == NULL ) return NULL;
for ( POSITION pos = m_pButtons.GetHeadPosition() ; pos ; )
{
CmdButton* pButton = m_pButtons.GetNext( pos );
if ( pButton->HitTest( ptIn, bAll ) ) return pButton;
}
return NULL;
}
void CRemoteWnd::UpdateCmdButtons()
{
BOOL bChanged = FALSE;
for ( POSITION pos = m_pButtons.GetHeadPosition() ; pos ; )
{
CmdButton* pButton = m_pButtons.GetNext( pos );
pButton->m_bChanged = FALSE;
pButton->DoUpdate( (CCmdTarget*)AfxGetMainWnd(), TRUE );
bChanged |= pButton->m_bChanged;
}
if ( bChanged ) Invalidate();
}
/////////////////////////////////////////////////////////////////////////////
// CRemoteWnd skin change handler
void CRemoteWnd::OnSkinChange()
{
for ( POSITION pos = m_pButtons.GetHeadPosition() ; pos ; ) delete m_pButtons.GetNext( pos );
m_pCmdHover = m_pCmdDown = NULL;
m_pButtons.RemoveAll();
m_pSkin = NULL;
if ( m_hWnd == NULL ) return;
m_pSkin = Skin.GetWindowSkin( _T("CRemoteWnd") );
if ( m_pSkin == NULL )
{
ShowWindow( SW_HIDE );
return;
}
if ( ! m_pSkin->GetPart( _T("Background"), m_rcBackground ) )
{
m_pSkin = NULL;
ShowWindow( SW_HIDE );
return;
}
for ( pos = m_pSkin->m_pAnchorList.GetStartPosition() ; pos ; )
{
CRect* prcAnchor;
CString strAnchor;
m_pSkin->m_pAnchorList.GetNextAssoc( pos, strAnchor, (void*&)prcAnchor );
if ( strAnchor.Find( '_' ) == 0 )
{
m_pButtons.AddTail( new CmdButton( strAnchor ) );
}
}
m_bsStatusText = m_pSkin->GetAnchor( _T("StatusText"), m_rcsStatusText );
m_bsHistoryDest = m_pSkin->GetAnchor( _T("History"), m_rcsHistoryDest );
m_bsHistoryTx[0] = m_pSkin->GetPart( _T("HistoryTx1"), m_rcsHistoryTx[0] );
m_bsHistoryTx[1] = m_pSkin->GetPart( _T("HistoryTx2"), m_rcsHistoryTx[1] );
m_bsHistoryRx[0] = m_pSkin->GetPart( _T("HistoryRx1"), m_rcsHistoryRx[0] );
m_bsHistoryRx[1] = m_pSkin->GetPart( _T("HistoryRx2"), m_rcsHistoryRx[1] );
m_bsFlowTxDest = m_pSkin->GetAnchor( _T("FlowTx"), m_rcsFlowTxDest );
m_bsFlowTxSrc[0] = m_pSkin->GetPart( _T("FlowTx1"), m_rcsFlowTxSrc[0] );
m_bsFlowTxSrc[1] = m_pSkin->GetPart( _T("FlowTx2"), m_rcsFlowTxSrc[1] );
m_bsFlowRxDest = m_pSkin->GetAnchor( _T("FlowRx"), m_rcsFlowRxDest );
m_bsFlowRxSrc[0] = m_pSkin->GetPart( _T("FlowRx1"), m_rcsFlowRxSrc[0] );
m_bsFlowRxSrc[1] = m_pSkin->GetPart( _T("FlowRx2"), m_rcsFlowRxSrc[1] );
m_bsScalerTrack = m_pSkin->GetAnchor( _T("ScalerTrack"), m_rcsScalerTrack );
m_bsScalerTab = m_pSkin->GetPart( _T("ScalerTab"), m_rcsScalerTab );
m_bsScalerBar = m_pSkin->GetPart( _T("ScalerBar"), m_rcsScalerBar );
m_bsMediaSeekTrack = m_pSkin->GetAnchor( _T("MediaSeekTrack"), m_rcsMediaSeekTrack );
m_bsMediaSeekTab = m_pSkin->GetPart( _T("MediaSeekTab"), m_rcsMediaSeekTab );
m_bsMediaSeekBar = m_pSkin->GetPart( _T("MediaSeekBar"), m_rcsMediaSeekBar );
m_bsMediaVolTrack = m_pSkin->GetAnchor( _T("MediaVolTrack"), m_rcsMediaVolTrack );
m_bsMediaVolTab = m_pSkin->GetPart( _T("MediaVolTab"), m_rcsMediaVolTab );
m_bsMediaVolBar = m_pSkin->GetPart( _T("MediaVolBar"), m_rcsMediaVolBar );
m_bsMediaStates[0][0] = m_pSkin->GetAnchor( _T("MediaStateStopped"), m_rcsMediaStates[0][0] );
m_bsMediaStates[0][1] = m_pSkin->GetAnchor( _T("MediaStatePlaying"), m_rcsMediaStates[0][1] );
m_bsMediaStates[0][2] = m_pSkin->GetAnchor( _T("MediaStatePaused"), m_rcsMediaStates[0][2] );
m_bsMediaStates[1][0] = m_pSkin->GetPart( _T("MediaStateStopped"), m_rcsMediaStates[1][0] );
m_bsMediaStates[1][1] = m_pSkin->GetPart( _T("MediaStatePlaying"), m_rcsMediaStates[1][1] );
m_bsMediaStates[1][2] = m_pSkin->GetPart( _T("MediaStatePaused"), m_rcsMediaStates[1][2] );
SetWindowPos( NULL, 0, 0, m_rcBackground.Width(), m_rcBackground.Height(), SWP_NOMOVE );
m_pSkin->OnSize( this );
Invalidate();
}
/////////////////////////////////////////////////////////////////////////////
// CRemoteWnd display message handlers
void CRemoteWnd::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize( nType, cx, cy );
if ( m_pSkin != NULL ) m_pSkin->OnSize( this );
Invalidate();
}
void CRemoteWnd::OnPaint()
{
CPaintDC dc( this );
CRect rcClient;
GetClientRect( &rcClient );
if ( m_pSkin == NULL )
{
dc.FillSolidRect( &rcClient, GetSysColor( COLOR_BTNFACE ) );
return;
}
CDC* pDC = CoolInterface.GetBuffer( dc, rcClient.Size() );
m_pSkin->Prepare( &dc );
pDC->BitBlt( 0, 0, m_rcBackground.Width(), m_rcBackground.Height(),
&m_pSkin->m_dcSkin, m_rcBackground.left, m_rcBackground.top, SRCCOPY );
CFont* pfOld = NULL;
if ( m_pSkin->m_fnCaption.m_hObject != NULL )
{
pfOld = (CFont*)pDC->SelectObject( &m_pSkin->m_fnCaption );
pDC->SetTextColor( m_pSkin->m_crCaptionText );
}
else
{
pfOld = (CFont*)pDC->SelectObject( &CoolInterface.m_fntNormal );
pDC->SetTextColor( RGB( 255, 255, 255 ) );
}
pDC->SetBkMode( TRANSPARENT );
m_bStatus = FALSE;
PaintHistory( pDC, m_pMonitor->m_pTxItem, m_pMonitor->m_pRxItem, m_pMonitor->m_nMaximum );
PaintFlow( pDC, &m_bsFlowTxDest, &m_rcsFlowTxDest, m_bsFlowTxSrc, m_rcsFlowTxSrc, m_pMonitor->m_pTxItem, m_pMonitor->m_nMaximum );
PaintFlow( pDC, &m_bsFlowRxDest, &m_rcsFlowRxDest, m_bsFlowRxSrc, m_rcsFlowRxSrc, m_pMonitor->m_pRxItem, m_pMonitor->m_nMaximum );
PaintScaler( pDC );
PaintMedia( pDC );
PaintStatus( pDC );
for ( POSITION pos = m_pButtons.GetHeadPosition() ; pos ; )
{
m_pButtons.GetNext( pos )->Paint( pDC, rcClient, m_pSkin, m_pCmdHover, m_pCmdDown );
}
pDC->SelectObject( pfOld );
pDC->SelectClipRgn( NULL );
dc.BitBlt( 0, 0, rcClient.Width(), rcClient.Height(), pDC, 0, 0, SRCCOPY );
}
void CRemoteWnd::OnNcPaint()
{
}
BOOL CRemoteWnd::OnNcActivate(BOOL bActive)
{
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CRemoteWnd paint monitor functionality
void CRemoteWnd::PaintHistory(CDC* pDC, CGraphItem* pTxItem, CGraphItem* pRxItem, DWORD nMaximum)
{
if ( nMaximum == 0 ) return;
if ( m_bsHistoryDest == FALSE ) return;
pTxItem->SetHistory( m_rcsHistoryDest.Width(), TRUE );
pRxItem->SetHistory( m_rcsHistoryDest.Width(), TRUE );
DWORD nMax = min( pTxItem->m_nLength, (DWORD)m_rcsHistoryDest.Width() );
int nX = m_rcsHistoryDest.right - 1;
for ( DWORD nPos = 0 ; nPos < nMax ; nPos++, nX-- )
{
DWORD nTxValue = pTxItem->GetValueAt( nPos );
DWORD nRxValue = pRxItem->GetValueAt( nPos );
nTxValue = m_rcsHistoryDest.bottom - nTxValue * m_rcsHistoryDest.Height() / nMaximum;
nRxValue = m_rcsHistoryDest.bottom - nRxValue * m_rcsHistoryDest.Height() / nMaximum;
if ( nTxValue < nRxValue )
{
if ( nTxValue < (DWORD)m_rcsHistoryDest.bottom && m_bsHistoryTx[0] )
{
pDC->BitBlt( nX, nTxValue, 1, m_rcsHistoryDest.bottom - nTxValue,
&m_pSkin->m_dcSkin, m_rcsHistoryTx[0].left + ( nX - m_rcsHistoryDest.left ),
m_rcsHistoryTx[0].top + nTxValue - m_rcsHistoryDest.top, SRCCOPY );
}
else if ( nTxValue < (DWORD)m_rcsHistoryDest.bottom && m_bsHistoryTx[1] )
{
pDC->BitBlt( nX, nTxValue, 1, m_rcsHistoryDest.bottom - nTxValue,
&m_pSkin->m_dcSkin, m_rcsHistoryTx[1].left + ( nX - m_rcsHistoryDest.left ),
m_rcsHistoryTx[1].top, SRCCOPY );
}
if ( nRxValue < (DWORD)m_rcsHistoryDest.bottom && m_bsHistoryRx[0] )
{
pDC->BitBlt( nX, nRxValue, 1, m_rcsHistoryDest.bottom - nRxValue,
&m_pSkin->m_dcSkin, m_rcsHistoryRx[0].left + ( nX - m_rcsHistoryDest.left ),
m_rcsHistoryRx[0].top + nRxValue - m_rcsHistoryDest.top, SRCCOPY );
}
else if ( nRxValue < (DWORD)m_rcsHistoryDest.bottom && m_bsHistoryRx[1] )
{
pDC->BitBlt( nX, nRxValue, 1, m_rcsHistoryDest.bottom - nRxValue,
&m_pSkin->m_dcSkin, m_rcsHistoryRx[1].left + ( nX - m_rcsHistoryDest.left ),
m_rcsHistoryRx[1].top, SRCCOPY );
}
}
else
{
if ( nRxValue < (DWORD)m_rcsHistoryDest.bottom && m_bsHistoryRx[0] )
{
pDC->BitBlt( nX, nRxValue, 1, m_rcsHistoryDest.bottom - nRxValue,
&m_pSkin->m_dcSkin, m_rcsHistoryRx[0].left + ( nX - m_rcsHistoryDest.left ),
m_rcsHistoryRx[0].top + nRxValue - m_rcsHistoryDest.top, SRCCOPY );
}
else if ( nRxValue < (DWORD)m_rcsHistoryDest.bottom && m_bsHistoryRx[1] )
{
pDC->BitBlt( nX, nRxValue, 1, m_rcsHistoryDest.bottom - nRxValue,
&m_pSkin->m_dcSkin, m_rcsHistoryRx[1].left + ( nX - m_rcsHistoryDest.left ),
m_rcsHistoryRx[1].top, SRCCOPY );
}
if ( nTxValue < (DWORD)m_rcsHistoryDest.bottom && m_bsHistoryTx[0] )
{
pDC->BitBlt( nX, nTxValue, 1, m_rcsHistoryDest.bottom - nTxValue,
&m_pSkin->m_dcSkin, m_rcsHistoryTx[0].left + ( nX - m_rcsHistoryDest.left ),
m_rcsHistoryTx[0].top + nTxValue - m_rcsHistoryDest.top, SRCCOPY );
}
else if ( nTxValue < (DWORD)m_rcsHistoryDest.bottom && m_bsHistoryTx[1] )
{
pDC->BitBlt( nX, nTxValue, 1, m_rcsHistoryDest.bottom - nTxValue,
&m_pSkin->m_dcSkin, m_rcsHistoryTx[1].left + ( nX - m_rcsHistoryDest.left ),
m_rcsHistoryTx[1].top, SRCCOPY );
}
}
}
}
void CRemoteWnd::PaintFlow(CDC* pDC, BOOL* pbDest, CRect* prcDest, BOOL* pbSrc, CRect* prcSrc, CGraphItem* pItem, DWORD nMaximum)
{
if ( *pbDest == FALSE ) return;
if ( nMaximum == 0 || pItem->m_nLength < 1 ) return;
DWORD nValue = (DWORD)pItem->GetValue( pItem->m_nCode );
nValue = nValue * prcDest->Height() / nMaximum;
if ( pbSrc[0] )
{
pDC->BitBlt( prcDest->left, prcDest->bottom - nValue,
prcDest->Width(), nValue, &m_pSkin->m_dcSkin,
prcSrc[0].left, prcSrc[0].bottom - nValue, SRCCOPY );
}
else if ( pbSrc[1] )
{
pDC->BitBlt( prcDest->left, prcDest->bottom - nValue,
prcDest->Width(), nValue, &m_pSkin->m_dcSkin,
prcSrc[1].left, prcSrc[1].top, SRCCOPY );
}
}
/////////////////////////////////////////////////////////////////////////////
// CRemoteWnd paint bandwidth scaler
void CRemoteWnd::PaintScaler(CDC* pDC)
{
if ( m_bsScalerTrack )
{
CRect rcTrack( &m_rcsScalerTrack ), rcPart;
float nPosition = 0;
if ( Settings.Live.BandwidthScale > 100 )
nPosition = 1.0f;
else
nPosition = (float)Settings.Live.BandwidthScale / 105.0f;
if ( m_bsScalerTab )
{
rcPart.CopyRect( &m_rcsScalerTab );
if ( m_bScaler ) rcPart.OffsetRect( rcPart.Width(), 0 );
m_rcScalerTab.left = rcTrack.left + (int)( nPosition * ( rcTrack.Width() - rcPart.Width() ) );
m_rcScalerTab.right = m_rcScalerTab.left + rcPart.Width();
m_rcScalerTab.top = rcTrack.top;
m_rcScalerTab.bottom = rcTrack.top + rcPart.Height();
pDC->BitBlt( m_rcScalerTab.left, m_rcScalerTab.top, m_rcScalerTab.Width(),
m_rcScalerTab.Height(), &m_pSkin->m_dcSkin, rcPart.left, rcPart.top, SRCCOPY );
pDC->ExcludeClipRect( &m_rcScalerTab );
rcTrack.right = m_rcScalerTab.left;
}
if ( m_bsScalerBar )
{
rcPart.CopyRect( &m_rcsScalerBar );
CRect rcBar( &rcTrack );
while ( rcBar.left < rcBar.right )
{
pDC->BitBlt( rcBar.left, rcBar.top, min( rcBar.Width(), rcPart.Width() ),
rcPart.Height(), &m_pSkin->m_dcSkin, rcPart.left, rcPart.top, SRCCOPY );
rcBar.left += rcPart.Width();
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CRemoteWnd paint media functionality
void CRemoteWnd::PaintMedia(CDC* pDC)
{
if ( m_bsMediaSeekTrack )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -