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 "Settings.h"
00025 #include "GraphItem.h"
00026 #include "DlgGraphItem.h"
00027 #include "Skin.h"
00028
00029 #ifdef _DEBUG
00030 #define new DEBUG_NEW
00031 #undef THIS_FILE
00032 static char THIS_FILE[] = __FILE__;
00033 #endif
00034
00035 BEGIN_MESSAGE_MAP(CGraphItemDlg, CSkinDialog)
00036
00037 ON_CBN_SELCHANGE(IDC_GRAPH_SOURCE, OnSelChangeGraphSource)
00038 ON_BN_CLICKED(IDC_GRAPH_COLOUR, OnGraphColour)
00039 ON_WM_PAINT()
00040 ON_WM_MEASUREITEM()
00041 ON_WM_DRAWITEM()
00042
00043 END_MESSAGE_MAP()
00044
00045
00047
00048
00049 CGraphItemDlg::CGraphItemDlg(CWnd* pParent, CGraphItem* pItem) : CSkinDialog(CGraphItemDlg::IDD, pParent)
00050 {
00051
00052
00053 m_pItem = pItem;
00054 }
00055
00056 void CGraphItemDlg::DoDataExchange(CDataExchange* pDX)
00057 {
00058 CSkinDialog::DoDataExchange(pDX);
00059
00060 DDX_Control(pDX, IDOK, m_wndOK);
00061 DDX_Control(pDX, IDC_GRAPH_UNITS, m_wndUnits);
00062 DDX_Control(pDX, IDC_GRAPH_SOURCE, m_wndSource);
00063 DDX_Control(pDX, IDC_GRAPH_REMOVE, m_wndRemove);
00064 DDX_Control(pDX, IDC_GRAPH_PARAM, m_wndParam);
00065 DDX_Control(pDX, IDC_GRAPH_COLOUR_BOX, m_wndColourBox);
00066
00067 }
00068
00070
00071
00072 BOOL CGraphItemDlg::OnInitDialog()
00073 {
00074 CSkinDialog::OnInitDialog();
00075
00076 SkinMe( _T("CGraphItemDlg"), IDR_TRAFFICFRAME );
00077
00078 m_gdiImageList.Create( 16, 16, ILC_COLOR32|ILC_MASK, 1, 1 );
00079 m_gdiImageList.Add( theApp.LoadIcon( IDR_TRAFFICFRAME ) );
00080
00081 for ( int nItem = 1 ; CGraphItem::m_pItemDesc[ nItem ].m_nCode ; nItem++ )
00082 {
00083 GRAPHITEM* pItem = &CGraphItem::m_pItemDesc[ nItem ];
00084 CString strItem;
00085
00086 ::Skin.LoadString( strItem, pItem->m_nStringID );
00087 int nIndex = m_wndSource.AddString( strItem );
00088 m_wndSource.SetItemData( nIndex, (LPARAM)pItem );
00089
00090 if ( pItem->m_nCode == m_pItem->m_nCode ) m_wndSource.SetCurSel( nIndex );
00091 }
00092
00093 m_crColour = m_pItem->m_nColour;
00094
00095 OnSelChangeGraphSource();
00096
00097 return TRUE;
00098 }
00099
00100 void CGraphItemDlg::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
00101 {
00102 lpMeasureItemStruct->itemWidth = 1024;
00103 lpMeasureItemStruct->itemHeight = 18;
00104 }
00105
00106 void CGraphItemDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
00107 {
00108 if ( lpDrawItemStruct->itemID == (UINT)-1 ) return;
00109 if ( ( lpDrawItemStruct->itemAction & ODA_SELECT ) == 0 &&
00110 ( lpDrawItemStruct->itemAction & ODA_DRAWENTIRE ) == 0 ) return;
00111
00112 CRect rcItem( &lpDrawItemStruct->rcItem );
00113 CDC dc;
00114
00115 dc.Attach( lpDrawItemStruct->hDC );
00116
00117 dc.FillSolidRect( &rcItem,
00118 GetSysColor( ( lpDrawItemStruct->itemState & ODS_SELECTED )
00119 ? COLOR_HIGHLIGHT : COLOR_WINDOW ) );
00120
00121 dc.SetTextColor( GetSysColor( ( lpDrawItemStruct->itemState & ODS_SELECTED )
00122 ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT ) );
00123
00124 dc.SetBkMode( TRANSPARENT );
00125
00126 CPoint pt( rcItem.left + 1, rcItem.top + 1 );
00127
00128 ImageList_Draw( m_gdiImageList.GetSafeHandle(),
00129 0, dc.GetSafeHdc(), pt.x, pt.y,
00130 ( lpDrawItemStruct->itemState & ODS_SELECTED ) ? ILD_SELECTED : ILD_NORMAL );
00131
00132 rcItem.left += 20; rcItem.right -= 2;
00133
00134 CString strText;
00135 m_wndSource.GetLBText( lpDrawItemStruct->itemID, strText );
00136
00137 CFont* pOldFont = (CFont*)dc.SelectObject( &theApp.m_gdiFont );
00138 dc.DrawText( strText, &rcItem, DT_SINGLELINE|DT_LEFT|DT_VCENTER|DT_NOPREFIX );
00139 dc.SelectObject( pOldFont );
00140
00141 dc.Detach();
00142 }
00143
00144 void CGraphItemDlg::OnSelChangeGraphSource()
00145 {
00146 int nItem = m_wndSource.GetCurSel();
00147 if ( nItem < 0 ) return;
00148
00149 GRAPHITEM* pItem = (GRAPHITEM*)m_wndSource.GetItemData( nItem );
00150 if ( ! pItem ) return;
00151
00152 switch ( pItem->m_nUnits )
00153 {
00154 case 0:
00155 m_wndUnits.SetWindowText( _T("Items") );
00156 break;
00157 case 1:
00158 m_wndUnits.SetWindowText( Settings.General.RatesInBytes ? _T("Bytes per Second") : _T("Bits per Second") );
00159 break;
00160 case 2:
00161 m_wndUnits.SetWindowText( _T("Volume (B/KB/MB/GB/TB") );
00162 break;
00163 default:
00164 m_wndUnits.SetWindowText( _T("") );
00165 break;
00166 }
00167
00168 m_wndOK.EnableWindow( TRUE );
00169 }
00170
00171 void CGraphItemDlg::OnGraphColour()
00172 {
00173 CColorDialog dlg( m_crColour, CC_ANYCOLOR|CC_SOLIDCOLOR, this );
00174
00175 if ( dlg.DoModal() == IDOK )
00176 {
00177 m_crColour = dlg.GetColor();
00178 Invalidate();
00179 }
00180 }
00181
00182 void CGraphItemDlg::OnPaint()
00183 {
00184 CPaintDC dc( this );
00185 CRect rc;
00186
00187 m_wndColourBox.GetWindowRect( &rc );
00188 ScreenToClient( &rc );
00189
00190 dc.Draw3dRect( &rc, 0, 0 );
00191 rc.DeflateRect( 1, 1 );
00192 dc.FillSolidRect( &rc, 0 );
00193 dc.Draw3dRect( rc.left, ( rc.top + rc.bottom ) / 2, rc.Width() + 1, 2, m_crColour, 0 );
00194 }
00195
00196 void CGraphItemDlg::OnOK()
00197 {
00198 int nItem = m_wndSource.GetCurSel();
00199 if ( nItem < 0 ) return;
00200
00201 GRAPHITEM* pItem = (GRAPHITEM*)m_wndSource.GetItemData( nItem );
00202 if ( ! pItem ) return;
00203
00204 m_pItem->SetCode( pItem->m_nCode );
00205 m_pItem->m_nColour = m_crColour;
00206
00207 CSkinDialog::OnOK();
00208 }