|
Lines 307-339
void cr3view::OnTimer(wxTimerEvent& event)
Link Here
|
| 307 |
} |
307 |
} |
| 308 |
} |
308 |
} |
| 309 |
|
309 |
|
| 310 |
void cr3view::Paint() |
310 |
static bool getBatteryState(int& state, int& chargingConn, int& level) |
| 311 |
{ |
311 |
{ |
| 312 |
//printf("cr3view::Paint() \n"); |
|
|
| 313 |
int battery_state = -1; |
| 314 |
#ifdef _WIN32 |
312 |
#ifdef _WIN32 |
|
|
313 |
// update battery state |
| 315 |
SYSTEM_POWER_STATUS bstatus; |
314 |
SYSTEM_POWER_STATUS bstatus; |
| 316 |
BOOL pow = GetSystemPowerStatus(&bstatus); |
315 |
BOOL pow = GetSystemPowerStatus(&bstatus); |
| 317 |
if (bstatus.BatteryFlag & 128) |
316 |
if (pow) { |
| 318 |
pow = FALSE; |
317 |
state = CR_BATTERY_STATE_DISCHARGING; |
| 319 |
if (bstatus.ACLineStatus!=0 || bstatus.BatteryLifePercent==255) |
318 |
if (bstatus.BatteryFlag & 128) |
| 320 |
pow = FALSE; |
319 |
state = CR_BATTERY_STATE_NO_BATTERY; // no system battery |
| 321 |
if ( pow ) |
320 |
else if (bstatus.BatteryFlag & 8) |
| 322 |
battery_state = bstatus.BatteryLifePercent; |
321 |
state = CR_BATTERY_STATE_CHARGING; // charging |
|
|
322 |
chargingConn = CR_BATTERY_CHARGER_NO; |
| 323 |
if (bstatus.ACLineStatus==1) |
| 324 |
chargingConn = CR_BATTERY_CHARGER_AC; // AC power charging connected |
| 325 |
if (bstatus.BatteryLifePercent>=0 && bstatus.BatteryLifePercent<=100) |
| 326 |
level = bstatus.BatteryLifePercent; |
| 327 |
return true; |
| 328 |
} |
| 329 |
return false; |
| 323 |
#else |
330 |
#else |
| 324 |
if ( ::wxGetPowerType() == wxPOWER_BATTERY ) { |
331 |
wxPowerType wxpwrtype = wxGetPowerType(); |
| 325 |
int n = ::wxGetBatteryState(); |
332 |
switch (wxpwrtype) { |
| 326 |
if ( n == wxBATTERY_NORMAL_STATE ) |
333 |
case wxPOWER_SOCKET: |
| 327 |
battery_state = 100; |
334 |
state = CR_BATTERY_STATE_CHARGING; |
| 328 |
else if ( n == wxBATTERY_LOW_STATE ) |
335 |
chargingConn = CR_BATTERY_CHARGER_AC; |
| 329 |
battery_state = 50; |
336 |
break; |
| 330 |
else if ( n == wxBATTERY_CRITICAL_STATE ) |
337 |
case wxPOWER_BATTERY: |
| 331 |
battery_state = 0; |
338 |
state = CR_BATTERY_STATE_DISCHARGING; |
| 332 |
else if ( n == wxBATTERY_SHUTDOWN_STATE ) |
339 |
chargingConn = CR_BATTERY_CHARGER_NO; |
| 333 |
battery_state = 0; |
340 |
break; |
| 334 |
}; |
341 |
default: |
|
|
342 |
state = CR_BATTERY_STATE_NO_BATTERY; |
| 343 |
chargingConn = CR_BATTERY_CHARGER_NO; |
| 344 |
break; |
| 345 |
} |
| 346 |
wxBatteryState wxbatstate = wxGetBatteryState(); |
| 347 |
switch (wxbatstate) { |
| 348 |
case wxBATTERY_NORMAL_STATE: |
| 349 |
level = 100; |
| 350 |
break; |
| 351 |
case wxBATTERY_LOW_STATE: |
| 352 |
level = 50; |
| 353 |
break; |
| 354 |
case wxBATTERY_CRITICAL_STATE: |
| 355 |
level = 5; |
| 356 |
break; |
| 357 |
case wxBATTERY_SHUTDOWN_STATE: |
| 358 |
level = 0; |
| 359 |
break; |
| 360 |
default: |
| 361 |
level = 0; |
| 362 |
break; |
| 363 |
} |
| 364 |
return true; |
| 335 |
#endif |
365 |
#endif |
| 336 |
getDocView()->setBatteryState( battery_state ); |
366 |
} |
|
|
367 |
|
| 368 |
void cr3view::Paint() |
| 369 |
{ |
| 370 |
//printf("cr3view::Paint() \n"); |
| 371 |
int battery_state; |
| 372 |
int charging_conn; |
| 373 |
int charge_level; |
| 374 |
if (getBatteryState(battery_state, charging_conn, charge_level)) { |
| 375 |
getDocView()->setBatteryState( battery_state, charging_conn, charge_level ); |
| 376 |
} |
| 337 |
//_docview->Draw(); |
377 |
//_docview->Draw(); |
| 338 |
UpdateScrollBar(); |
378 |
UpdateScrollBar(); |
| 339 |
Refresh( FALSE ); |
379 |
Refresh( FALSE ); |