]> git.saurik.com Git - wxWidgets.git/blob - src/msw/power.cpp
Hack compilation using the latest MinGW release.
[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 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #ifndef WX_PRECOMP
27 #endif //WX_PRECOMP
28
29 #include "wx/power.h"
30 #include "wx/msw/private.h"
31
32 #if !defined(__WINCE_STANDARDSDK__)
33
34 #ifdef __WXWINCE__
35 typedef SYSTEM_POWER_STATUS_EX SYSTEM_POWER_STATUS;
36 BOOL GetSystemPowerStatus(SYSTEM_POWER_STATUS *status)
37 {
38 return GetSystemPowerStatusEx(status, TRUE);
39 }
40 #endif
41
42 // ----------------------------------------------------------------------------
43 // helper functions
44 // ----------------------------------------------------------------------------
45
46 static inline bool wxGetPowerStatus(SYSTEM_POWER_STATUS *sps)
47 {
48 if ( !::GetSystemPowerStatus(sps) )
49 {
50 wxLogLastError(wxT("GetSystemPowerStatus()"));
51 return false;
52 }
53
54 return true;
55 }
56
57 #endif
58
59 // ============================================================================
60 // implementation
61 // ============================================================================
62
63 wxPowerType wxGetPowerType()
64 {
65 #if !defined(__WINCE_STANDARDSDK__)
66 SYSTEM_POWER_STATUS sps;
67 if ( wxGetPowerStatus(&sps) )
68 {
69 switch ( sps.ACLineStatus )
70 {
71 case 0:
72 return wxPOWER_BATTERY;
73
74 case 1:
75 return wxPOWER_SOCKET;
76
77 default:
78 wxLogDebug(wxT("Unknown ACLineStatus=%u"), sps.ACLineStatus);
79 case 255:
80 break;
81 }
82 }
83 #endif
84
85 return wxPOWER_UNKNOWN;
86 }
87
88 wxBatteryState wxGetBatteryState()
89 {
90 #if !defined(__WINCE_STANDARDSDK__)
91 SYSTEM_POWER_STATUS sps;
92 if ( wxGetPowerStatus(&sps) )
93 {
94 // there can be other bits set in the flag field ("charging" and "no
95 // battery"), extract only those which we need here
96 switch ( sps.BatteryFlag & 7 )
97 {
98 case 1:
99 return wxBATTERY_NORMAL_STATE;
100
101 case 2:
102 return wxBATTERY_LOW_STATE;
103
104 case 3:
105 return wxBATTERY_CRITICAL_STATE;
106 }
107 }
108 #endif
109
110 return wxBATTERY_UNKNOWN_STATE;
111 }