Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

DlgDownloadMonitor.cpp

Go to the documentation of this file.
00001 //
00002 // DlgDownloadMonitor.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "Transfers.h"
00026 #include "Downloads.h"
00027 #include "Download.h"
00028 #include "FragmentedFile.h"
00029 #include "FragmentBar.h"
00030 #include "GraphLine.h"
00031 #include "GraphItem.h"
00032 #include "Library.h"
00033 #include "FileExecutor.h"
00034 #include "CoolInterface.h"
00035 #include "CoolMenu.h"
00036 #include "ShellIcons.h"
00037 #include "Plugins.h"
00038 #include "Skin.h"
00039 #include "DlgDownloadMonitor.h"
00040 #include "WndMain.h"
00041 #include "WndDownloads.h"
00042 
00043 #ifdef _DEBUG
00044 #define new DEBUG_NEW
00045 #undef THIS_FILE
00046 static char THIS_FILE[] = __FILE__;
00047 #endif
00048 
00049 BEGIN_MESSAGE_MAP(CDownloadMonitorDlg, CSkinDialog)
00050         //{{AFX_MSG_MAP(CDownloadMonitorDlg)
00051         ON_WM_PAINT()
00052         ON_BN_CLICKED(IDC_DOWNLOAD_CANCEL, OnDownloadCancel)
00053         ON_WM_DESTROY()
00054         ON_WM_TIMER()
00055         ON_BN_CLICKED(IDC_DOWNLOAD_LAUNCH, OnDownloadLaunch)
00056         ON_BN_CLICKED(IDC_DOWNLOAD_LIBRARY, OnDownloadLibrary)
00057         ON_BN_CLICKED(IDC_DOWNLOAD_STOP, OnDownloadStop)
00058         ON_WM_CLOSE()
00059         ON_WM_SYSCOMMAND()
00060         ON_WM_CTLCOLOR()
00061         ON_WM_CONTEXTMENU()
00062         ON_WM_INITMENUPOPUP()
00063         //}}AFX_MSG_MAP
00064         ON_MESSAGE(WM_TRAY, OnTray)
00065         ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnNeedText)
00066 END_MESSAGE_MAP()
00067 
00068 CPtrList CDownloadMonitorDlg::m_pWindows;
00069 
00070 
00072 // CDownloadMonitorDlg dialog
00073 
00074 CDownloadMonitorDlg::CDownloadMonitorDlg(CDownload* pDownload) : CSkinDialog( CDownloadMonitorDlg::IDD, NULL )
00075 {
00076         //{{AFX_DATA_INIT(CDownloadMonitorDlg)
00077         //}}AFX_DATA_INIT
00078         
00079         m_pDownload             = pDownload;
00080         m_pGraph                = NULL;
00081         m_bTray                 = FALSE;
00082         m_bCompleted    = FALSE;
00083         
00084         CreateReal( IDD );
00085         
00086         m_pWindows.AddTail( this );
00087 }
00088 
00089 CDownloadMonitorDlg::~CDownloadMonitorDlg()
00090 {
00091         if ( m_pGraph != NULL ) delete m_pGraph;
00092         if ( POSITION pos = m_pWindows.Find( this ) ) m_pWindows.RemoveAt( pos );
00093 }
00094  
00095 void CDownloadMonitorDlg::DoDataExchange(CDataExchange* pDX)
00096 {
00097         CSkinDialog::DoDataExchange( pDX );
00098         //{{AFX_DATA_MAP(CDownloadMonitorDlg)
00099         DDX_Control(pDX, IDC_DOWNLOAD_VOLUME, m_wndVolume);
00100         DDX_Control(pDX, IDC_DOWNLOAD_CANCEL, m_wndCancel);
00101         DDX_Control(pDX, IDC_DOWNLOAD_CLOSE, m_wndClose);
00102         DDX_Control(pDX, IDC_DOWNLOAD_STOP, m_wndStop);
00103         DDX_Control(pDX, IDC_PROGRESS, m_wndProgress);
00104         DDX_Control(pDX, IDC_DOWNLOAD_TIME, m_wndTime);
00105         DDX_Control(pDX, IDC_DOWNLOAD_STATUS, m_wndStatus);
00106         DDX_Control(pDX, IDC_DOWNLOAD_SPEED, m_wndSpeed);
00107         DDX_Control(pDX, IDC_DOWNLOAD_SOURCES, m_wndSources);
00108         DDX_Control(pDX, IDC_DOWNLOAD_LIBRARY, m_wndLibrary);
00109         DDX_Control(pDX, IDC_DOWNLOAD_LAUNCH, m_wndLaunch);
00110         DDX_Control(pDX, IDC_DOWNLOAD_ICON, m_wndIcon);
00111         DDX_Control(pDX, IDC_DOWNLOAD_GRAPH, m_wndGraph);
00112         DDX_Control(pDX, IDC_DOWNLOAD_FILE, m_wndFile);
00113         //}}AFX_DATA_MAP
00114 }
00115 
00117 // CDownloadMonitorDlg operations
00118 
00119 BOOL CDownloadMonitorDlg::CreateReal(UINT nID)
00120 {
00121         LPCTSTR lpszTemplateName = MAKEINTRESOURCE( nID );
00122 
00123         HINSTANCE hInst         = AfxFindResourceHandle( lpszTemplateName, RT_DIALOG );
00124         HRSRC hResource         = ::FindResource( hInst, lpszTemplateName, RT_DIALOG );
00125         HGLOBAL hTemplate       = LoadResource( hInst, hResource );
00126 
00127         LPCDLGTEMPLATE lpDialogTemplate = (LPCDLGTEMPLATE)LockResource( hTemplate );
00128 
00129         BOOL bResult = CreateDlgIndirect( lpDialogTemplate, NULL, hInst );
00130 
00131         UnlockResource( hTemplate );
00132 
00133         FreeResource( hTemplate );
00134 
00135         return bResult;
00136 }
00137 
00138 void CDownloadMonitorDlg::OnSkinChange(BOOL bSet)
00139 {
00140         for ( POSITION pos = m_pWindows.GetHeadPosition() ; pos ; )
00141         {
00142                 CDownloadMonitorDlg* pDlg = (CDownloadMonitorDlg*)m_pWindows.GetNext( pos );
00143 
00144                 if ( bSet )
00145                 {
00146                         pDlg->SkinMe( _T("CDownloadMonitorDlg"), IDI_DOWNLOAD_MONITOR );
00147                         pDlg->Invalidate();
00148                 }
00149                 else
00150                 {
00151                         pDlg->m_pSkin = NULL;
00152                 }
00153         }
00154 }
00155 
00156 void CDownloadMonitorDlg::CloseAll()
00157 {
00158         for ( POSITION pos = m_pWindows.GetHeadPosition() ; pos ; )
00159         {
00160                 delete (CDownloadMonitorDlg*)m_pWindows.GetNext( pos );
00161         }
00162         m_pWindows.RemoveAll();
00163 }
00164 
00166 // CDownloadMonitorDlg message handlers
00167 
00168 BOOL CDownloadMonitorDlg::OnInitDialog() 
00169 {
00170         CSkinDialog::OnInitDialog();
00171         
00172         SkinMe( _T("CDownloadMonitorDlg"), IDI_DOWNLOAD_MONITOR );
00173         
00174         CMenu* pMenu = GetSystemMenu( FALSE );
00175         pMenu->InsertMenu( 0, MF_BYPOSITION|MF_SEPARATOR, ID_SEPARATOR );
00176         pMenu->InsertMenu( 0, MF_BYPOSITION|MF_STRING, SC_NEXTWINDOW, _T("&Always on Top") );
00177         
00178         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00179         
00180         if ( Downloads.Check( m_pDownload ) )
00181         {
00182                 m_sName = m_pDownload->m_sRemoteName;
00183                 CString strType = m_sName;
00184 
00185                 int nPeriod = strType.ReverseFind( '.' );
00186 
00187                 if ( nPeriod > 0 )
00188                 {
00189                         strType = strType.Mid( nPeriod );
00190                         HICON hIcon;
00191 
00192                         if ( ShellIcons.Lookup( strType, NULL, &hIcon, NULL, NULL ) )
00193                                 m_wndIcon.SetIcon( theApp.m_bRTL ? CreateMirroredIcon( hIcon ) : hIcon );
00194                 }
00195 
00196                 m_wndFile.SetWindowText( m_sName );
00197         }
00198 
00199         pLock.Unlock();
00200 
00201         m_pGraph        = new CLineGraph();
00202         m_pItem         = new CGraphItem( 0, 0, RGB( 0xFF, 0, 0 ) );
00203 
00204         m_pGraph->m_bShowLegend         = FALSE;
00205         m_pGraph->m_bShowAxis           = FALSE;
00206         m_pGraph->m_crBack                      = RGB( 255, 255, 240 );
00207         m_pGraph->m_crGrid                      = RGB( 220, 220, 170 );
00208         m_pGraph->m_nMinGridVert        = 16;
00209 
00210         m_pGraph->AddItem( m_pItem );
00211 
00212         OnTimer( 1 );
00213 
00214         CenterWindow();
00215         ShowWindow( SW_SHOW );
00216 
00217         SetTimer( 1, 100, NULL );
00218         EnableToolTips();
00219         
00220         return TRUE;
00221 }
00222 
00223 void CDownloadMonitorDlg::OnDestroy() 
00224 {
00225         KillTimer( 1 );
00226         
00227         if ( m_pDownload != NULL )
00228         {
00229                 CSingleLock pLock( &Transfers.m_pSection );
00230                 
00231                 if ( pLock.Lock( 250 ) )
00232                 {
00233                         if ( Downloads.Check( m_pDownload ) ) m_pDownload->m_pMonitorWnd = NULL;
00234                         m_pDownload = NULL;
00235                         pLock.Unlock();
00236                 }
00237         }
00238         
00239         if ( m_bTray )
00240         {
00241                 Shell_NotifyIcon( NIM_DELETE, &m_pTray );
00242                 m_bTray = FALSE;
00243         }
00244         
00245         CSkinDialog::OnDestroy();
00246 }
00247 
00248 void CDownloadMonitorDlg::PostNcDestroy() 
00249 {
00250         CSkinDialog::PostNcDestroy();
00251         delete this;
00252 }
00253 
00254 void CDownloadMonitorDlg::OnTimer(UINT nIDEvent) 
00255 {
00256         CSingleLock pLock( &Transfers.m_pSection );
00257         if ( ! pLock.Lock( 250 ) ) return;
00258         
00259         if ( ! m_pDownload || ! Downloads.Check( m_pDownload ) )
00260         {
00261                 KillTimer( 1 );
00262                 PostMessage( WM_CLOSE );
00263                 return;
00264         }
00265         
00266         if ( m_bCompleted ) return;
00267         
00268         BOOL bCompleted = m_pDownload->IsCompleted();
00269         DWORD nSpeed    = m_pDownload->GetMeasuredSpeed() * 8;
00270         CString strText, strFormat, strOf;
00271 
00272         LoadString( strOf, IDS_GENERAL_OF );
00273         
00274         m_pItem->Add( nSpeed );
00275         m_pGraph->m_nUpdates++;
00276         m_pGraph->m_nMaximum = max( m_pGraph->m_nMaximum, nSpeed );
00277         
00278         if ( m_pDownload->IsStarted() )
00279         {
00280                 if ( theApp.m_bRTL )
00281                 {
00282                         strText.Format( _T("%s %s %.1f%% : Shareaza"),
00283                                 (LPCTSTR)m_pDownload->m_sRemoteName, strOf, m_pDownload->GetProgress() * 100.0 );
00284                 }
00285                 else
00286                 {
00287                 strText.Format( _T("%.1f%% %s %s : Shareaza"),
00288                         m_pDownload->GetProgress() * 100.0, strOf, (LPCTSTR)m_pDownload->m_sRemoteName );
00289         }
00290         }
00291         else
00292         {
00293                 strText.Format( _T("%s : Shareaza"),
00294                         (LPCTSTR)m_pDownload->m_sRemoteName );
00295         }
00296         
00297         Update( this, strText );
00298         
00299         if ( m_bTray )
00300         {
00301                 if ( _tcsncmp( m_pTray.szTip, strText, 63 ) )
00302                 {
00303                         m_pTray.uFlags = NIF_TIP;
00304                         _tcsncpy( m_pTray.szTip, strText, 63 );
00305                         m_pTray.szTip[63] = 0;
00306                         Shell_NotifyIcon( NIM_MODIFY, &m_pTray );
00307                 }
00308         }
00309         
00310         if ( bCompleted )
00311         {
00312                 if ( m_wndClose.GetCheck() )
00313                 {
00314                         PostMessage( WM_CLOSE );
00315                 }
00316                 else
00317                 {
00318                         ShowWindow( SW_SHOWNORMAL );
00319                         SetForegroundWindow();
00320                 }
00321                 
00322                 m_bCompleted = TRUE;
00323         }
00324         else
00325         {
00326                 if ( IsIconic() || m_bTray ) return;
00327         }
00328         
00329         int nSourceCount        = m_pDownload->GetSourceCount();
00330         int nTransferCount      = m_pDownload->GetTransferCount();
00331         
00332         CString strNA;
00333         LoadString( strNA, IDS_TIP_NA );
00334         
00335         if ( bCompleted )
00336         {
00337                 LoadString( strText, IDS_DLM_COMPLETED );
00338                 Update( &m_wndStatus, strText );
00339                 Update( &m_wndTime, strNA );
00340                 Update( &m_wndSpeed, strNA );
00341                 LoadString( strText, IDS_DLM_COMPLETED_WORD );
00342                 Update( &m_wndSources, strText );
00343         }
00344         else if ( m_pDownload->IsMoving() )
00345         {
00346                 LoadString( strText, IDS_DLM_MOVING );
00347                 Update( &m_wndStatus, strText );
00348                 Update( &m_wndTime, strNA );
00349                 Update( &m_wndSpeed, strNA );
00350                 LoadString( strText, IDS_DLM_COMPLETED_WORD );
00351                 Update( &m_wndSources, strText );
00352         }
00353         else if ( m_pDownload->IsPaused() )
00354         {
00355                 LoadString( strText, IDS_DLM_PAUSED );
00356                 Update( &m_wndStatus, strText );
00357                 Update( &m_wndTime, strNA );
00358                 Update( &m_wndSpeed, strNA );
00359                 strText.Format( _T("%i"), nSourceCount );
00360                 Update( &m_wndSources, strText );               
00361         }
00362         else if ( m_pDownload->GetProgress() == 1.0f && m_pDownload->IsStarted() )
00363         {
00364                 LoadString( strText, IDS_DLM_VERIFY );
00365                 Update( &m_wndStatus, strText );
00366                 Update( &m_wndTime, strNA );
00367                 Update( &m_wndSpeed, strNA );
00368         }
00369         else if ( nTransferCount > 0 )
00370         {
00371                 LoadString( strText, IDS_DLM_DOWNLOADING );
00372                 Update( &m_wndStatus, strText );
00373 
00374                 DWORD nTime = m_pDownload->GetTimeRemaining();
00375                 strText.Empty();
00376 
00377                 if ( nTime != 0xFFFFFFFF )
00378                 {
00379                         if ( nTime > 86400 )
00380                         {
00381                                 LoadString( strFormat, IDS_DLM_TIME_DAH );
00382                                 strText.Format( strFormat, nTime / 86400, ( nTime / 3600 ) % 24 );
00383                         }
00384                         else if ( nTime > 3600 )
00385                         {
00386                                 LoadString( strFormat, IDS_DLM_TIME_HAM );
00387                                 strText.Format( strFormat, nTime / 3600, ( nTime % 3600 ) / 60 );
00388                         }
00389                         else if ( nTime > 60 )
00390                         {
00391                                 LoadString( strFormat, IDS_DLM_TIME_MAS );
00392                                 strText.Format( strFormat, nTime / 60, nTime % 60 );
00393                         }
00394                         else
00395                         {
00396                                 LoadString( strFormat, IDS_DLM_TIME_S );
00397                                 strText.Format( strFormat, nTime % 60 );
00398                         }
00399                 }
00400 
00401                 Update( &m_wndTime, strText );
00402 
00403                 strText = Settings.SmartVolume( m_pDownload->GetAverageSpeed() * 8, FALSE, TRUE );
00404                 Update( &m_wndSpeed, strText );
00405 
00406                 strText.Format( _T("%i %s %i"), nTransferCount, strOf, nSourceCount );
00407                 if ( theApp.m_bRTL ) strText = _T("\x202B") + strText;
00408                 Update( &m_wndSources, strText );
00409         }
00410         else if ( nSourceCount )
00411         {
00412                 LoadString( strText, IDS_DLM_DOWNLOADING );
00413                 Update( &m_wndStatus, strText );
00414                 Update( &m_wndTime, strNA );
00415                 Update( &m_wndSpeed, strNA );
00416                 strText.Format( _T("%i"), nSourceCount );
00417                 Update( &m_wndSources, strText );
00418         }
00419         else
00420         {
00421                 LoadString( strText, IDS_DLM_SOURCING );
00422                 Update( &m_wndStatus, strText );
00423                 Update( &m_wndTime, strNA );
00424                 Update( &m_wndSpeed, strNA );
00425                 LoadString( strText, IDS_DLM_NO_SOURCES );
00426                 Update( &m_wndSources, strText );
00427         }
00428 
00429         if ( m_pDownload->IsStarted() )
00430         {
00431                 if ( theApp.m_bRTL )
00432                 {
00433                         strText.Format( _T("(%.2f%%) %s %s %s"),
00434                                 m_pDownload->GetProgress() * 100.0,
00435                                 (LPCTSTR)Settings.SmartVolume( m_pDownload->m_nSize, FALSE ), strOf,
00436                                 (LPCTSTR)Settings.SmartVolume( m_pDownload->GetVolumeComplete(), FALSE ) );
00437                 }
00438                 else
00439                 {
00440                 strText.Format( _T("%s %s %s (%.2f%%)"),
00441                         (LPCTSTR)Settings.SmartVolume( m_pDownload->GetVolumeComplete(), FALSE ),
00442                         strOf, (LPCTSTR)Settings.SmartVolume( m_pDownload->m_nSize, FALSE ),
00443                         m_pDownload->GetProgress() * 100.0 );
00444                 }
00445                 Update( &m_wndVolume, strText );
00446         }
00447         else
00448         {
00449                 LoadString( strText, IDS_TIP_NA );
00450                 Update( &m_wndVolume, strText );
00451         }
00452 
00453         
00454         LoadString( strText, bCompleted ? IDS_DLM_OPEN_OPEN : IDS_DLM_OPEN_PREVIEW );
00455         Update( &m_wndLaunch, strText );
00456         Update( &m_wndLaunch, m_pDownload->IsStarted() );
00457         Update( &m_wndStop, ! bCompleted );
00458         Update( &m_wndClose, ! bCompleted );
00459 
00460         CClientDC dc( this );
00461         DoPaint( dc );
00462 }
00463 
00464 void CDownloadMonitorDlg::Update(CWnd* pWnd, LPCTSTR pszText)
00465 {
00466         CString strOld;
00467         pWnd->GetWindowText( strOld );
00468         if ( strOld != pszText ) pWnd->SetWindowText( pszText );
00469 }
00470 
00471 void CDownloadMonitorDlg::Update(CWnd* pWnd, BOOL bEnabled)
00472 {
00473         if ( pWnd->IsWindowEnabled() == bEnabled ) return;
00474         pWnd->EnableWindow( bEnabled );
00475 }
00476 
00477 void CDownloadMonitorDlg::OnPaint() 
00478 {
00479         CPaintDC dc( this );
00480         DoPaint( dc );
00481 }
00482 
00483 void CDownloadMonitorDlg::DoPaint(CDC& dc)
00484 {
00485         CRect rc;
00486 
00487         m_wndProgress.GetWindowRect( &rc );
00488         ScreenToClient( &rc );
00489         
00490         DrawProgressBar( &dc, &rc );
00491         
00492         m_wndGraph.GetWindowRect( &rc );
00493         ScreenToClient( &rc );
00494         
00495         dc.Draw3dRect( &rc, 0, 0 );
00496         rc.DeflateRect( 1, 1 );
00497         
00498         m_pGraph->BufferedPaint( &dc, &rc );
00499 }
00500 
00501 void CDownloadMonitorDlg::DrawProgressBar(CDC* pDC, CRect* pRect)
00502 {
00503         CRect rcCell( pRect );
00504 
00505         pDC->Draw3dRect( &rcCell, 0, 0 );
00506         rcCell.DeflateRect( 1, 1 );
00507         
00508         if ( Transfers.m_pSection.Lock( 50 ) )
00509         {
00510                 if ( Downloads.Check( m_pDownload ) )
00511                         CFragmentBar::DrawDownload( pDC, &rcCell, m_pDownload, Skin.m_crDialog );
00512                 Transfers.m_pSection.Unlock();
00513         }
00514 }
00515 
00516 void CDownloadMonitorDlg::OnDownloadLaunch() 
00517 {
00518         CSingleLock pLock( &Transfers.m_pSection );
00519         if ( ! pLock.Lock( 250 ) || ! Downloads.Check( m_pDownload ) ) return;
00520         
00521         CString strName = m_pDownload->m_sLocalName;
00522         BOOL bCompleted = m_pDownload->IsMoving();
00523         
00524         CString strType;
00525         CLSID pCLSID;
00526         
00527         int nExtPos = strName.ReverseFind( '.' );
00528         if ( nExtPos > 0 ) strType = strName.Mid( nExtPos );
00529         CharLower( strType.GetBuffer() );
00530         strType.ReleaseBuffer();
00531         
00532         if ( bCompleted || ! Plugins.LookupCLSID( _T("DownloadPreview"), strType, pCLSID ) )
00533         {
00534                 pLock.Unlock();
00535                 CFileExecutor::Execute( strName, FALSE ); // , IDS_DOWNLOAD_CONFIRM_EXECUTE );
00536         }
00537         else
00538         {
00539                 m_pDownload->Preview( &pLock );
00540                 pLock.Unlock();
00541         }
00542         
00543         if ( bCompleted ) PostMessage( WM_CLOSE );
00544 }
00545 
00546 void CDownloadMonitorDlg::OnDownloadLibrary() 
00547 {
00548         CWnd* pMainWnd = AfxGetMainWnd();
00549         if ( ! pMainWnd ) return;
00550 
00551         pMainWnd->PostMessage( WM_COMMAND, ID_VIEW_LIBRARY );
00552         pMainWnd->PostMessage( WM_SYSCOMMAND, SC_RESTORE );
00553 }
00554 
00555 void CDownloadMonitorDlg::OnDownloadStop() 
00556 {
00557         CSingleLock pLock( &Transfers.m_pSection );
00558         if ( ! pLock.Lock( 250 ) || ! Downloads.Check( m_pDownload ) ) return;
00559 
00560         if ( m_pDownload->IsStarted() )
00561         {
00562                 CString strFormat, strPrompt;
00563 		::LoadString( strFormat, IDS_DOWNLOAD_CONFIRM_CLEAR );
00564                 strPrompt.Format( strFormat, (LPCTSTR)m_pDownload->m_sRemoteName );
00565 
00566                 pLock.Unlock();
00567                 if ( MessageBox( strPrompt, NULL, MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 ) != IDYES ) return;
00568                 pLock.Lock();
00569         }
00570 
00571         if ( Downloads.Check( m_pDownload ) )
00572         {
00573                 m_pDownload->Remove();
00574                 PostMessage( WM_CLOSE );
00575         }
00576 }
00577 
00578 void CDownloadMonitorDlg::OnDownloadCancel() 
00579 {
00580         PostMessage( WM_CLOSE );
00581 }
00582 
00583 void CDownloadMonitorDlg::OnClose() 
00584 {
00585         DestroyWindow();
00586 }
00587 
00588 void CDownloadMonitorDlg::OnSysCommand(UINT nID, LPARAM lParam) 
00589 {
00590         UINT nCommand = nID & 0xFFF0;
00591         BOOL bShift = GetAsyncKeyState( VK_SHIFT ) & 0x8000;
00592 
00593         if ( nCommand == SC_MAXIMIZE || ( nCommand == SC_MINIMIZE && bShift ) )
00594         {
00595                 if ( ! m_bTray )
00596                 {
00597                         m_pTray.cbSize                          = sizeof(m_pTray);
00598                         m_pTray.hWnd                            = GetSafeHwnd();
00599                         m_pTray.uID                                     = 0;
00600                         m_pTray.uFlags                          = NIF_ICON | NIF_MESSAGE | NIF_TIP;
00601                         m_pTray.uCallbackMessage        = WM_TRAY;
00602                         m_pTray.hIcon                           = theApp.LoadIcon( IDI_DOWNLOAD_MONITOR );
00603                         _tcscpy( m_pTray.szTip, _T("Shareaza Download") );
00604                         Shell_NotifyIcon( NIM_ADD, &m_pTray );
00605                         ShowWindow( SW_HIDE );
00606                         m_bTray = TRUE;
00607                 }
00608                 return;
00609         }
00610         else if ( nCommand == SC_RESTORE && m_bTray )
00611         {
00612                 OnTray( WM_LBUTTONDBLCLK, 0 );
00613                 return;
00614         }
00615         else if ( nCommand == SC_NEXTWINDOW )
00616         {
00617                 if ( GetExStyle() & WS_EX_TOPMOST )
00618                 {
00619                         SetWindowPos( &wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
00620                 }
00621                 else
00622                 {
00623                         SetWindowPos( &wndTopMost, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
00624                 }
00625                 return;
00626         }
00627         
00628         CSkinDialog::OnSysCommand( nID, lParam );
00629 }
00630 
00631 LONG CDownloadMonitorDlg::OnTray(UINT wParam, LONG lParam)
00632 {
00633         if ( LOWORD(lParam) == WM_LBUTTONDBLCLK && m_bTray )
00634         {
00635                 Shell_NotifyIcon( NIM_DELETE, &m_pTray );
00636                 ShowWindow( SW_SHOWNORMAL );
00637                 SetForegroundWindow();
00638                 m_bTray = FALSE;
00639         }
00640 
00641         return 0;
00642 }
00643 
00644 HBRUSH CDownloadMonitorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
00645 {
00646         HBRUSH hbr = CSkinDialog::OnCtlColor(pDC, pWnd, nCtlColor);
00647         
00648         if ( pWnd == &m_wndFile )
00649         {
00650                 pDC->SelectObject( &theApp.m_gdiFontBold );
00651         }
00652 
00653         return hbr;
00654 }
00655 
00656 void CDownloadMonitorDlg::OnContextMenu(CWnd* pWnd, CPoint point) 
00657 {
00658         CMainWnd* pMainWnd = (CMainWnd*)AfxGetMainWnd();
00659         if ( ! pMainWnd || ! IsWindow( pMainWnd->m_hWnd ) ) return;
00660         
00661         CDownloadsWnd* pDownWnd = (CDownloadsWnd*)pMainWnd->m_pWindows.Find( RUNTIME_CLASS(CDownloadsWnd) );
00662         if ( ! pDownWnd ) return;
00663         
00664         if ( ! pDownWnd->Select( m_pDownload ) ) return;
00665         
00666         CMenu* pPopup = ::Skin.GetMenu( _T("CDownloadsWnd.Download") );
00667         if ( ! pPopup ) return;
00668 
00669         MENUITEMINFO pInfo;
00670         pInfo.cbSize    = sizeof(pInfo);
00671         pInfo.fMask             = MIIM_STATE;
00672         GetMenuItemInfo( pPopup->GetSafeHmenu(), ID_DOWNLOADS_LAUNCH, FALSE, &pInfo );
00673         pInfo.fState    |= MFS_DEFAULT;
00674         SetMenuItemInfo( pPopup->GetSafeHmenu(), ID_DOWNLOADS_LAUNCH, FALSE, &pInfo );
00675 
00676         CoolMenu.AddMenu( pPopup, TRUE );
00677 
00678         UINT nID = pPopup->TrackPopupMenu( TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_RETURNCMD,
00679                 point.x, point.y, pDownWnd );
00680 
00681         if ( nID && pDownWnd->Select( m_pDownload ) )
00682         {
00683                 pDownWnd->SendMessage( WM_COMMAND, nID );
00684         }
00685 }
00686 
00687 BOOL CDownloadMonitorDlg::OnNeedText(UINT nID, NMHDR* pTTTH, LRESULT* pResult)
00688 {
00689         if ( pTTTH->idFrom == IDC_DOWNLOAD_FILE )
00690         {
00691                 TOOLTIPTEXT* pTTT = (TOOLTIPTEXT*)pTTTH;
00692                 pTTT->lpszText = (LPTSTR)(LPCTSTR)m_sName;
00693         }
00694 
00695         return TRUE;
00696 }
00697 
00698 void CDownloadMonitorDlg::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) 
00699 {
00700         DWORD nCheck = ( GetExStyle() & WS_EX_TOPMOST ) ? MF_CHECKED : MF_UNCHECKED;
00701         pPopupMenu->CheckMenuItem( SC_NEXTWINDOW, MF_BYCOMMAND|nCheck );
00702 
00703         CSkinDialog::OnInitMenuPopup( pPopupMenu, nIndex, bSysMenu );
00704 }

Generated on Thu Dec 15 10:39:39 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2