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

DlgGraphList.cpp

Go to the documentation of this file.
00001 //
00002 // DlgGraphList.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 "GraphLine.h"
00025 #include "GraphItem.h"
00026 #include "DlgGraphList.h"
00027 #include "DlgGraphItem.h"
00028 #include "LiveList.h"
00029 #include "Skin.h"
00030 
00031 #ifdef _DEBUG
00032 #define new DEBUG_NEW
00033 #undef THIS_FILE
00034 static char THIS_FILE[] = __FILE__;
00035 #endif
00036 
00037 BEGIN_MESSAGE_MAP(CGraphListDlg, CSkinDialog)
00038         //{{AFX_MSG_MAP(CGraphListDlg)
00039         ON_NOTIFY(LVN_ITEMCHANGED, IDC_GRAPH_ITEMS, OnItemChangedGraphItems)
00040         ON_BN_CLICKED(IDC_GRAPH_ADD, OnGraphAdd)
00041         ON_BN_CLICKED(IDC_GRAPH_EDIT, OnGraphEdit)
00042         ON_BN_CLICKED(IDC_GRAPH_REMOVE, OnGraphRemove)
00043         ON_NOTIFY(NM_DBLCLK, IDC_GRAPH_ITEMS, OnDblClkGraphItems)
00044         ON_NOTIFY(NM_CUSTOMDRAW, IDC_GRAPH_ITEMS, OnCustomDrawItems)
00045         //}}AFX_MSG_MAP
00046 END_MESSAGE_MAP()
00047 
00048 #define LIST_COLUMNS    1
00049 
00050 
00052 // CGraphListDlg dialog
00053 
00054 CGraphListDlg::CGraphListDlg(CWnd* pParent, CLineGraph* pGraph) : CSkinDialog(CGraphListDlg::IDD, pParent)
00055 {
00056         //{{AFX_DATA_INIT(CGraphListDlg)
00057         m_nSpeed = 0;
00058         m_bShowGrid = FALSE;
00059         m_bShowAxis = FALSE;
00060         m_bShowLegend = FALSE;
00061         m_sName = _T("");
00062         //}}AFX_DATA_INIT
00063         m_pGraph = pGraph;
00064 }
00065 
00066 void CGraphListDlg::DoDataExchange(CDataExchange* pDX)
00067 {
00068         CSkinDialog::DoDataExchange(pDX);
00069         //{{AFX_DATA_MAP(CGraphListDlg)
00070         DDX_Control(pDX, IDCANCEL, m_wndCancel);
00071         DDX_Control(pDX, IDOK, m_wndOK);
00072         DDX_Control(pDX, IDC_GRAPH_SPEED_SPIN, m_wndSpeed);
00073         DDX_Control(pDX, IDC_GRAPH_REMOVE, m_wndRemove);
00074         DDX_Control(pDX, IDC_GRAPH_EDIT, m_wndEdit);
00075         DDX_Control(pDX, IDC_GRAPH_ITEMS, m_wndList);
00076         DDX_Text(pDX, IDC_GRAPH_SPEED, m_nSpeed);
00077         DDX_Check(pDX, IDC_GRAPH_GRID, m_bShowGrid);
00078         DDX_Check(pDX, IDC_GRAPH_AXIS, m_bShowAxis);
00079         DDX_Check(pDX, IDC_GRAPH_LEGEND, m_bShowLegend);
00080         DDX_Text(pDX, IDC_NAME, m_sName);
00081         //}}AFX_DATA_MAP
00082 }
00083 
00085 // CGraphListDlg message handlers
00086 
00087 BOOL CGraphListDlg::OnInitDialog()
00088 {
00089         CSkinDialog::OnInitDialog();
00090 
00091         SkinMe( _T("CGraphListDlg"), IDR_TRAFFICFRAME );
00092 
00093         m_gdiImageList.Create( IDB_COLOURDOT, 16, 0, RGB(0,255,0) );
00094         m_wndList.SetImageList( &m_gdiImageList, LVSIL_SMALL );
00095 
00096         m_wndSpeed.SendMessage( WM_USER+111, 10, 120000 );
00097 
00098         m_bShowAxis             = m_pGraph->m_bShowAxis;
00099         m_bShowGrid             = m_pGraph->m_bShowGrid;
00100         m_bShowLegend   = m_pGraph->m_bShowLegend;
00101         m_nSpeed                = m_pGraph->m_nSpeed;
00102 
00103         UpdateData( FALSE );
00104 
00105         for ( POSITION pos = m_pGraph->GetItemIterator() ; pos ; )
00106         {
00107                 CGraphItem* pItem = m_pGraph->GetNextItem( pos );
00108                 CLiveItem* pLive = PrepareItem( pItem );
00109                 pLive->Add( &m_wndList, -1, LIST_COLUMNS );
00110                 delete pLive;
00111         }
00112 
00113         OnItemChangedGraphItems( NULL, NULL );
00114 
00115         return TRUE;
00116 }
00117 
00118 CLiveItem* CGraphListDlg::PrepareItem(CGraphItem* pItem)
00119 {
00120         CLiveItem* pLive = new CLiveItem( LIST_COLUMNS, (DWORD)pItem );
00121         pLive->m_nImage = -1;
00122 
00123         pLive->Set( 0, pItem->m_sName );
00124 
00125         return pLive;
00126 }
00127 
00128 void CGraphListDlg::OnCustomDrawItems(NMHDR* pNMHDR, LRESULT* pResult)
00129 {
00130         NMLVCUSTOMDRAW* pDraw = (NMLVCUSTOMDRAW*)pNMHDR;
00131 
00132         if ( pDraw->nmcd.dwDrawStage == CDDS_PREPAINT )
00133         {
00134                 *pResult = CDRF_NOTIFYITEMDRAW;
00135         }
00136         else if ( pDraw->nmcd.dwDrawStage == (CDDS_ITEM|CDDS_PREPAINT) )
00137         {
00138                 CGraphItem* pItem = (CGraphItem*)pDraw->nmcd.lItemlParam;
00139                 CDC* pDC = CDC::FromHandle( pDraw->nmcd.hdc );
00140 
00141                 CRect rc;
00142                 m_wndList.GetItemRect( pDraw->nmcd.dwItemSpec, &rc, LVIR_ICON );
00143 
00144                 pDC->SetTextColor( pItem->m_nColour );
00145                 m_gdiImageList.Draw( pDC, 1, rc.TopLeft(), ILD_NORMAL );
00146                 m_gdiImageList.Draw( pDC, 0, rc.TopLeft(), ILD_MASK|ILD_TRANSPARENT );
00147 
00148                 *pResult = CDRF_DODEFAULT;
00149         }
00150 }
00151 
00152 void CGraphListDlg::OnItemChangedGraphItems(NMHDR* pNMHDR, LRESULT* pResult)
00153 {
00154         NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
00155         if ( pResult ) *pResult = 0;
00156         int nSelected = m_wndList.GetSelectedCount();
00157         m_wndEdit.EnableWindow( nSelected == 1 );
00158         m_wndRemove.EnableWindow( nSelected > 0 );
00159 }
00160 
00161 void CGraphListDlg::OnDblClkGraphItems(NMHDR* pNMHDR, LRESULT* pResult)
00162 {
00163         OnGraphEdit();
00164         *pResult = 0;
00165 }
00166 
00167 void CGraphListDlg::OnGraphAdd()
00168 {
00169         CGraphItemDlg dlg( this, new CGraphItem() );
00170 
00171         if ( dlg.DoModal() == IDOK )
00172         {
00173                 m_pGraph->AddItem( dlg.m_pItem );
00174                 CLiveItem* pLive = PrepareItem( dlg.m_pItem );
00175                 pLive->Add( &m_wndList, -1, LIST_COLUMNS );
00176                 delete pLive;
00177                 SetModified();
00178         }
00179         else
00180         {
00181                 delete dlg.m_pItem;
00182         }
00183 }
00184 
00185 void CGraphListDlg::OnGraphEdit()
00186 {
00187         int nItem = m_wndList.GetNextItem( -1, LVNI_SELECTED );
00188         if ( nItem < 0 ) return;
00189 
00190         CGraphItemDlg dlg( this, (CGraphItem*)m_wndList.GetItemData( nItem ) );
00191 
00192         if ( dlg.DoModal() == IDOK )
00193         {
00194                 CLiveItem* pLive = PrepareItem( dlg.m_pItem );
00195                 pLive->Update( &m_wndList, nItem, LIST_COLUMNS );
00196                 delete pLive;
00197                 SetModified();
00198         }
00199 }
00200 
00201 void CGraphListDlg::OnGraphRemove()
00202 {
00203         for ( int nItem = m_wndList.GetItemCount() - 1 ; nItem >= 0 ; nItem -- )
00204         {
00205                 if ( m_wndList.GetItemState( nItem, LVIS_SELECTED ) )
00206                 {
00207                         CGraphItem* pItem = (CGraphItem*)m_wndList.GetItemData( nItem );
00208                         m_wndList.DeleteItem( nItem );
00209                         m_pGraph->RemoveItem( pItem );
00210                         m_pGraph->ResetMaximum();
00211                         SetModified();
00212                 }
00213         }
00214 }
00215 
00216 void CGraphListDlg::SetModified()
00217 {
00218         CString sText;
00219         if ( m_wndCancel.IsWindowEnabled() )
00220         {
00221                 m_wndCancel.EnableWindow( FALSE );
00222                 LoadString( sText, IDS_GENERAL_CLOSE );
00223                 m_wndOK.SetWindowText( sText );
00224         }
00225 }
00226 
00227 void CGraphListDlg::OnOK()
00228 {
00229         UpdateData();
00230 
00231         m_pGraph->m_bShowAxis           = m_bShowAxis;
00232         m_pGraph->m_bShowGrid           = m_bShowGrid;
00233         m_pGraph->m_bShowLegend         = m_bShowLegend;
00234         m_pGraph->m_nSpeed                      = m_nSpeed;
00235 
00236         m_pGraph->ResetMaximum();
00237 
00238         CSkinDialog::OnOK();
00239 }

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