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

WndTraffic.cpp

Go to the documentation of this file.
00001 //
00002 // WndTraffic.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 "WndTraffic.h"
00026 #include "WndMain.h"
00027 #include "DlgGraphList.h"
00028 #include "GraphLine.h"
00029 
00030 #ifdef _DEBUG
00031 #define new DEBUG_NEW
00032 #undef THIS_FILE
00033 static char THIS_FILE[] = __FILE__;
00034 #endif
00035 
00036 IMPLEMENT_SERIAL(CTrafficWnd, CChildWnd, 0)
00037 
00038 BEGIN_MESSAGE_MAP(CTrafficWnd, CChildWnd)
00039         //{{AFX_MSG_MAP(CTrafficWnd)
00040         ON_WM_CREATE()
00041         ON_WM_DESTROY()
00042         ON_WM_PAINT()
00043         ON_WM_TIMER()
00044         ON_WM_CONTEXTMENU()
00045         ON_UPDATE_COMMAND_UI(ID_TRAFFIC_GRID, OnUpdateTrafficGrid)
00046         ON_COMMAND(ID_TRAFFIC_GRID, OnTrafficGrid)
00047         ON_UPDATE_COMMAND_UI(ID_TRAFFIC_AXIS, OnUpdateTrafficAxis)
00048         ON_COMMAND(ID_TRAFFIC_AXIS, OnTrafficAxis)
00049         ON_UPDATE_COMMAND_UI(ID_TRAFFIC_LEGEND, OnUpdateTrafficLegend)
00050         ON_COMMAND(ID_TRAFFIC_LEGEND, OnTrafficLegend)
00051         ON_COMMAND(ID_TRAFFIC_SETUP, OnTrafficSetup)
00052         ON_COMMAND(ID_TRAFFIC_CLEAR, OnTrafficClear)
00053         ON_WM_LBUTTONDBLCLK()
00054         ON_COMMAND(ID_TRAFFIC_WINDOW, OnTrafficWindow)
00055         ON_WM_SIZE()
00056         //}}AFX_MSG_MAP
00057 END_MESSAGE_MAP()
00058 
00059 
00061 // CTrafficWnd construction
00062 
00063 CTrafficWnd::CTrafficWnd(DWORD nUnique)
00064 {
00065         m_nUnique               = nUnique;
00066         m_pGraph                = new CLineGraph();
00067 
00068         Create( IDR_TRAFFICFRAME );
00069 }
00070 
00071 CTrafficWnd::~CTrafficWnd()
00072 {
00073         if ( m_pGraph ) delete m_pGraph;
00074 }
00075 
00077 // CTrafficWnd message handlers
00078 
00079 int CTrafficWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
00080 {
00081         if ( CChildWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00082 
00083         if ( m_nUnique == 0 ) FindFreeUnique();
00084 
00085         if ( ! Serialize( FALSE ) && m_nUnique == 1 ) m_pGraph->CreateDefaults();
00086 
00087         UpdateCaption();
00088 
00089         return 0;
00090 }
00091 
00092 void CTrafficWnd::OnDestroy()
00093 {
00094         KillTimer( 2 );
00095         Serialize( TRUE );
00096 
00097         CChildWnd::OnDestroy();
00098 }
00099 
00100 void CTrafficWnd::FindFreeUnique()
00101 {
00102         CWindowManager* pWindows = GetManager();
00103 
00104         for ( m_nUnique = 1 ; m_nUnique < 1000 ; m_nUnique++ )
00105         {
00106                 CTrafficWnd* pChild = NULL;
00107                 BOOL bAvailable         = TRUE;
00108 
00109                 while ( pChild = (CTrafficWnd*)pWindows->Find( RUNTIME_CLASS(CTrafficWnd), pChild ) )
00110                 {
00111                         if ( pChild != this && pChild->m_nUnique == m_nUnique )
00112                         {
00113                                 bAvailable = FALSE;
00114                                 break;
00115                         }
00116                 }
00117 
00118                 if ( bAvailable ) break;
00119         }
00120 }
00121 
00122 void CTrafficWnd::SetUpdateRate()
00123 {
00124         KillTimer( 2 );
00125 
00126         if ( TRUE )
00127         {
00128                 CLineGraph* pGraph = (CLineGraph*)m_pGraph;
00129                 SetTimer( 2, pGraph->m_nSpeed, NULL );
00130         }
00131 }
00132 
00133 void CTrafficWnd::OnSize(UINT nType, int cx, int cy)
00134 {
00135         CChildWnd::OnSize( nType, cx, cy );
00136         Invalidate();
00137 }
00138 
00139 void CTrafficWnd::OnPaint()
00140 {
00141         CPaintDC dc( this );
00142         CRect rc;
00143 
00144         GetClientRect( &rc );
00145         m_pGraph->BufferedPaint( &dc, &rc );
00146 }
00147 
00148 void CTrafficWnd::OnTimer(UINT nIDEvent)
00149 {
00150         if ( nIDEvent == 2 && m_pGraph->Update() ) Invalidate();
00151 }
00152 
00153 void CTrafficWnd::OnContextMenu(CWnd* pWnd, CPoint point)
00154 {
00155         TrackPopupMenu( _T("CTrafficWnd"), point, ID_TRAFFIC_SETUP );
00156 }
00157 
00158 void CTrafficWnd::OnUpdateTrafficGrid(CCmdUI* pCmdUI)
00159 {
00160         CLineGraph* pLineGraph = (CLineGraph*)m_pGraph;
00161         pCmdUI->SetCheck( pLineGraph->m_bShowGrid );
00162 }
00163 
00164 void CTrafficWnd::OnTrafficGrid()
00165 {
00166         CLineGraph* pLineGraph = (CLineGraph*)m_pGraph;
00167         pLineGraph->m_bShowGrid = ! pLineGraph->m_bShowGrid;
00168         Invalidate();
00169 }
00170 
00171 void CTrafficWnd::OnUpdateTrafficAxis(CCmdUI* pCmdUI)
00172 {
00173         CLineGraph* pLineGraph = (CLineGraph*)m_pGraph;
00174         pCmdUI->SetCheck( pLineGraph->m_bShowAxis );
00175 }
00176 
00177 void CTrafficWnd::OnTrafficAxis()
00178 {
00179         CLineGraph* pLineGraph = (CLineGraph*)m_pGraph;
00180         pLineGraph->m_bShowAxis = ! pLineGraph->m_bShowAxis;
00181         Invalidate();
00182 }
00183 
00184 void CTrafficWnd::OnUpdateTrafficLegend(CCmdUI* pCmdUI)
00185 {
00186         CLineGraph* pLineGraph = (CLineGraph*)m_pGraph;
00187         pCmdUI->SetCheck( pLineGraph->m_bShowLegend );
00188 }
00189 
00190 void CTrafficWnd::OnTrafficLegend()
00191 {
00192         CLineGraph* pLineGraph = (CLineGraph*)m_pGraph;
00193         pLineGraph->m_bShowLegend = ! pLineGraph->m_bShowLegend;
00194         Invalidate();
00195 }
00196 
00197 void CTrafficWnd::OnTrafficSetup()
00198 {
00199         CGraphListDlg dlg( this, (CLineGraph*)m_pGraph );
00200 
00201         dlg.m_sName = m_sName;
00202 
00203         if ( dlg.DoModal() == IDOK )
00204         {
00205                 m_sName = dlg.m_sName;
00206 
00207                 SetUpdateRate();
00208                 UpdateCaption();
00209                 Invalidate();
00210         }
00211 }
00212 
00213 void CTrafficWnd::OnTrafficClear()
00214 {
00215         m_pGraph->Clear();
00216 }
00217 
00218 void CTrafficWnd::OnLButtonDblClk(UINT nFlags, CPoint point)
00219 {
00220         PostMessage( WM_COMMAND, ID_TRAFFIC_SETUP );
00221 }
00222 
00223 void CTrafficWnd::OnTrafficWindow()
00224 {
00225         new CTrafficWnd();
00226 }
00227 
00229 // CTrafficWnd serialize
00230 
00231 BOOL CTrafficWnd::Serialize(BOOL bSave)
00232 {
00233         WINDOWPLACEMENT pPos = { sizeof(WINDOWPLACEMENT) };
00234         CString strFile;
00235         CFile pFile;
00236 
00237         strFile.Format( _T("%s\\Data\\Graph%.4i.dat"), (LPCTSTR)Settings.General.Path, m_nUnique );
00238 
00239         if ( ! pFile.Open( strFile, bSave ? ( CFile::modeWrite | CFile::modeCreate ) : CFile::modeRead ) )
00240                 return FALSE;
00241 
00242         CArchive ar( &pFile, bSave ? CArchive::store : CArchive::load );
00243         int nVersion = 0;
00244 
00245         if ( ar.IsStoring() )
00246         {
00247                 nVersion = 0xFFFFFFFF;
00248                 ar << nVersion;
00249                 nVersion = 1;
00250                 ar << nVersion;
00251 
00252                 ar << m_nUnique;
00253                 ar << m_sName;
00254 
00255                 GetWindowPlacement( &pPos );
00256                 ar.Write( &pPos, sizeof(pPos) );
00257         }
00258         else
00259         {
00260                 ar >> m_nUnique;
00261 
00262                 if ( m_nUnique == 0xFFFFFFFF )
00263                 {
00264                         ar >> nVersion;
00265                         ar >> m_nUnique;
00266                 }
00267 
00268                 if ( nVersion >= 1 ) ar >> m_sName;
00269 
00270                 ar.Read( &pPos, sizeof(pPos) );
00271                 if ( pPos.showCmd == SW_SHOWNORMAL )
00272                         SetWindowPlacement( &pPos );
00273         }
00274 
00275         m_pGraph->Serialize( ar );
00276 
00277         ar.Close();
00278         pFile.Close();
00279 
00280         if ( ! bSave ) SetUpdateRate();
00281 
00282         return TRUE;
00283 }
00284 
00285 void CTrafficWnd::UpdateCaption()
00286 {
00287         CString strCaption, strName;
00288 
00289         if ( m_sName.GetLength() )
00290         {
00291                 strName = _T(" : ") + m_sName;
00292         }
00293         else
00294         {
00295                 if ( m_nUnique <= 26 )
00296                         strName.Format( _T(" (%c)"), 'A' + m_nUnique - 1 );
00297                 else
00298                         strName.Format( _T(" (%lu)"), m_nUnique );
00299         }
00300 
00301         LoadString( strCaption, IDR_TRAFFICFRAME );
00302         strCaption += strName;
00303         SetWindowText( strCaption );
00304 }

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