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