--- wxCpuThrottle/src/wxcputhrottleframe.cpp 2007/08/09 17:14:40 21 +++ wxCpuThrottle/src/wxcputhrottleframe.cpp 2009/04/09 18:39:29 221 @@ -21,23 +21,85 @@ #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() -wxCpuThrottleFrame::wxCpuThrottleFrame( const wxString& title, const wxPoint& pos, const wxSize& size ) - : wxDialog((wxDialog *)NULL, -1, title, pos, size), - mIcon(SysMetrix_xpm) + + +wxCpuThrottleFrame::wxCpuThrottleFrame( ) + : wxDialog(NULL, -1, wxT("wxCpuThrottle"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE ), + mIcon(SysMetrix_xpm), + mWritable(true), + mTimer(this, ID_TIMER) { + try + { + mParser.ReadAcpiFile(); + } + catch ( ... ) + { + wxMessageBox(wxT("Could not open kernel file - aborting program")); + OnQuit(); + } + + try + { + mParser.SetState( mParser.GetCurrentState() ); + } + catch ( ...) + { + mWritable = false; + } + + SetIcon(mIcon); + mTrayIcon = new TrayIcon(this); mTrayIcon->SetIcon(mIcon,wxT("wxCpuThrottle") ); + + wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL ); + + + 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; @@ -51,6 +113,19 @@ Show(false); } +void wxCpuThrottleFrame::OnTimer( wxTimerEvent& WXUNUSED(event) ) +{ + mParser.ReadAcpiFile(); + mButtonbox->SetSelection( mParser.GetCurrentState() ); + + std::string statedesc = mParser.GetStateDescription( mParser.GetCurrentState() ); + + wxString tooltip = wxT("wxCpuThrottle - "); + tooltip += wxString(statedesc.c_str(), wxConvISO8859_1); + + mTrayIcon->SetIcon( mIcon, tooltip ); +} + void wxCpuThrottleFrame::SetPosition() { const int freeBorder = 20; @@ -58,3 +133,9 @@ wxSize mySize = GetSize(); Move(screenSize.GetWidth()-mySize.GetWidth() - freeBorder, screenSize.GetHeight() - mySize.GetHeight() - freeBorder); } + + +void wxCpuThrottleFrame::OnRadiobutton(wxCommandEvent& event) +{ + mParser.SetState( mButtonbox->GetSelection() ); +}