--- wxCpuThrottle/src/wxcputhrottleframe.cpp 2007/08/08 21:00:34 20 +++ wxCpuThrottle/src/wxcputhrottleframe.cpp 2007/08/10 18:12:36 25 @@ -20,22 +20,88 @@ #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) - //mTrayIcon(this) -{ + + +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("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; + Close(TRUE); wxExit(); @@ -46,4 +112,27 @@ 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; + wxSize screenSize = ::wxGetDisplaySize(); + wxSize mySize = GetSize(); + Move(screenSize.GetWidth()-mySize.GetWidth() - freeBorder, screenSize.GetHeight() - mySize.GetHeight() - freeBorder); +} + +void wxCpuThrottleFrame::OnRadiobutton(wxCommandEvent& event) +{ + mParser.SetState( mButtonbox->GetSelection() ); +}