2006-05-27 14:09:40 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2006-05-29 07:36:41 +00:00
|
|
|
// Name: wx/power.h
|
2006-05-27 14:09:40 +00:00
|
|
|
// Purpose: functions and classes for system power management
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 2006-05-27
|
2019-04-22 12:12:05 +00:00
|
|
|
// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwidgets.org>
|
2006-05-27 14:09:40 +00:00
|
|
|
// Licence: wxWindows licence
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_POWER_H_
|
|
|
|
#define _WX_POWER_H_
|
|
|
|
|
|
|
|
#include "wx/event.h"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// power management constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum wxPowerType
|
|
|
|
{
|
|
|
|
wxPOWER_SOCKET,
|
|
|
|
wxPOWER_BATTERY,
|
|
|
|
wxPOWER_UNKNOWN
|
|
|
|
};
|
|
|
|
|
|
|
|
enum wxBatteryState
|
|
|
|
{
|
|
|
|
wxBATTERY_NORMAL_STATE, // system is fully usable
|
|
|
|
wxBATTERY_LOW_STATE, // start to worry
|
|
|
|
wxBATTERY_CRITICAL_STATE, // save quickly
|
|
|
|
wxBATTERY_SHUTDOWN_STATE, // too late
|
|
|
|
wxBATTERY_UNKNOWN_STATE
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxPowerEvent is generated when the system online status changes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// currently the power events are only available under Windows, to avoid
|
|
|
|
// compiling in the code for handling them which is never going to be invoked
|
|
|
|
// under the other platforms, we define wxHAS_POWER_EVENTS symbol if this event
|
|
|
|
// is available, it should be used to guard all code using wxPowerEvent
|
2012-03-04 00:29:31 +00:00
|
|
|
#ifdef __WINDOWS__
|
2006-05-27 14:09:40 +00:00
|
|
|
|
|
|
|
#define wxHAS_POWER_EVENTS
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxPowerEvent : public wxEvent
|
|
|
|
{
|
|
|
|
public:
|
2008-12-28 01:29:37 +00:00
|
|
|
wxPowerEvent() // just for use by wxRTTI
|
|
|
|
: m_veto(false) { }
|
|
|
|
|
2006-05-27 14:09:40 +00:00
|
|
|
wxPowerEvent(wxEventType evtType) : wxEvent(wxID_NONE, evtType)
|
|
|
|
{
|
|
|
|
m_veto = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Veto the operation (only makes sense with EVT_POWER_SUSPENDING)
|
|
|
|
void Veto() { m_veto = true; }
|
|
|
|
|
|
|
|
bool IsVetoed() const { return m_veto; }
|
|
|
|
|
|
|
|
|
|
|
|
// default copy ctor, assignment operator and dtor are ok
|
|
|
|
|
2016-09-25 20:21:28 +00:00
|
|
|
virtual wxEvent *Clone() const wxOVERRIDE { return new wxPowerEvent(*this); }
|
2006-05-27 14:09:40 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_veto;
|
2007-09-19 23:14:16 +00:00
|
|
|
|
2015-04-23 11:49:01 +00:00
|
|
|
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxPowerEvent);
|
2006-05-27 14:09:40 +00:00
|
|
|
};
|
|
|
|
|
2009-02-07 18:59:25 +00:00
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_BASE, wxEVT_POWER_SUSPENDING, wxPowerEvent );
|
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_BASE, wxEVT_POWER_SUSPENDED, wxPowerEvent );
|
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_BASE, wxEVT_POWER_SUSPEND_CANCEL, wxPowerEvent );
|
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_BASE, wxEVT_POWER_RESUME, wxPowerEvent );
|
2006-05-27 14:09:40 +00:00
|
|
|
|
|
|
|
typedef void (wxEvtHandler::*wxPowerEventFunction)(wxPowerEvent&);
|
|
|
|
|
|
|
|
#define wxPowerEventHandler(func) \
|
2009-01-12 14:26:13 +00:00
|
|
|
wxEVENT_HANDLER_CAST(wxPowerEventFunction, func)
|
2006-05-27 14:09:40 +00:00
|
|
|
|
|
|
|
#define EVT_POWER_SUSPENDING(func) \
|
|
|
|
wx__DECLARE_EVT0(wxEVT_POWER_SUSPENDING, wxPowerEventHandler(func))
|
|
|
|
#define EVT_POWER_SUSPENDED(func) \
|
|
|
|
wx__DECLARE_EVT0(wxEVT_POWER_SUSPENDED, wxPowerEventHandler(func))
|
|
|
|
#define EVT_POWER_SUSPEND_CANCEL(func) \
|
|
|
|
wx__DECLARE_EVT0(wxEVT_POWER_SUSPEND_CANCEL, wxPowerEventHandler(func))
|
|
|
|
#define EVT_POWER_RESUME(func) \
|
|
|
|
wx__DECLARE_EVT0(wxEVT_POWER_RESUME, wxPowerEventHandler(func))
|
|
|
|
|
|
|
|
#else // no support for power events
|
|
|
|
#undef wxHAS_POWER_EVENTS
|
|
|
|
#endif // support for power events/no support
|
|
|
|
|
2014-08-29 23:22:15 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxPowerResourceBlocker
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum wxPowerResourceKind
|
|
|
|
{
|
|
|
|
wxPOWER_RESOURCE_SCREEN,
|
|
|
|
wxPOWER_RESOURCE_SYSTEM
|
|
|
|
};
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxPowerResource
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static bool Acquire(wxPowerResourceKind kind,
|
|
|
|
const wxString& reason = wxString());
|
|
|
|
static void Release(wxPowerResourceKind kind);
|
|
|
|
};
|
|
|
|
|
|
|
|
class wxPowerResourceBlocker
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit wxPowerResourceBlocker(wxPowerResourceKind kind,
|
|
|
|
const wxString& reason = wxString())
|
|
|
|
: m_kind(kind),
|
|
|
|
m_acquired(wxPowerResource::Acquire(kind, reason))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsInEffect() const { return m_acquired; }
|
|
|
|
|
|
|
|
~wxPowerResourceBlocker()
|
|
|
|
{
|
|
|
|
if ( m_acquired )
|
|
|
|
wxPowerResource::Release(m_kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const wxPowerResourceKind m_kind;
|
|
|
|
const bool m_acquired;
|
|
|
|
|
|
|
|
wxDECLARE_NO_COPY_CLASS(wxPowerResourceBlocker);
|
|
|
|
};
|
|
|
|
|
2006-05-27 14:09:40 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// power management functions
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// return the current system power state: online or offline
|
|
|
|
WXDLLIMPEXP_BASE wxPowerType wxGetPowerType();
|
|
|
|
|
|
|
|
// return approximate battery state
|
|
|
|
WXDLLIMPEXP_BASE wxBatteryState wxGetBatteryState();
|
|
|
|
|
|
|
|
#endif // _WX_POWER_H_
|