/[projects]/wxCpuThrottle/src/wxcputhrottleframe.cpp
ViewVC logotype

Diff of /wxCpuThrottle/src/wxcputhrottleframe.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 20 by torben, Wed Aug 8 21:00:34 2007 UTC revision 221 by torben, Thu Apr 9 18:39:29 2009 UTC
# Line 20  Line 20 
20    
21  #include "wxcputhrottleframe.h"  #include "wxcputhrottleframe.h"
22    
23    #include "SysMetrix.xpm"
24    #include <wx/tglbtn.h> //togglebutton
25    
26    
27    enum
28    {
29            ID_SLIDER = 2000,
30            ID_RADIOBOX,
31            ID_TIMER        
32    };
33    
34  BEGIN_EVENT_TABLE( wxCpuThrottleFrame, wxDialog )  BEGIN_EVENT_TABLE( wxCpuThrottleFrame, wxDialog )
35          EVT_CLOSE( wxCpuThrottleFrame::OnClose )          EVT_CLOSE( wxCpuThrottleFrame::OnClose )
36            EVT_TIMER( ID_TIMER, wxCpuThrottleFrame::OnTimer )
37            EVT_RADIOBOX( ID_RADIOBOX, wxCpuThrottleFrame::OnRadiobutton)
38  END_EVENT_TABLE()  END_EVENT_TABLE()
39    
40    
41  wxCpuThrottleFrame::wxCpuThrottleFrame( const wxString& title, const wxPoint& pos, const wxSize& size )  
42          : wxDialog((wxDialog *)NULL, -1, title, pos, size)  
43          //mTrayIcon(this)  wxCpuThrottleFrame::wxCpuThrottleFrame( )
44  {                : wxDialog(NULL, -1, wxT("wxCpuThrottle"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE ),
45            mIcon(SysMetrix_xpm),
46            mWritable(true),
47            mTimer(this, ID_TIMER)
48    {
49            try
50            {
51                    mParser.ReadAcpiFile();
52            }
53            catch ( ... )
54            {
55                    wxMessageBox(wxT("Could not open kernel file - aborting program"));
56                    OnQuit();
57            }
58            
59            try
60            {
61                    mParser.SetState( mParser.GetCurrentState() );
62            }
63            catch ( ...)
64            {
65                    mWritable = false;
66            }
67            
68            
69            SetIcon(mIcon);
70            
71          mTrayIcon = new TrayIcon(this);          mTrayIcon = new TrayIcon(this);
72          mTrayIcon->SetIcon(mIcon,wxT("wxCpuThrottle") );          mTrayIcon->SetIcon(mIcon,wxT("wxCpuThrottle") );
73            
74            wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL );
75            
76    
77            wxArrayString strings;
78            strings.Alloc(mParser.GetStateCount() );
79            
80            for (int i=0; i<mParser.GetStateCount() ; i++)
81            {
82                    std::string statedesc = mParser.GetStateDescription(i);
83                    strings.Add( wxString(statedesc.c_str(),wxConvISO8859_1) );
84            }
85            
86            mButtonbox = new wxRadioBox(this, ID_RADIOBOX, wxT("Throttle values"), wxDefaultPosition, wxDefaultSize,strings,1);
87            
88            mButtonbox->Enable( mWritable );
89            
90            mainSizer->Add( mButtonbox, 1, wxEXPAND,0);
91            
92            SetSizer(mainSizer);
93            mainSizer->SetSizeHints(this );
94            
95            mTimer.Start(1000);
96            
97            
98  }  }
99    
100  void wxCpuThrottleFrame::OnQuit( wxCommandEvent& WXUNUSED( event ) )  void wxCpuThrottleFrame::OnQuit( /*wxCommandEvent& WXUNUSED( event )*/ )
101  {  {
102            mTimer.Stop();
103          delete mTrayIcon;          delete mTrayIcon;
104            mTrayIcon = 0;
105            
106          Close(TRUE);          Close(TRUE);
107          wxExit();          wxExit();
108                    
# Line 46  void wxCpuThrottleFrame::OnClose( wxClos Line 113  void wxCpuThrottleFrame::OnClose( wxClos
113          Show(false);          Show(false);
114  }  }
115    
116    void wxCpuThrottleFrame::OnTimer( wxTimerEvent& WXUNUSED(event) )
117    {
118            mParser.ReadAcpiFile();
119            mButtonbox->SetSelection( mParser.GetCurrentState() );
120    
121            std::string statedesc = mParser.GetStateDescription( mParser.GetCurrentState() );
122            
123            wxString tooltip = wxT("wxCpuThrottle - ");
124            tooltip += wxString(statedesc.c_str(), wxConvISO8859_1);
125            
126            mTrayIcon->SetIcon( mIcon, tooltip );
127    }
128    
129    void wxCpuThrottleFrame::SetPosition()
130    {
131            const int freeBorder = 20;
132            wxSize screenSize = ::wxGetDisplaySize();
133            wxSize mySize = GetSize();
134            Move(screenSize.GetWidth()-mySize.GetWidth() - freeBorder, screenSize.GetHeight() - mySize.GetHeight() - freeBorder);
135    }
136    
137    
138    void wxCpuThrottleFrame::OnRadiobutton(wxCommandEvent& event)
139    {
140        mParser.SetState( mButtonbox->GetSelection() );
141    }

Legend:
Removed from v.20  
changed lines
  Added in v.221

  ViewVC Help
Powered by ViewVC 1.1.20