--- wxCpuThrottle/src/wxcputhrottleframe.cpp 2007/08/09 20:57:19 24 +++ wxCpuThrottle/src/wxcputhrottleframe.cpp 2007/08/10 18:12:36 25 @@ -21,22 +21,51 @@ #include "wxcputhrottleframe.h" #include "SysMetrix.xpm" +#include //togglebutton + + +enum +{ + ID_SLIDER = 2000, + ID_RADIOBOX, + ID_TIMER +}; BEGIN_EVENT_TABLE( wxCpuThrottleFrame, wxDialog ) EVT_CLOSE( wxCpuThrottleFrame::OnClose ) + EVT_TIMER( ID_TIMER, wxCpuThrottleFrame::OnTimer ) + EVT_RADIOBOX( ID_RADIOBOX, wxCpuThrottleFrame::OnRadiobutton) END_EVENT_TABLE() -enum -{ - ID_SLIDER = 2000 -}; + wxCpuThrottleFrame::wxCpuThrottleFrame( ) - : wxDialog(NULL, -1, wxT("wxCpuThrottle"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), - mIcon(SysMetrix_xpm) + : wxDialog(NULL, -1, wxT("wxCpuThrottle"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE ), + mIcon(SysMetrix_xpm), + mWritable(true), + mTimer(this, ID_TIMER) { - mParser.ReadAcpiFile(); + try + { + mParser.ReadAcpiFile(); + } + catch ( ... ) + { + wxMessageBox("Could not open kernel file - aborting program"); + OnQuit(); + } + + try + { + mParser.SetState( mParser.GetCurrentState() ); + } + catch ( ...) + { + mWritable = false; + } + + SetIcon(mIcon); mTrayIcon = new TrayIcon(this); @@ -44,18 +73,32 @@ wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL ); - wxSlider* slider = new wxSlider(this, ID_SLIDER, mParser.GetCurrentState(), 0, mParser.GetStateCount()-1, wxDefaultPosition, wxSize(80,200), wxSL_VERTICAL|wxSL_AUTOTICKS|wxSL_LEFT|wxSL_LABELS); - mainSizer->Add(slider, 1, wxEXPAND,0); + + wxArrayString strings; + strings.Alloc(mParser.GetStateCount() ); + + for (int i=0; iEnable( mWritable ); + + mainSizer->Add( mButtonbox, 1, wxEXPAND,0); SetSizer(mainSizer); mainSizer->SetSizeHints(this ); + mTimer.Start(1000); + } -void wxCpuThrottleFrame::OnQuit( wxCommandEvent& WXUNUSED( event ) ) +void wxCpuThrottleFrame::OnQuit( /*wxCommandEvent& WXUNUSED( event )*/ ) { + mTimer.Stop(); delete mTrayIcon; mTrayIcon = 0; @@ -69,6 +112,17 @@ Show(false); } +void wxCpuThrottleFrame::OnTimer( wxTimerEvent& WXUNUSED(event) ) +{ + mParser.ReadAcpiFile(); + mButtonbox->SetSelection( mParser.GetCurrentState() ); + + wxString tooltip = wxT("wxCpuThrottle - "); + tooltip += mParser.GetStateDescription( mParser.GetCurrentState() ); + + mTrayIcon->SetIcon( mIcon, tooltip ); +} + void wxCpuThrottleFrame::SetPosition() { const int freeBorder = 20; @@ -76,3 +130,9 @@ wxSize mySize = GetSize(); Move(screenSize.GetWidth()-mySize.GetWidth() - freeBorder, screenSize.GetHeight() - mySize.GetHeight() - freeBorder); } + + +void wxCpuThrottleFrame::OnRadiobutton(wxCommandEvent& event) +{ + mParser.SetState( mButtonbox->GetSelection() ); +}