]> git.saurik.com Git - wxWidgets.git/blob - samples/power/power.cpp
04b9ab3c63ce71d6485e21e8deb44635c13b0f4a
[wxWidgets.git] / samples / power / power.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: power.cpp
3 // Purpose: wxWidgets power management sample
4 // Author: Vadim Zeitlin
5 // Created: 2006-05-27
6 // RCS-ID: $Id$
7 // Copyright: (C) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #include "wx/wxprec.h"
20
21 #ifdef __BORLANDC__
22 #pragma hdrstop
23 #endif
24
25 #ifndef WX_PRECOMP
26 #include "wx/app.h"
27 #include "wx/frame.h"
28 #endif
29
30 #include "wx/textctrl.h"
31 #include "wx/msgdlg.h"
32
33 #include "wx/power.h"
34
35 #if !defined(__WXMSW__) && !defined(__WXPM__)
36 #include "../sample.xpm"
37 #endif
38
39 // ----------------------------------------------------------------------------
40 // main frame class
41 // ----------------------------------------------------------------------------
42
43 class MyFrame : public wxFrame
44 {
45 public:
46 MyFrame()
47 : wxFrame(NULL, wxID_ANY, _T("wxWidgets Power Management Sample"),
48 wxDefaultPosition, wxSize(500, 200))
49 {
50 wxTextCtrl *text = new wxTextCtrl(this, wxID_ANY, _T(""),
51 wxDefaultPosition, wxDefaultSize,
52 wxTE_MULTILINE | wxTE_READONLY);
53 m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(text));
54
55 SetIcon(wxICON(sample));
56
57 Show();
58 }
59
60 virtual ~MyFrame()
61 {
62 delete wxLog::SetActiveTarget(m_logOld);
63 }
64
65 private:
66 void OnSuspending(wxPowerEvent& event)
67 {
68 wxLogMessage(_T("System suspend starting..."));
69 if ( wxMessageBox(_T("Veto suspend?"), _T("Please answer"),
70 wxYES_NO, this) == wxYES )
71 {
72 event.Veto();
73 wxLogMessage(_T("Vetoed suspend."));
74 }
75 }
76
77 void OnSuspended(wxPowerEvent& WXUNUSED(event))
78 {
79 wxLogMessage(_T("System is going to suspend."));
80 }
81
82 void OnSuspendCancel(wxPowerEvent& WXUNUSED(event))
83 {
84 wxLogMessage(_T("System suspend was cancelled."));
85 }
86
87 void OnResume(wxPowerEvent& WXUNUSED(event))
88 {
89 wxLogMessage(_T("System resumed from suspend."));
90 }
91
92
93 wxLog *m_logOld;
94
95 DECLARE_EVENT_TABLE()
96 };
97
98 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
99 EVT_POWER_SUSPENDING(MyFrame::OnSuspending)
100 EVT_POWER_SUSPENDED(MyFrame::OnSuspended)
101 EVT_POWER_SUSPEND_CANCEL(MyFrame::OnSuspendCancel)
102 EVT_POWER_RESUME(MyFrame::OnResume)
103 END_EVENT_TABLE()
104
105 // ----------------------------------------------------------------------------
106 // main application class
107 // ----------------------------------------------------------------------------
108
109 class MyApp : public wxApp
110 {
111 public:
112 virtual bool OnInit()
113 {
114 new MyFrame;
115
116 return true;
117 }
118 };
119
120 IMPLEMENT_APP(MyApp)