]> git.saurik.com Git - wxWidgets.git/blame - src/msw/power.cpp
add wxGet/Set/HasWindowExStyle() helpers and use them
[wxWidgets.git] / src / msw / power.cpp
CommitLineData
3032b7b5
VZ
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"
7325e21c 31#include "wx/msw/private.h"
3032b7b5 32
a8e89343
JS
33#if !defined(__WINCE_STANDARDSDK__)
34
dbc74bcc
WS
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
3032b7b5
VZ
43// ----------------------------------------------------------------------------
44// helper functions
45// ----------------------------------------------------------------------------
46
47static 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
a8e89343
JS
58#endif
59
3032b7b5
VZ
60// ============================================================================
61// implementation
62// ============================================================================
63
64wxPowerType wxGetPowerType()
65{
a8e89343 66#if !defined(__WINCE_STANDARDSDK__)
3032b7b5
VZ
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 }
a8e89343 84#endif
3032b7b5
VZ
85
86 return wxPOWER_UNKNOWN;
87}
88
89wxBatteryState wxGetBatteryState()
90{
a8e89343 91#if !defined(__WINCE_STANDARDSDK__)
3032b7b5
VZ
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 }
a8e89343 109#endif
3032b7b5
VZ
110
111 return wxBATTERY_UNKNOWN_STATE;
112}