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

PageSettingsScheduler.cpp

Go to the documentation of this file.
00001 //
00002 // PageSettingsScheduler.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 "Scheduler.h"
00026 #include "PageSettingsScheduler.h"
00027 
00028 #ifdef _DEBUG
00029 #define new DEBUG_NEW
00030 #undef THIS_FILE
00031 static char THIS_FILE[] = __FILE__;
00032 #endif
00033 
00034 IMPLEMENT_DYNCREATE(CSchedulerSettingsPage, CSettingsPage)
00035 
00036 BEGIN_MESSAGE_MAP(CSchedulerSettingsPage, CSettingsPage)
00037         //{{AFX_MSG_MAP(CSchedulerSettingsPage)
00038         ON_WM_ERASEBKGND()
00039         ON_WM_PAINT()
00040         ON_WM_MOUSEMOVE()
00041         ON_WM_LBUTTONDOWN()
00042         ON_WM_LBUTTONUP()
00043         ON_WM_LBUTTONDBLCLK()
00044         ON_WM_RBUTTONDOWN()
00045         ON_WM_RBUTTONUP()
00046         //}}AFX_MSG_MAP
00047 END_MESSAGE_MAP()
00048 
00049 
00050 #define HEADING_HEIGHT 32
00051 
00052 
00054 // CSchedulerSettingsPage property page
00055 
00056 CSchedulerSettingsPage::CSchedulerSettingsPage() : CSettingsPage(CSchedulerSettingsPage::IDD)
00057 {
00058         //{{AFX_DATA_INIT(CSchedulerSettingsPage)
00059         m_bSchedulerEnable = FALSE;
00060         m_nLimited = 0;
00061         m_bLimitedNetworks = TRUE;
00062         //}}AFX_DATA_INIT
00063 }
00064 
00065 CSchedulerSettingsPage::~CSchedulerSettingsPage()
00066 {
00067 }
00068 
00069 void CSchedulerSettingsPage::DoDataExchange(CDataExchange* pDX)
00070 {
00071         CSettingsPage::DoDataExchange(pDX);
00072         //{{AFX_DATA_MAP(CSchedulerSettingsPage)
00073         DDX_Check(pDX, IDC_SCHEDULER_ENABLE, m_bSchedulerEnable);
00074         DDX_Text(pDX, IDC_SCHEDULER_LIMITED, m_nLimited);
00075         DDX_Control(pDX, IDC_SCHEDULER_LIMITED_SPIN, m_wndLimitedSpin);
00076         DDX_Check(pDX, IDC_SCHEDULER_LIMITED_NETWORKS, m_bLimitedNetworks);
00077         DDX_Control(pDX, IDC_SCHEDULER_DISPLAY, m_wndDisplay);
00078         //}}AFX_DATA_MAP
00079 }
00080 
00082 // CSchedulerSettingsPage message handlers
00083 
00084 BOOL CSchedulerSettingsPage::OnInitDialog()
00085 {
00086         CSettingsPage::OnInitDialog();
00087 
00088         m_bmHeader.LoadBitmap( IDB_SCHEDULER_HEADER );
00089 
00090         CBitmap bmTimeSlices;
00091         bmTimeSlices.LoadBitmap( IDB_SCHEDULER_TIMESLICES );
00092         m_pTimeSlices.Create( 16, 16, ILC_COLOR24, 3, 0 );
00093         m_pTimeSlices.Add( &bmTimeSlices, RGB( 0, 255, 0 ) );
00094 
00095         CopyMemory( m_pSchedule, Schedule.m_pSchedule, 7 * 24 );
00096 
00097         m_bSchedulerEnable      = Settings.Scheduler.Enable;
00098         m_nLimited                      = Settings.Scheduler.LimitedBandwidth;
00099         m_bLimitedNetworks      = Settings.Scheduler.LimitedNetworks;
00100 
00101         m_nDownDay                      = m_nHoverDay = 0xFF;
00102         m_nDownHour                     = m_nHoverHour = 0xFF;
00103         m_bPaint                        = FALSE;
00104         m_nPaintValue           = 0;
00105 
00106         m_wndLimitedSpin.SetRange( 5, 95 );
00107 
00108         LoadString (m_sDayName[0], IDS_DAY_SUNDAY);
00109         LoadString (m_sDayName[1], IDS_DAY_MONDAY);
00110         LoadString (m_sDayName[2], IDS_DAY_TUESDAY);
00111         LoadString (m_sDayName[3], IDS_DAY_WEDNESDAY);
00112         LoadString (m_sDayName[4], IDS_DAY_THURSDAY);
00113         LoadString (m_sDayName[5], IDS_DAY_FRIDAY);
00114         LoadString (m_sDayName[6], IDS_DAY_SATURDAY);
00115 
00116         UpdateData( FALSE );
00117 
00118         return TRUE;
00119 }
00120 
00121 
00122 void CSchedulerSettingsPage::OnMouseMove(UINT nFlags, CPoint point)
00123 {
00124         CRect rc;
00125         CString strSliceDisplay;
00126 
00127         GetClientRect( &rc );
00128 
00129         rc.top += 10 + HEADING_HEIGHT;
00130         rc.left += 34;
00131 
00132 
00133         rc.bottom = rc.top + ( 7 * 16 );
00134         rc.right = rc.left + ( 24 * 16 );
00135 
00136         if ( rc.PtInRect( point ) )
00137         {
00138                 int nHoverDay = ( point.y - rc.top ) / 16;
00139                 int nHoverHour = ( point.x - rc.left ) / 16;
00140 
00141                 if ( ( nHoverDay != m_nHoverDay ) || ( nHoverHour != m_nHoverHour ) )
00142                 {
00143                         if ( m_bPaint )
00144                         {
00145                                 m_pSchedule[nHoverDay][nHoverHour] = m_nPaintValue;
00146                                 Invalidate();
00147                         }
00148 
00149                         if ( nHoverDay != m_nHoverDay )
00150                         {
00151                                 m_nHoverDay = nHoverDay;
00152 
00153                                 strSliceDisplay.Format(_T("%s, %d:00 - %d:59"), m_sDayName[m_nHoverDay], m_nHoverHour, m_nHoverHour );
00154                                 m_wndDisplay.SetWindowText( strSliceDisplay );
00155 
00156                                 Invalidate();
00157                         }
00158                         if ( nHoverHour != m_nHoverHour )
00159                         {
00160                                 m_nHoverHour = nHoverHour;
00161 
00162                                 strSliceDisplay.Format(_T("%s, %d:00 - %d:59"), m_sDayName[m_nHoverDay], m_nHoverHour, m_nHoverHour );
00163                                 m_wndDisplay.SetWindowText( strSliceDisplay );
00164 
00165                                 Invalidate();
00166                         }
00167                 }
00168         }
00169         else
00170         {
00171                 m_wndDisplay.SetWindowText( _T("") );
00172 
00173                 if ( ( m_nHoverDay != 0xFF ) || ( m_nHoverHour != 0xFF ) )
00174                 {
00175                         m_nHoverDay = m_nHoverHour = 0xFF;
00176                         m_nDownHour = m_nHoverHour      = 0xFF;
00177 
00178                         ReleaseCapture();
00179                         Invalidate();
00180                 }
00181         }
00182 
00183         //CSettingsPage::OnMouseMove( nFlags, point );
00184 }
00185 
00186 
00187 void CSchedulerSettingsPage::OnLButtonDown(UINT nFlags, CPoint point)
00188 {
00189         if ( ( m_nHoverDay == 0xFF ) || ( m_nHoverHour == 0xFF ) ) return;
00190         m_nDownDay              = m_nHoverDay;
00191         m_nDownHour             = m_nHoverHour;
00192         m_bPaint                = TRUE;
00193         m_nPaintValue   = m_pSchedule[m_nHoverDay][m_nHoverHour];
00194         SetCapture();
00195         Invalidate();
00196 }
00197 
00198 void CSchedulerSettingsPage::OnLButtonUp(UINT nFlags, CPoint point)
00199 {
00200         m_bPaint                = FALSE;
00201         m_nPaintValue   = 0;
00202         if ( ( m_nHoverDay == 0xFF ) || ( m_nHoverHour == 0xFF ) ) return;
00203 
00204         if ( m_nDownDay != m_nHoverDay ) return;
00205         if ( m_nDownHour != m_nHoverHour ) return;
00206 
00207 
00208         m_pSchedule[m_nHoverDay][m_nHoverHour] ++;
00209         m_pSchedule[m_nHoverDay][m_nHoverHour] %= 3;
00210 
00211         m_nDownDay              = 0xFF;
00212         m_nDownHour             = 0xFF;
00213 
00214 
00215         ReleaseCapture();
00216         Invalidate();
00217         UpdateWindow();
00218 }
00219 
00220 void CSchedulerSettingsPage::OnLButtonDblClk(UINT nFlags, CPoint point)
00221 {
00222         m_bPaint                = FALSE;
00223         m_nPaintValue   = 0;
00224         if ( ( m_nHoverDay == 0xFF ) || ( m_nHoverHour == 0xFF ) ) return;
00225 
00226         m_pSchedule[m_nHoverDay][m_nHoverHour] ++;
00227         m_pSchedule[m_nHoverDay][m_nHoverHour] %= 3;
00228 
00229         m_nDownDay              = 0xFF;
00230         m_nDownHour             = 0xFF;
00231 
00232         ReleaseCapture();
00233         Invalidate();
00234         UpdateWindow();
00235 }
00236 
00237 void CSchedulerSettingsPage::OnRButtonDown(UINT nFlags, CPoint point)
00238 {
00239         if ( ( m_nHoverDay == 0xFF ) || ( m_nHoverHour == 0xFF ) ) return;
00240         m_nDownDay              = m_nHoverDay;
00241         m_nDownHour             = m_nHoverHour;
00242         m_bPaint                = TRUE;
00243         m_nPaintValue   = m_pSchedule[m_nHoverDay][m_nHoverHour];
00244         SetCapture();
00245         Invalidate();
00246 }
00247 
00248 void CSchedulerSettingsPage::OnRButtonUp(UINT nFlags, CPoint point)
00249 {
00250         m_bPaint                = FALSE;
00251         m_nPaintValue   = 0;
00252         if ( ( m_nHoverDay == 0xFF ) || ( m_nHoverHour == 0xFF ) ) return;
00253 
00254         if ( m_nDownDay != m_nHoverDay ) return;
00255         if ( m_nDownHour != m_nHoverHour ) return;
00256 
00257         m_pSchedule[m_nHoverDay][m_nHoverHour] += 2;
00258         m_pSchedule[m_nHoverDay][m_nHoverHour] %= 3;
00259 
00260         m_nDownDay              = 0xFF;
00261         m_nDownHour             = 0xFF;
00262 
00263 
00264         ReleaseCapture();
00265         Invalidate();
00266         UpdateWindow();
00267 }
00268 
00269 BOOL CSchedulerSettingsPage::OnEraseBkgnd(CDC* pDC)
00270 {
00271         return TRUE;
00272 }
00273 
00274 void CSchedulerSettingsPage::OnPaint()
00275 {
00276         // Draw the schedule box
00277         int nDay, nHour;
00278         CPaintDC dc( this );
00279         CRect rc;
00280         GetClientRect( &rc );
00281 
00282         rc.top += 10;
00283         rc.left += 34;
00284         CDC mdc;
00285         mdc.CreateCompatibleDC( &dc );
00286 
00287         CBitmap* pOldBmp = (CBitmap*)mdc.SelectObject( &m_bmHeader );
00288         dc.BitBlt( rc.left, rc.top, 385, HEADING_HEIGHT, &mdc, 0, 0, SRCCOPY );
00289         mdc.SelectObject( pOldBmp );
00290         mdc.DeleteDC();
00291         rc.top += HEADING_HEIGHT;
00292 
00293         for ( nDay = 0 ; nDay < 7 ; nDay++ )
00294         {
00295                 for ( nHour = 0 ; nHour < 24 ; nHour++ )
00296                 {
00297                         if ( ( nDay == m_nHoverDay ) && ( nHour == m_nHoverHour ) )
00298                                 ImageList_DrawEx( m_pTimeSlices, m_pSchedule[nDay][nHour], dc.GetSafeHdc(), rc.left + ( nHour * 16 ),
00299                                         rc.top + ( nDay * 16 ) , 16, 16, CLR_DEFAULT, RGB( 180, 180, 180), ILD_SELECTED );
00300                         else
00301                                 ImageList_DrawEx( m_pTimeSlices, m_pSchedule[nDay][nHour], dc.GetSafeHdc(), rc.left + ( nHour * 16 ),
00302                                         rc.top + ( nDay * 16 ) , 16, 16, CLR_DEFAULT, CLR_DEFAULT, ILD_NORMAL );
00303                 }
00304         }
00305 
00306         // Draw the border of the box
00307         dc.Draw3dRect( 33, 9, 385, 145, RGB( 0, 0, 0 ), RGB( 0, 0, 0 ) );
00308 
00309         // Draw the schedule time slices for the 'key'
00310         LONG nYpos = ( rc.bottom / 2 ) + 7; 
00311 
00312         ImageList_DrawEx( m_pTimeSlices, SCHEDULE_OFF, dc.GetSafeHdc(),
00313                                         30 , nYpos , 16, 16, CLR_DEFAULT, CLR_DEFAULT, ILD_NORMAL );
00314 
00315         ImageList_DrawEx( m_pTimeSlices, SCHEDULE_LIMITED_SPEED, dc.GetSafeHdc(),
00316                                         30 , nYpos + 20 , 16, 16, CLR_DEFAULT, CLR_DEFAULT, ILD_NORMAL );
00317 
00318         ImageList_DrawEx( m_pTimeSlices, SCHEDULE_FULL_SPEED  , dc.GetSafeHdc(),
00319                                         30 , nYpos + 40 , 16, 16, CLR_DEFAULT, CLR_DEFAULT, ILD_NORMAL );
00320 
00321         //CSettingsPage::OnPaint();
00322 }
00323 
00324 void CSchedulerSettingsPage::OnOK()
00325 {
00326         UpdateData();
00327 
00328         Settings.Scheduler.Enable                       = m_bSchedulerEnable;
00329         Settings.Scheduler.LimitedBandwidth = m_nLimited;
00330         Settings.Scheduler.LimitedNetworks      = m_bLimitedNetworks;
00331 
00332         CopyMemory( Schedule.m_pSchedule , m_pSchedule, 7 * 24 );
00333         Schedule.Save();
00334 
00335         CSettingsPage::OnOK();
00336 }

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