Missing header.
[wxWidgets.git] / src / msw / power.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/power.cpp
3 // Purpose: power management functions for MSW
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 2006-05-27
7 // RCS-ID: $Id$
8 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #endif //WX_PRECOMP
29
30 #include "wx/power.h"
31 #include "wx/msw/private.h"
32
33 // ----------------------------------------------------------------------------
34 // helper functions
35 // ----------------------------------------------------------------------------
36
37 static inline bool wxGetPowerStatus(SYSTEM_POWER_STATUS *sps)
38 {
39 if ( !::GetSystemPowerStatus(sps) )
40 {
41 wxLogLastError(_T("GetSystemPowerStatus()"));
42 return false;
43 }
44
45 return true;
46 }
47
48 // ============================================================================
49 // implementation
50 // ============================================================================
51
52 wxPowerType wxGetPowerType()
53 {
54 SYSTEM_POWER_STATUS sps;
55 if ( wxGetPowerStatus(&sps) )
56 {
57 switch ( sps.ACLineStatus )
58 {
59 case 0:
60 return wxPOWER_BATTERY;
61
62 case 1:
63 return wxPOWER_SOCKET;
64
65 default:
66 wxLogDebug(_T("Unknown ACLineStatus=%u"), sps.ACLineStatus);
67 case 255:
68 break;
69 }
70 }
71
72 return wxPOWER_UNKNOWN;
73 }
74
75 wxBatteryState wxGetBatteryState()
76 {
77 SYSTEM_POWER_STATUS sps;
78 if ( wxGetPowerStatus(&sps) )
79 {
80 // there can be other bits set in the flag field ("charging" and "no
81 // battery"), extract only those which we need here
82 switch ( sps.BatteryFlag & 7 )
83 {
84 case 1:
85 return wxBATTERY_NORMAL_STATE;
86
87 case 2:
88 return wxBATTERY_LOW_STATE;
89
90 case 3:
91 return wxBATTERY_CRITICAL_STATE;
92 }
93 }
94
95 return wxBATTERY_UNKNOWN_STATE;
96 }
97
98