moved power functions for MSW from utils.cpp to (new) power.cpp and implemented them
[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
32 // ----------------------------------------------------------------------------
33 // helper functions
34 // ----------------------------------------------------------------------------
35
36 static inline bool wxGetPowerStatus(SYSTEM_POWER_STATUS *sps)
37 {
38 if ( !::GetSystemPowerStatus(sps) )
39 {
40 wxLogLastError(_T("GetSystemPowerStatus()"));
41 return false;
42 }
43
44 return true;
45 }
46
47 // ============================================================================
48 // implementation
49 // ============================================================================
50
51 wxPowerType wxGetPowerType()
52 {
53 SYSTEM_POWER_STATUS sps;
54 if ( wxGetPowerStatus(&sps) )
55 {
56 switch ( sps.ACLineStatus )
57 {
58 case 0:
59 return wxPOWER_BATTERY;
60
61 case 1:
62 return wxPOWER_SOCKET;
63
64 default:
65 wxLogDebug(_T("Unknown ACLineStatus=%u"), sps.ACLineStatus);
66 case 255:
67 break;
68 }
69 }
70
71 return wxPOWER_UNKNOWN;
72 }
73
74 wxBatteryState wxGetBatteryState()
75 {
76 SYSTEM_POWER_STATUS sps;
77 if ( wxGetPowerStatus(&sps) )
78 {
79 // there can be other bits set in the flag field ("charging" and "no
80 // battery"), extract only those which we need here
81 switch ( sps.BatteryFlag & 7 )
82 {
83 case 1:
84 return wxBATTERY_NORMAL_STATE;
85
86 case 2:
87 return wxBATTERY_LOW_STATE;
88
89 case 3:
90 return wxBATTERY_CRITICAL_STATE;
91 }
92 }
93
94 return wxBATTERY_UNKNOWN_STATE;
95 }
96
97