21 |
#include "wxcputhrottleframe.h" |
#include "wxcputhrottleframe.h" |
22 |
|
|
23 |
#include "SysMetrix.xpm" |
#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 |
mIcon(SysMetrix_xpm) |
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("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); |
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 |
|
strings.Add( mParser.GetStateDescription(i) ); |
83 |
|
} |
84 |
|
|
85 |
|
mButtonbox = new wxRadioBox(this, ID_RADIOBOX, wxT("Throttle values"), wxDefaultPosition, wxDefaultSize,strings,1); |
86 |
|
|
87 |
|
mButtonbox->Enable( mWritable ); |
88 |
|
|
89 |
|
mainSizer->Add( mButtonbox, 1, wxEXPAND,0); |
90 |
|
|
91 |
|
SetSizer(mainSizer); |
92 |
|
mainSizer->SetSizeHints(this ); |
93 |
|
|
94 |
|
mTimer.Start(1000); |
95 |
|
|
96 |
|
|
97 |
} |
} |
98 |
|
|
99 |
void wxCpuThrottleFrame::OnQuit( wxCommandEvent& WXUNUSED( event ) ) |
void wxCpuThrottleFrame::OnQuit( /*wxCommandEvent& WXUNUSED( event )*/ ) |
100 |
{ |
{ |
101 |
|
mTimer.Stop(); |
102 |
delete mTrayIcon; |
delete mTrayIcon; |
103 |
mTrayIcon = 0; |
mTrayIcon = 0; |
104 |
|
|
112 |
Show(false); |
Show(false); |
113 |
} |
} |
114 |
|
|
115 |
|
void wxCpuThrottleFrame::OnTimer( wxTimerEvent& WXUNUSED(event) ) |
116 |
|
{ |
117 |
|
mParser.ReadAcpiFile(); |
118 |
|
mButtonbox->SetSelection( mParser.GetCurrentState() ); |
119 |
|
|
120 |
|
wxString tooltip = wxT("wxCpuThrottle - "); |
121 |
|
tooltip += mParser.GetStateDescription( mParser.GetCurrentState() ); |
122 |
|
|
123 |
|
mTrayIcon->SetIcon( mIcon, tooltip ); |
124 |
|
} |
125 |
|
|
126 |
void wxCpuThrottleFrame::SetPosition() |
void wxCpuThrottleFrame::SetPosition() |
127 |
{ |
{ |
128 |
const int freeBorder = 20; |
const int freeBorder = 20; |
130 |
wxSize mySize = GetSize(); |
wxSize mySize = GetSize(); |
131 |
Move(screenSize.GetWidth()-mySize.GetWidth() - freeBorder, screenSize.GetHeight() - mySize.GetHeight() - freeBorder); |
Move(screenSize.GetWidth()-mySize.GetWidth() - freeBorder, screenSize.GetHeight() - mySize.GetHeight() - freeBorder); |
132 |
} |
} |
133 |
|
|
134 |
|
|
135 |
|
void wxCpuThrottleFrame::OnRadiobutton(wxCommandEvent& event) |
136 |
|
{ |
137 |
|
mParser.SetState( mButtonbox->GetSelection() ); |
138 |
|
} |