/*************************************************************************** * Copyright (C) 2007 by Torben Nielsen * * torben@t-hoerup.dk * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #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( ) : 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 )*/ ) { mTimer.Stop(); delete mTrayIcon; mTrayIcon = 0; Close(TRUE); wxExit(); } void wxCpuThrottleFrame::OnClose( wxCloseEvent& WXUNUSED( event ) ) { 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() ); }