00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Library.h"
00025 #include "LibraryBuilder.h"
00026 #include "CoolInterface.h"
00027 #include "WndHashProgressBar.h"
00028 #include "Settings.h"
00029
00030 #ifdef _DEBUG
00031 #define new DEBUG_NEW
00032 #undef THIS_FILE
00033 static char THIS_FILE[] = __FILE__;
00034 #endif
00035
00036 BEGIN_MESSAGE_MAP(CHashProgressBar, CWnd)
00037
00038 ON_WM_CREATE()
00039 ON_WM_ERASEBKGND()
00040 ON_WM_PAINT()
00041 ON_WM_LBUTTONDOWN()
00042
00043 END_MESSAGE_MAP()
00044
00045 #define WINDOW_WIDTH 320
00046 #define WINDOW_HEIGHT 60
00047 #define DISPLAY_THRESHOLD 5
00048
00049
00051
00052
00053 CHashProgressBar::CHashProgressBar()
00054 {
00055 m_pParent = NULL;
00056 m_hIcon = NULL;
00057 m_nRemaining = 0;
00058 m_nFlash = 0;
00059
00060 m_nRemaining = 0;
00061 m_nTotal = 0;
00062 m_sCurrent.Empty();
00063 m_sPrevious.Empty();
00064 }
00065
00066 CHashProgressBar::~CHashProgressBar()
00067 {
00068 }
00069
00071
00072
00073 void CHashProgressBar::Create(CWnd* pParent)
00074 {
00075 m_pParent = pParent;
00076 }
00077
00078 void CHashProgressBar::Run()
00079 {
00080 if ( Settings.Library.HashWindow )
00081 {
00082
00083 m_nTotal = LibraryMaps.GetFileCount();
00084 LibraryBuilder.UpdateStatus( &m_sCurrent, &m_nRemaining );
00085
00086 int nPos = m_sCurrent.ReverseFind( '\\' );
00087 if ( nPos > 0 ) m_sCurrent = m_sCurrent.Mid( nPos + 1 );
00088
00089 BOOL bShow = Settings.Library.HashWindow;
00090
00091 if ( m_hWnd == NULL )
00092 {
00093 if ( m_nRemaining > DISPLAY_THRESHOLD )
00094 {
00095 LPCTSTR hClass = AfxRegisterWndClass( 0 );
00096 CreateEx( WS_EX_TOPMOST|WS_EX_TOOLWINDOW, hClass, _T("Shareaza Hashing..."),
00097 WS_POPUP , 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT,
00098 NULL, 0 );
00099 bShow = TRUE;
00100 }
00101 }
00102 else if ( m_nRemaining <= 0 )
00103 {
00104 DestroyWindow();
00105 }
00106
00107 if ( m_hWnd != NULL )
00108 {
00109 Update();
00110 Show( WINDOW_WIDTH, TRUE );
00111 }
00112 }
00113 else
00114 {
00115 if ( m_hWnd != NULL ) DestroyWindow();
00116 }
00117 }
00118
00119 void CHashProgressBar::Update()
00120 {
00121 if ( m_sCurrent != m_sPrevious )
00122 {
00123 m_sPrevious = m_sCurrent;
00124
00125 CClientDC dc( this );
00126 CFont* pOld = (CFont*)dc.SelectObject( &CoolInterface.m_fntCaption );
00127 CSize sz = dc.GetTextExtent( m_sCurrent );
00128 dc.SelectObject( pOld );
00129
00130 int nWidth = sz.cx + 4 + 48 + 8 + 16;
00131 nWidth = max( nWidth, WINDOW_WIDTH );
00132 nWidth = min( nWidth, GetSystemMetrics( SM_CXSCREEN ) );
00133
00134
00135
00136
00137
00138
00139 Show( nWidth, FALSE );
00140 }
00141
00142 Invalidate();
00143 }
00144
00145 void CHashProgressBar::Show(int nWidth, BOOL bShow)
00146 {
00147 CRect rc;
00148 SystemParametersInfo( SPI_GETWORKAREA, 0, &rc, 0 );
00149 rc.left = rc.right - nWidth;
00150 rc.top = rc.bottom - WINDOW_HEIGHT;
00151 SetWindowPos( bShow ? &wndTopMost : NULL, rc.left, rc.top, rc.Width(), rc.Height(),
00152 ( bShow ? SWP_SHOWWINDOW : SWP_NOZORDER ) | SWP_NOACTIVATE );
00153 }
00154
00156
00157
00158 int CHashProgressBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
00159 {
00160 if ( CWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00161
00162 m_hIcon = (HICON)LoadImage( AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_SEARCH_FOLDER),
00163 IMAGE_ICON, 48, 48, 0 );
00164
00165 if ( m_hIcon == NULL )
00166 {
00167 m_hIcon = (HICON)LoadImage( AfxGetResourceHandle(),
00168 MAKEINTRESOURCE(IDI_SEARCH_FOLDER), IMAGE_ICON, 32, 32, 0 );
00169 }
00170
00171 m_crFill = GetSysColor( COLOR_ACTIVECAPTION );
00172 m_crBorder = CCoolInterface::CalculateColour( m_crFill, 0xFFFFFFFF, 128 );
00173 m_crText = CCoolInterface::CalculateColour( m_crFill, 0xFFFFFFFF, 220 );
00174
00175 if ( m_brFill.m_hObject != NULL ) m_brFill.DeleteObject();
00176 m_brFill.CreateSolidBrush( m_crFill );
00177
00178 return 0;
00179 }
00180
00181 BOOL CHashProgressBar::OnEraseBkgnd(CDC* pDC)
00182 {
00183 return TRUE;
00184 }
00185
00186 void CHashProgressBar::OnPaint()
00187 {
00188 CRect rcClient, rcText;
00189 CPaintDC dc( this );
00190
00191 GetClientRect( &rcClient );
00192
00193 dc.Draw3dRect( &rcClient, m_crBorder, m_crBorder );
00194 rcClient.DeflateRect( 1, 1 );
00195
00196 dc.SetBkMode( OPAQUE );
00197 dc.SetBkColor( m_crFill );
00198 dc.SetTextColor( ( m_nFlash++ & 1 ) ? RGB( 255, 255, 0 ) : m_crText );
00199
00200
00201 DrawIconEx( dc, rcClient.left + 4, rcClient.top + 4,
00202 m_hIcon, 48, 48, 0, m_brFill, DI_NORMAL );
00203 dc.ExcludeClipRect( rcClient.left + 4, rcClient.top + 4,
00204 rcClient.left + 4 + 48, rcClient.top + 4 + 48 );
00205
00206
00207 CFont* pOld = dc.GetCurrentFont();
00208 CString strText, strFormat;
00209 CSize sz;
00210
00211 LoadString( strFormat, IDS_HASH_MESSAGE );
00212 strText.Format( strFormat, m_nRemaining );
00213
00214 dc.SelectObject( &CoolInterface.m_fntNormal );
00215 sz = dc.GetTextExtent( strText );
00216 rcText.SetRect( 4 + 48 + 8, 12, 4 + 48 + 8 + sz.cx, 12 + sz.cy );
00217 rcText.OffsetRect( rcClient.left, rcClient.top );
00218 dc.ExtTextOut( rcText.left, rcText.top, ETO_OPAQUE|ETO_CLIPPED,
00219 &rcText, strText, NULL );
00220 dc.ExcludeClipRect( rcText.left, rcText.top, rcText.right, rcText.bottom );
00221
00222 dc.SelectObject( &CoolInterface.m_fntCaption );
00223 sz = dc.GetTextExtent( m_sCurrent );
00224 dc.ExtTextOut( rcText.left, rcClient.top + 4 + 48 - sz.cy - 8,
00225 ETO_OPAQUE|ETO_CLIPPED, &rcClient, m_sCurrent, NULL );
00226
00227 dc.SelectObject( pOld );
00228
00229
00230 CRect rcProgress = rcClient;
00231 rcProgress.DeflateRect( 1, 1 );
00232 rcProgress.top = rcProgress.bottom - 3;
00233 float nPercentage = (float)( m_nTotal - m_nRemaining );
00234 nPercentage /= m_nTotal;
00235 if ( ( nPercentage < 0 ) || ( nPercentage > 1 ) ) nPercentage = 1;
00236 rcProgress.right = rcProgress.left + (LONG)( rcProgress.Width() * nPercentage );
00237 dc.Draw3dRect( &rcProgress, m_crText, m_crText );
00238 }
00239
00240 void CHashProgressBar::OnLButtonDown(UINT nFlags, CPoint point)
00241 {
00242 Settings.Library.HashWindow = FALSE;
00243 ShowWindow( SW_HIDE );
00244 }