1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: functions and classes for system power management
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
16 // ----------------------------------------------------------------------------
17 // power management constants
18 // ----------------------------------------------------------------------------
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
36 // ----------------------------------------------------------------------------
37 // wxPowerEvent is generated when the system online status changes
38 // ----------------------------------------------------------------------------
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
46 #define wxHAS_POWER_EVENTS
48 class WXDLLIMPEXP_BASE wxPowerEvent
: public wxEvent
51 wxPowerEvent() // just for use by wxRTTI
54 wxPowerEvent(wxEventType evtType
) : wxEvent(wxID_NONE
, evtType
)
59 // Veto the operation (only makes sense with EVT_POWER_SUSPENDING)
60 void Veto() { m_veto
= true; }
62 bool IsVetoed() const { return m_veto
; }
65 // default copy ctor, assignment operator and dtor are ok
67 virtual wxEvent
*Clone() const { return new wxPowerEvent(*this); }
72 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxPowerEvent
)
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
);
80 typedef void (wxEvtHandler::*wxPowerEventFunction
)(wxPowerEvent
&);
82 #define wxPowerEventHandler(func) \
83 wxEVENT_HANDLER_CAST(wxPowerEventFunction, func)
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))
94 #else // no support for power events
95 #undef wxHAS_POWER_EVENTS
96 #endif // support for power events/no support
98 // ----------------------------------------------------------------------------
99 // power management functions
100 // ----------------------------------------------------------------------------
102 // return the current system power state: online or offline
103 WXDLLIMPEXP_BASE wxPowerType
wxGetPowerType();
105 // return approximate battery state
106 WXDLLIMPEXP_BASE wxBatteryState
wxGetBatteryState();
108 #endif // _WX_POWER_H_