]> git.saurik.com Git - wxWidgets.git/blob - src/msw/power.cpp
fix GetTLWParentIfNotBeingDeleted() to work correctly even if an intermediate non...
[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 #if !defined(__WINCE_STANDARDSDK__)
34
35 #ifdef __WXWINCE__
36 typedef SYSTEM_POWER_STATUS_EX SYSTEM_POWER_STATUS;
37 BOOL GetSystemPowerStatus(SYSTEM_POWER_STATUS *status)
38 {
39 return GetSystemPowerStatusEx(status, TRUE);
40 }
41 #endif
42
43 // ----------------------------------------------------------------------------
44 // helper functions
45 // ----------------------------------------------------------------------------
46
47 static inline bool wxGetPowerStatus(SYSTEM_POWER_STATUS *sps)
48 {
49 if ( !::GetSystemPowerStatus(sps) )
50 {
51 wxLogLastError(_T("GetSystemPowerStatus()"));
52 return false;
53 }
54
55 return true;
56 }
57
58 #endif
59
60 // ============================================================================
61 // implementation
62 // ============================================================================
63
64 wxPowerType wxGetPowerType()
65 {
66 #if !defined(__WINCE_STANDARDSDK__)
67 SYSTEM_POWER_STATUS sps;
68 if ( wxGetPowerStatus(&sps) )
69 {
70 switch ( sps.ACLineStatus )
71 {
72 case 0:
73 return wxPOWER_BATTERY;
74
75 case 1:
76 return wxPOWER_SOCKET;
77
78 default:
79 wxLogDebug(_T("Unknown ACLineStatus=%u"), sps.ACLineStatus);
80 case 255:
81 break;
82 }
83 }
84 #endif
85
86 return wxPOWER_UNKNOWN;
87 }
88
89 wxBatteryState wxGetBatteryState()
90 {
91 #if !defined(__WINCE_STANDARDSDK__)
92 SYSTEM_POWER_STATUS sps;
93 if ( wxGetPowerStatus(&sps) )
94 {
95 // there can be other bits set in the flag field ("charging" and "no
96 // battery"), extract only those which we need here
97 switch ( sps.BatteryFlag & 7 )
98 {
99 case 1:
100 return wxBATTERY_NORMAL_STATE;
101
102 case 2:
103 return wxBATTERY_LOW_STATE;
104
105 case 3:
106 return wxBATTERY_CRITICAL_STATE;
107 }
108 }
109 #endif
110
111 return wxBATTERY_UNKNOWN_STATE;
112 }