power.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #ifndef _WX_POWER_H_
  11. #define _WX_POWER_H_
  12. #include "wx/event.h"
  13. // ----------------------------------------------------------------------------
  14. // power management constants
  15. // ----------------------------------------------------------------------------
  16. enum wxPowerType
  17. {
  18. wxPOWER_SOCKET,
  19. wxPOWER_BATTERY,
  20. wxPOWER_UNKNOWN
  21. };
  22. enum wxBatteryState
  23. {
  24. wxBATTERY_NORMAL_STATE, // system is fully usable
  25. wxBATTERY_LOW_STATE, // start to worry
  26. wxBATTERY_CRITICAL_STATE, // save quickly
  27. wxBATTERY_SHUTDOWN_STATE, // too late
  28. wxBATTERY_UNKNOWN_STATE
  29. };
  30. // ----------------------------------------------------------------------------
  31. // wxPowerEvent is generated when the system online status changes
  32. // ----------------------------------------------------------------------------
  33. // currently the power events are only available under Windows, to avoid
  34. // compiling in the code for handling them which is never going to be invoked
  35. // under the other platforms, we define wxHAS_POWER_EVENTS symbol if this event
  36. // is available, it should be used to guard all code using wxPowerEvent
  37. #ifdef __WINDOWS__
  38. #define wxHAS_POWER_EVENTS
  39. class WXDLLIMPEXP_BASE wxPowerEvent : public wxEvent
  40. {
  41. public:
  42. wxPowerEvent() // just for use by wxRTTI
  43. : m_veto(false) { }
  44. wxPowerEvent(wxEventType evtType) : wxEvent(wxID_NONE, evtType)
  45. {
  46. m_veto = false;
  47. }
  48. // Veto the operation (only makes sense with EVT_POWER_SUSPENDING)
  49. void Veto() { m_veto = true; }
  50. bool IsVetoed() const { return m_veto; }
  51. // default copy ctor, assignment operator and dtor are ok
  52. virtual wxEvent *Clone() const { return new wxPowerEvent(*this); }
  53. private:
  54. bool m_veto;
  55. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxPowerEvent)
  56. };
  57. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_BASE, wxEVT_POWER_SUSPENDING, wxPowerEvent );
  58. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_BASE, wxEVT_POWER_SUSPENDED, wxPowerEvent );
  59. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_BASE, wxEVT_POWER_SUSPEND_CANCEL, wxPowerEvent );
  60. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_BASE, wxEVT_POWER_RESUME, wxPowerEvent );
  61. typedef void (wxEvtHandler::*wxPowerEventFunction)(wxPowerEvent&);
  62. #define wxPowerEventHandler(func) \
  63. wxEVENT_HANDLER_CAST(wxPowerEventFunction, func)
  64. #define EVT_POWER_SUSPENDING(func) \
  65. wx__DECLARE_EVT0(wxEVT_POWER_SUSPENDING, wxPowerEventHandler(func))
  66. #define EVT_POWER_SUSPENDED(func) \
  67. wx__DECLARE_EVT0(wxEVT_POWER_SUSPENDED, wxPowerEventHandler(func))
  68. #define EVT_POWER_SUSPEND_CANCEL(func) \
  69. wx__DECLARE_EVT0(wxEVT_POWER_SUSPEND_CANCEL, wxPowerEventHandler(func))
  70. #define EVT_POWER_RESUME(func) \
  71. wx__DECLARE_EVT0(wxEVT_POWER_RESUME, wxPowerEventHandler(func))
  72. #else // no support for power events
  73. #undef wxHAS_POWER_EVENTS
  74. #endif // support for power events/no support
  75. // ----------------------------------------------------------------------------
  76. // power management functions
  77. // ----------------------------------------------------------------------------
  78. // return the current system power state: online or offline
  79. WXDLLIMPEXP_BASE wxPowerType wxGetPowerType();
  80. // return approximate battery state
  81. WXDLLIMPEXP_BASE wxBatteryState wxGetBatteryState();
  82. #endif // _WX_POWER_H_