]> git.saurik.com Git - wxWidgets.git/blob - include/wx/power.h
Don't define __STRICT_ANSI__, we should build both with and without it.
[wxWidgets.git] / include / wx / power.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/power.h
3 // Purpose: functions and classes for system power management
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 2006-05-27
7 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_POWER_H_
12 #define _WX_POWER_H_
13
14 #include "wx/event.h"
15
16 // ----------------------------------------------------------------------------
17 // power management constants
18 // ----------------------------------------------------------------------------
19
20 enum wxPowerType
21 {
22 wxPOWER_SOCKET,
23 wxPOWER_BATTERY,
24 wxPOWER_UNKNOWN
25 };
26
27 enum wxBatteryState
28 {
29 wxBATTERY_NORMAL_STATE, // system is fully usable
30 wxBATTERY_LOW_STATE, // start to worry
31 wxBATTERY_CRITICAL_STATE, // save quickly
32 wxBATTERY_SHUTDOWN_STATE, // too late
33 wxBATTERY_UNKNOWN_STATE
34 };
35
36 // ----------------------------------------------------------------------------
37 // wxPowerEvent is generated when the system online status changes
38 // ----------------------------------------------------------------------------
39
40 // currently the power events are only available under Windows, to avoid
41 // compiling in the code for handling them which is never going to be invoked
42 // under the other platforms, we define wxHAS_POWER_EVENTS symbol if this event
43 // is available, it should be used to guard all code using wxPowerEvent
44 #ifdef __WINDOWS__
45
46 #define wxHAS_POWER_EVENTS
47
48 class WXDLLIMPEXP_BASE wxPowerEvent : public wxEvent
49 {
50 public:
51 wxPowerEvent() // just for use by wxRTTI
52 : m_veto(false) { }
53
54 wxPowerEvent(wxEventType evtType) : wxEvent(wxID_NONE, evtType)
55 {
56 m_veto = false;
57 }
58
59 // Veto the operation (only makes sense with EVT_POWER_SUSPENDING)
60 void Veto() { m_veto = true; }
61
62 bool IsVetoed() const { return m_veto; }
63
64
65 // default copy ctor, assignment operator and dtor are ok
66
67 virtual wxEvent *Clone() const { return new wxPowerEvent(*this); }
68
69 private:
70 bool m_veto;
71
72 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxPowerEvent)
73 };
74
75 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_BASE, wxEVT_POWER_SUSPENDING, wxPowerEvent );
76 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_BASE, wxEVT_POWER_SUSPENDED, wxPowerEvent );
77 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_BASE, wxEVT_POWER_SUSPEND_CANCEL, wxPowerEvent );
78 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_BASE, wxEVT_POWER_RESUME, wxPowerEvent );
79
80 typedef void (wxEvtHandler::*wxPowerEventFunction)(wxPowerEvent&);
81
82 #define wxPowerEventHandler(func) \
83 wxEVENT_HANDLER_CAST(wxPowerEventFunction, func)
84
85 #define EVT_POWER_SUSPENDING(func) \
86 wx__DECLARE_EVT0(wxEVT_POWER_SUSPENDING, wxPowerEventHandler(func))
87 #define EVT_POWER_SUSPENDED(func) \
88 wx__DECLARE_EVT0(wxEVT_POWER_SUSPENDED, wxPowerEventHandler(func))
89 #define EVT_POWER_SUSPEND_CANCEL(func) \
90 wx__DECLARE_EVT0(wxEVT_POWER_SUSPEND_CANCEL, wxPowerEventHandler(func))
91 #define EVT_POWER_RESUME(func) \
92 wx__DECLARE_EVT0(wxEVT_POWER_RESUME, wxPowerEventHandler(func))
93
94 #else // no support for power events
95 #undef wxHAS_POWER_EVENTS
96 #endif // support for power events/no support
97
98 // ----------------------------------------------------------------------------
99 // power management functions
100 // ----------------------------------------------------------------------------
101
102 // return the current system power state: online or offline
103 WXDLLIMPEXP_BASE wxPowerType wxGetPowerType();
104
105 // return approximate battery state
106 WXDLLIMPEXP_BASE wxBatteryState wxGetBatteryState();
107
108 #endif // _WX_POWER_H_