* Worked over the battery look a bit, looks much better now IMO.
* Made the replicant transparent (for background images). * Fixed many of Clemen's coding style violations. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32255 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
* Copyright 2009, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Clemens Zeidler, [email protected]
|
* Clemens Zeidler, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "ExtendedInfoWindow.h"
|
#include "ExtendedInfoWindow.h"
|
||||||
|
|
||||||
#include <Box.h>
|
#include <Box.h>
|
||||||
@@ -16,18 +17,21 @@
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
|
const int kLineSpacing = 5;
|
||||||
|
|
||||||
|
|
||||||
FontString::FontString()
|
FontString::FontString()
|
||||||
{
|
{
|
||||||
font = be_plain_font;
|
font = be_plain_font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const int kLineSpacing = 5;
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
BatteryInfoView::BatteryInfoView()
|
BatteryInfoView::BatteryInfoView()
|
||||||
:
|
:
|
||||||
BView("battery info view", B_WILL_DRAW |
|
BView("battery info view", B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
|
||||||
B_FULL_UPDATE_ON_RESIZE),
|
|
||||||
fPreferredSize(200, 200),
|
fPreferredSize(200, 200),
|
||||||
fMaxStringSize(0, 0)
|
fMaxStringSize(0, 0)
|
||||||
{
|
{
|
||||||
@@ -46,7 +50,7 @@ BatteryInfoView::Update(battery_info& info, acpi_extended_battery_info& extInfo)
|
|||||||
{
|
{
|
||||||
fBatteryInfo = info;
|
fBatteryInfo = info;
|
||||||
fBatteryExtendedInfo = extInfo;
|
fBatteryExtendedInfo = extInfo;
|
||||||
|
|
||||||
_FillStringList();
|
_FillStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,23 +59,22 @@ void
|
|||||||
BatteryInfoView::Draw(BRect updateRect)
|
BatteryInfoView::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
BPoint point(10, 10);
|
BPoint point(10, 10);
|
||||||
|
|
||||||
float space = _MeasureString("").height + kLineSpacing;
|
float space = _MeasureString("").height + kLineSpacing;
|
||||||
|
|
||||||
for (int i = 0; i < fStringList.CountItems(); i ++)
|
for (int i = 0; i < fStringList.CountItems(); i++) {
|
||||||
{
|
|
||||||
FontString* fontString = fStringList.ItemAt(i);
|
FontString* fontString = fStringList.ItemAt(i);
|
||||||
SetFont(fontString->font);
|
SetFont(fontString->font);
|
||||||
DrawString(fontString->string.String(), point);
|
DrawString(fontString->string.String(), point);
|
||||||
point.y += space;
|
point.y += space;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BatteryInfoView::GetPreferredSize(float *width, float *height)
|
BatteryInfoView::GetPreferredSize(float* width, float* height)
|
||||||
{
|
{
|
||||||
*width = fPreferredSize.width;
|
*width = fPreferredSize.width;
|
||||||
*height = fPreferredSize.height;
|
*height = fPreferredSize.height;
|
||||||
@@ -97,7 +100,7 @@ BatteryInfoView::_MeasureString(const BString& string)
|
|||||||
BFont font;
|
BFont font;
|
||||||
GetFont(&font);
|
GetFont(&font);
|
||||||
BSize size;
|
BSize size;
|
||||||
|
|
||||||
size.width = font.StringWidth(string);
|
size.width = font.StringWidth(string);
|
||||||
|
|
||||||
font_height height;
|
font_height height;
|
||||||
@@ -120,7 +123,7 @@ BatteryInfoView::_FillStringList()
|
|||||||
powerUnit = " mWh";
|
powerUnit = " mWh";
|
||||||
rateUnit = " mW";
|
rateUnit = " mW";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
powerUnit = " mAh";
|
powerUnit = " mAh";
|
||||||
rateUnit = " mA";
|
rateUnit = " mA";
|
||||||
@@ -132,7 +135,7 @@ BatteryInfoView::_FillStringList()
|
|||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
fStringList.AddItem(fontString);
|
fStringList.AddItem(fontString);
|
||||||
fontString->font = be_bold_font;
|
fontString->font = be_bold_font;
|
||||||
|
|
||||||
if (fBatteryInfo.state & BATTERY_CHARGING)
|
if (fBatteryInfo.state & BATTERY_CHARGING)
|
||||||
fontString->string = "Battery charging";
|
fontString->string = "Battery charging";
|
||||||
else if (fBatteryInfo.state & BATTERY_DISCHARGING)
|
else if (fBatteryInfo.state & BATTERY_DISCHARGING)
|
||||||
@@ -141,35 +144,35 @@ BatteryInfoView::_FillStringList()
|
|||||||
fontString->string = "Empty Battery Slot";
|
fontString->string = "Empty Battery Slot";
|
||||||
else
|
else
|
||||||
fontString->string = "Battery unused";
|
fontString->string = "Battery unused";
|
||||||
|
|
||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
fontString->string = "Capacity: ";
|
fontString->string = "Capacity: ";
|
||||||
fontString->string << fBatteryInfo.capacity;
|
fontString->string << fBatteryInfo.capacity;
|
||||||
fontString->string << powerUnit;
|
fontString->string << powerUnit;
|
||||||
_AddToStringList(fontString);
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
fontString->string = "Last full Charge: ";
|
fontString->string = "Last full Charge: ";
|
||||||
fontString->string << fBatteryInfo.full_capacity;
|
fontString->string << fBatteryInfo.full_capacity;
|
||||||
fontString->string << powerUnit;
|
fontString->string << powerUnit;
|
||||||
_AddToStringList(fontString);
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
fontString->string = "Current Rate: ";
|
fontString->string = "Current Rate: ";
|
||||||
fontString->string << fBatteryInfo.current_rate;
|
fontString->string << fBatteryInfo.current_rate;
|
||||||
fontString->string << rateUnit;
|
fontString->string << rateUnit;
|
||||||
_AddToStringList(fontString);
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
// empty line
|
// empty line
|
||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
_AddToStringList(fontString);
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
fontString->string = "Design Capacity: ";
|
fontString->string = "Design Capacity: ";
|
||||||
fontString->string << fBatteryExtendedInfo.design_capacity;
|
fontString->string << fBatteryExtendedInfo.design_capacity;
|
||||||
fontString->string << powerUnit;
|
fontString->string << powerUnit;
|
||||||
_AddToStringList(fontString);
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
fontString->string = "Technology: ";
|
fontString->string = "Technology: ";
|
||||||
if (fBatteryExtendedInfo.technology == 0)
|
if (fBatteryExtendedInfo.technology == 0)
|
||||||
@@ -179,57 +182,57 @@ BatteryInfoView::_FillStringList()
|
|||||||
else
|
else
|
||||||
fontString->string << "?";
|
fontString->string << "?";
|
||||||
_AddToStringList(fontString);
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
fontString->string = "Design Voltage: ";
|
fontString->string = "Design Voltage: ";
|
||||||
fontString->string << fBatteryExtendedInfo.design_voltage;
|
fontString->string << fBatteryExtendedInfo.design_voltage;
|
||||||
fontString->string << " mV";
|
fontString->string << " mV";
|
||||||
_AddToStringList(fontString);
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
fontString->string = "Design Capacity Warning: ";
|
fontString->string = "Design Capacity Warning: ";
|
||||||
fontString->string << fBatteryExtendedInfo.design_capacity_warning;
|
fontString->string << fBatteryExtendedInfo.design_capacity_warning;
|
||||||
fontString->string << powerUnit;
|
fontString->string << powerUnit;
|
||||||
_AddToStringList(fontString);
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
fontString->string = "Design Capacity low Warning: ";
|
fontString->string = "Design Capacity low Warning: ";
|
||||||
fontString->string << fBatteryExtendedInfo.design_capacity_low;
|
fontString->string << fBatteryExtendedInfo.design_capacity_low;
|
||||||
fontString->string << powerUnit;
|
fontString->string << powerUnit;
|
||||||
_AddToStringList(fontString);
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
fontString->string = "Capacity Granularity 1: ";
|
fontString->string = "Capacity Granularity 1: ";
|
||||||
fontString->string << fBatteryExtendedInfo.capacity_granularity_1;
|
fontString->string << fBatteryExtendedInfo.capacity_granularity_1;
|
||||||
fontString->string << powerUnit;
|
fontString->string << powerUnit;
|
||||||
_AddToStringList(fontString);
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
fontString->string = "Capacity Granularity 2: ";
|
fontString->string = "Capacity Granularity 2: ";
|
||||||
fontString->string << fBatteryExtendedInfo.capacity_granularity_2;
|
fontString->string << fBatteryExtendedInfo.capacity_granularity_2;
|
||||||
fontString->string << powerUnit;
|
fontString->string << powerUnit;
|
||||||
_AddToStringList(fontString);
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
fontString->string = "Model Number: ";
|
fontString->string = "Model Number: ";
|
||||||
fontString->string << fBatteryExtendedInfo.model_number;
|
fontString->string << fBatteryExtendedInfo.model_number;
|
||||||
_AddToStringList(fontString);
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
fontString->string = "Serial number: ";
|
fontString->string = "Serial number: ";
|
||||||
fontString->string << fBatteryExtendedInfo.serial_number;
|
fontString->string << fBatteryExtendedInfo.serial_number;
|
||||||
_AddToStringList(fontString);
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
fontString->string = "Type: ";
|
fontString->string = "Type: ";
|
||||||
fontString->string += fBatteryExtendedInfo.type;
|
fontString->string += fBatteryExtendedInfo.type;
|
||||||
_AddToStringList(fontString);
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
fontString = new FontString;
|
fontString = new FontString;
|
||||||
fontString->string = "OEM Info: ";
|
fontString->string = "OEM Info: ";
|
||||||
fontString->string += fBatteryExtendedInfo.oem_info;
|
fontString->string += fBatteryExtendedInfo.oem_info;
|
||||||
_AddToStringList(fontString);
|
_AddToStringList(fontString);
|
||||||
|
|
||||||
fPreferredSize.width = fMaxStringSize.width + 10;
|
fPreferredSize.width = fMaxStringSize.width + 10;
|
||||||
fPreferredSize.height = (fMaxStringSize.height + kLineSpacing) *
|
fPreferredSize.height = (fMaxStringSize.height + kLineSpacing) *
|
||||||
fStringList.CountItems();
|
fStringList.CountItems();
|
||||||
@@ -256,32 +259,28 @@ BatteryInfoView::_ClearStringList()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
ExtPowerStatusView::ExtPowerStatusView(PowerStatusDriverInterface* interface,
|
ExtPowerStatusView::ExtPowerStatusView(PowerStatusDriverInterface* interface,
|
||||||
BRect frame, int32 resizingMode, int batteryId,
|
BRect frame, int32 resizingMode, int batteryID,
|
||||||
ExtendedInfoWindow* window)
|
ExtendedInfoWindow* window)
|
||||||
:
|
:
|
||||||
PowerStatusView(interface, frame, resizingMode, batteryId),
|
PowerStatusView(interface, frame, resizingMode, batteryID),
|
||||||
fExtendedInfoWindow(window),
|
fExtendedInfoWindow(window),
|
||||||
fBatteryInfoView(window->GetExtendedBatteryInfoView()),
|
fBatteryInfoView(window->GetExtendedBatteryInfoView()),
|
||||||
fSelected(false)
|
fSelected(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ExtPowerStatusView::Draw(BRect updateRect)
|
ExtPowerStatusView::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
if (fSelected) {
|
if (fSelected)
|
||||||
SetLowColor(102, 152, 203);
|
SetLowColor(102, 152, 203);
|
||||||
SetHighColor(102, 152, 203);
|
else
|
||||||
FillRect(updateRect);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
|
||||||
FillRect(updateRect);
|
|
||||||
}
|
|
||||||
|
|
||||||
PowerStatusView::Draw(updateRect);
|
PowerStatusView::Draw(updateRect);
|
||||||
}
|
}
|
||||||
@@ -292,44 +291,47 @@ ExtPowerStatusView::MouseDown(BPoint where)
|
|||||||
{
|
{
|
||||||
if (!fSelected) {
|
if (!fSelected) {
|
||||||
fSelected = true;
|
fSelected = true;
|
||||||
_Update(true);
|
Update(true);
|
||||||
fExtendedInfoWindow->BatterySelected(this);
|
if (ExtendedInfoWindow* window
|
||||||
|
= dynamic_cast<ExtendedInfoWindow*>(Window()))
|
||||||
|
window->BatterySelected(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ExtPowerStatusView::Select(bool select)
|
ExtPowerStatusView::Select(bool select)
|
||||||
{
|
{
|
||||||
fSelected = select;
|
fSelected = select;
|
||||||
_Update(true);
|
Update(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ExtPowerStatusView::IsValid()
|
ExtPowerStatusView::IsCritical()
|
||||||
{
|
{
|
||||||
if (fBatteryInfo.state & BATTERY_CRITICAL_STATE)
|
return (fBatteryInfo.state & BATTERY_CRITICAL_STATE) != 0;
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ExtPowerStatusView::_Update(bool force)
|
ExtPowerStatusView::Update(bool force)
|
||||||
{
|
{
|
||||||
PowerStatusView::_Update(force);
|
PowerStatusView::Update(force);
|
||||||
if (!fSelected)
|
if (!fSelected)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
acpi_extended_battery_info extInfo;
|
acpi_extended_battery_info extInfo;
|
||||||
fDriverInterface->GetExtendedBatteryInfo(&extInfo, fBatteryId);
|
fDriverInterface->GetExtendedBatteryInfo(&extInfo, fBatteryID);
|
||||||
|
|
||||||
fBatteryInfoView->Update(fBatteryInfo, extInfo);
|
fBatteryInfoView->Update(fBatteryInfo, extInfo);
|
||||||
fBatteryInfoView->Invalidate();
|
fBatteryInfoView->Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
|
ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
|
||||||
:
|
:
|
||||||
BWindow(BRect(100, 150, 500, 500), "Extended Battery Info", B_TITLED_WINDOW,
|
BWindow(BRect(100, 150, 500, 500), "Extended Battery Info", B_TITLED_WINDOW,
|
||||||
@@ -348,7 +350,7 @@ ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
|
|||||||
mainLayout->SetSpacing(10);
|
mainLayout->SetSpacing(10);
|
||||||
mainLayout->SetInsets(10, 10, 10, 10);
|
mainLayout->SetInsets(10, 10, 10, 10);
|
||||||
view->SetLayout(mainLayout);
|
view->SetLayout(mainLayout);
|
||||||
|
|
||||||
BRect rect = Bounds();
|
BRect rect = Bounds();
|
||||||
rect.InsetBy(5, 5);
|
rect.InsetBy(5, 5);
|
||||||
BBox *infoBox = new BBox(rect, "Power Status Box");
|
BBox *infoBox = new BBox(rect, "Power Status Box");
|
||||||
@@ -358,14 +360,14 @@ ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
|
|||||||
infoLayout->SetSpacing(10);
|
infoLayout->SetSpacing(10);
|
||||||
infoBox->SetLayout(infoLayout);
|
infoBox->SetLayout(infoLayout);
|
||||||
mainLayout->AddView(infoBox);
|
mainLayout->AddView(infoBox);
|
||||||
|
|
||||||
BGroupView* batteryView = new BGroupView(B_VERTICAL);
|
BGroupView* batteryView = new BGroupView(B_VERTICAL);
|
||||||
batteryView->GroupLayout()->SetSpacing(10);
|
batteryView->GroupLayout()->SetSpacing(10);
|
||||||
infoLayout->AddView(batteryView);
|
infoLayout->AddView(batteryView);
|
||||||
|
|
||||||
// create before the battery views
|
// create before the battery views
|
||||||
fBatteryInfoView = new BatteryInfoView();
|
fBatteryInfoView = new BatteryInfoView();
|
||||||
|
|
||||||
BGroupLayout* batteryLayout = batteryView->GroupLayout();
|
BGroupLayout* batteryLayout = batteryView->GroupLayout();
|
||||||
BRect batteryRect(0, 0, 50, 30);
|
BRect batteryRect(0, 0, 50, 30);
|
||||||
for (int i = 0; i < interface->GetBatteryCount(); i++) {
|
for (int i = 0; i < interface->GetBatteryCount(); i++) {
|
||||||
@@ -377,18 +379,18 @@ ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
|
|||||||
batteryLayout->AddView(view);
|
batteryLayout->AddView(view);
|
||||||
fBatteryViewList.AddItem(view);
|
fBatteryViewList.AddItem(view);
|
||||||
fDriverInterface->StartWatching(view);
|
fDriverInterface->StartWatching(view);
|
||||||
if (view->IsValid())
|
if (!view->IsCritical())
|
||||||
fSelectedView = view;
|
fSelectedView = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
batteryLayout->AddItem(BSpaceLayoutItem::CreateGlue());
|
batteryLayout->AddItem(BSpaceLayoutItem::CreateGlue());
|
||||||
|
|
||||||
infoLayout->AddView(fBatteryInfoView);
|
infoLayout->AddView(fBatteryInfoView);
|
||||||
|
|
||||||
if (!fSelectedView && fBatteryViewList.CountItems() > 0)
|
if (!fSelectedView && fBatteryViewList.CountItems() > 0)
|
||||||
fSelectedView = fBatteryViewList.ItemAt(0);
|
fSelectedView = fBatteryViewList.ItemAt(0);
|
||||||
fSelectedView->Select();
|
fSelectedView->Select();
|
||||||
|
|
||||||
BSize size = mainLayout->PreferredSize();
|
BSize size = mainLayout->PreferredSize();
|
||||||
ResizeTo(size.width, size.height);
|
ResizeTo(size.width, size.height);
|
||||||
}
|
}
|
||||||
@@ -398,7 +400,7 @@ ExtendedInfoWindow::~ExtendedInfoWindow()
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < fBatteryViewList.CountItems(); i++)
|
for (int i = 0; i < fBatteryViewList.CountItems(); i++)
|
||||||
fDriverInterface->StopWatching(fBatteryViewList.ItemAt(i));
|
fDriverInterface->StopWatching(fBatteryViewList.ItemAt(i));
|
||||||
|
|
||||||
fDriverInterface->ReleaseReference();
|
fDriverInterface->ReleaseReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
* Copyright 2009, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Clemens Zeidler, [email protected]
|
* Clemens Zeidler, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef EXTENDED_INFO_WINDOW_H
|
#ifndef EXTENDED_INFO_WINDOW_H
|
||||||
#define EXTENDED_INFO_WINDOW_H
|
#define EXTENDED_INFO_WINDOW_H
|
||||||
|
|
||||||
|
|
||||||
#include <ObjectList.h>
|
#include <ObjectList.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
@@ -18,69 +19,67 @@
|
|||||||
#include "PowerStatusView.h"
|
#include "PowerStatusView.h"
|
||||||
|
|
||||||
|
|
||||||
class FontString
|
class FontString {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
FontString();
|
FontString();
|
||||||
|
|
||||||
const BFont* font;
|
const BFont* font;
|
||||||
BString string;
|
BString string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class BatteryInfoView : public BView
|
class BatteryInfoView : public BView {
|
||||||
{
|
public:
|
||||||
public:
|
BatteryInfoView();
|
||||||
BatteryInfoView();
|
~BatteryInfoView();
|
||||||
~BatteryInfoView();
|
|
||||||
|
|
||||||
virtual void Update(battery_info& info,
|
virtual void Update(battery_info& info,
|
||||||
acpi_extended_battery_info& extInfo);
|
acpi_extended_battery_info& extInfo);
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
virtual void GetPreferredSize(float *width, float *height);
|
virtual void GetPreferredSize(float* width, float* height);
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BSize _MeasureString(const BString& string);
|
BSize _MeasureString(const BString& string);
|
||||||
void _FillStringList();
|
void _FillStringList();
|
||||||
void _AddToStringList(FontString* fontString);
|
void _AddToStringList(FontString* fontString);
|
||||||
void _ClearStringList();
|
void _ClearStringList();
|
||||||
|
|
||||||
battery_info fBatteryInfo;
|
battery_info fBatteryInfo;
|
||||||
acpi_extended_battery_info fBatteryExtendedInfo;
|
acpi_extended_battery_info fBatteryExtendedInfo;
|
||||||
|
|
||||||
BSize fPreferredSize;
|
BSize fPreferredSize;
|
||||||
|
|
||||||
BObjectList<FontString> fStringList;
|
BObjectList<FontString> fStringList;
|
||||||
BSize fMaxStringSize;
|
BSize fMaxStringSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ExtendedInfoWindow;
|
class ExtendedInfoWindow;
|
||||||
|
|
||||||
class ExtPowerStatusView : public PowerStatusView
|
class ExtPowerStatusView : public PowerStatusView {
|
||||||
{
|
public:
|
||||||
public:
|
ExtPowerStatusView(
|
||||||
ExtPowerStatusView(PowerStatusDriverInterface* interface,
|
PowerStatusDriverInterface* interface,
|
||||||
BRect frame, int32 resizingMode, int batteryId,
|
BRect frame, int32 resizingMode,
|
||||||
ExtendedInfoWindow* window);
|
int batteryID, ExtendedInfoWindow* window);
|
||||||
|
|
||||||
virtual void Draw(BRect updateRect);
|
|
||||||
virtual void MouseDown(BPoint where);
|
|
||||||
|
|
||||||
virtual void Select(bool select = true);
|
virtual void Draw(BRect updateRect);
|
||||||
|
virtual void MouseDown(BPoint where);
|
||||||
// return true if it battery is in a none critical state
|
|
||||||
virtual bool IsValid();
|
|
||||||
|
|
||||||
protected:
|
virtual void Select(bool select = true);
|
||||||
virtual void _Update(bool force = false);
|
|
||||||
|
|
||||||
private:
|
// return true if it battery is in a critical state
|
||||||
ExtendedInfoWindow* fExtendedInfoWindow;
|
virtual bool IsCritical();
|
||||||
BatteryInfoView* fBatteryInfoView;
|
|
||||||
|
protected:
|
||||||
bool fSelected;
|
virtual void Update(bool force = false);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ExtendedInfoWindow* fExtendedInfoWindow;
|
||||||
|
BatteryInfoView* fBatteryInfoView;
|
||||||
|
|
||||||
|
bool fSelected;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -89,7 +88,7 @@ class ExtendedInfoWindow : public BWindow
|
|||||||
public:
|
public:
|
||||||
ExtendedInfoWindow(PowerStatusDriverInterface* interface);
|
ExtendedInfoWindow(PowerStatusDriverInterface* interface);
|
||||||
~ExtendedInfoWindow();
|
~ExtendedInfoWindow();
|
||||||
|
|
||||||
BatteryInfoView* GetExtendedBatteryInfoView();
|
BatteryInfoView* GetExtendedBatteryInfoView();
|
||||||
|
|
||||||
void BatterySelected(ExtPowerStatusView* view);
|
void BatterySelected(ExtPowerStatusView* view);
|
||||||
@@ -97,9 +96,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
PowerStatusDriverInterface* fDriverInterface;
|
PowerStatusDriverInterface* fDriverInterface;
|
||||||
BObjectList<ExtPowerStatusView> fBatteryViewList;
|
BObjectList<ExtPowerStatusView> fBatteryViewList;
|
||||||
|
|
||||||
BatteryInfoView* fBatteryInfoView;
|
BatteryInfoView* fBatteryInfoView;
|
||||||
|
|
||||||
ExtPowerStatusView* fSelectedView;
|
ExtPowerStatusView* fSelectedView;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ PowerStatus::ReadyToRun()
|
|||||||
isInstalled = deskbar.HasItem(kDeskbarItemName);
|
isInstalled = deskbar.HasItem(kDeskbarItemName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isInstalled = true;
|
||||||
if (isDeskbarRunning && !isInstalled) {
|
if (isDeskbarRunning && !isInstalled) {
|
||||||
BAlert* alert = new BAlert("", "Do you want PowerStatus to live in the Deskbar?",
|
BAlert* alert = new BAlert("", "Do you want PowerStatus to live in the Deskbar?",
|
||||||
"Don't", "Install", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
"Don't", "Install", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
||||||
@@ -87,7 +88,7 @@ PowerStatus::ReadyToRun()
|
|||||||
if (alert->Go()) {
|
if (alert->Go()) {
|
||||||
image_info info;
|
image_info info;
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
|
|
||||||
if (our_image(info) == B_OK
|
if (our_image(info) == B_OK
|
||||||
&& get_ref_for_path(info.name, &ref) == B_OK) {
|
&& get_ref_for_path(info.name, &ref) == B_OK) {
|
||||||
BDeskbar deskbar;
|
BDeskbar deskbar;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
* Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
|
#include <ControlLook.h>
|
||||||
#include <Deskbar.h>
|
#include <Deskbar.h>
|
||||||
#include <Dragger.h>
|
#include <Dragger.h>
|
||||||
#include <Drivers.h>
|
#include <Drivers.h>
|
||||||
@@ -43,12 +44,12 @@ const uint32 kMinIconHeight = 16;
|
|||||||
|
|
||||||
|
|
||||||
PowerStatusView::PowerStatusView(PowerStatusDriverInterface* interface,
|
PowerStatusView::PowerStatusView(PowerStatusDriverInterface* interface,
|
||||||
BRect frame, int32 resizingMode, int batteryId, bool inDeskbar)
|
BRect frame, int32 resizingMode, int batteryID, bool inDeskbar)
|
||||||
:
|
:
|
||||||
BView(frame, kDeskbarItemName, resizingMode,
|
BView(frame, kDeskbarItemName, resizingMode,
|
||||||
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
|
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
|
||||||
fDriverInterface(interface),
|
fDriverInterface(interface),
|
||||||
fBatteryId(batteryId),
|
fBatteryID(batteryID),
|
||||||
fInDeskbar(inDeskbar)
|
fInDeskbar(inDeskbar)
|
||||||
{
|
{
|
||||||
fPreferredSize.width = frame.Width();
|
fPreferredSize.width = frame.Width();
|
||||||
@@ -71,14 +72,12 @@ PowerStatusView::PowerStatusView(BMessage* archive)
|
|||||||
fShowTime = value;
|
fShowTime = value;
|
||||||
int32 intValue;
|
int32 intValue;
|
||||||
if (archive->FindInt32("battery id", &intValue) == B_OK)
|
if (archive->FindInt32("battery id", &intValue) == B_OK)
|
||||||
fBatteryId = intValue;
|
fBatteryID = intValue;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PowerStatusView::~PowerStatusView()
|
PowerStatusView::~PowerStatusView()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -93,7 +92,7 @@ PowerStatusView::Archive(BMessage* archive, bool deep) const
|
|||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = archive->AddBool("show time", fShowTime);
|
status = archive->AddBool("show time", fShowTime);
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = archive->AddInt32("battery id", fBatteryId);
|
status = archive->AddInt32("battery id", fBatteryID);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -102,6 +101,8 @@ PowerStatusView::Archive(BMessage* archive, bool deep) const
|
|||||||
void
|
void
|
||||||
PowerStatusView::_Init()
|
PowerStatusView::_Init()
|
||||||
{
|
{
|
||||||
|
SetViewColor(B_TRANSPARENT_COLOR);
|
||||||
|
|
||||||
fShowLabel = true;
|
fShowLabel = true;
|
||||||
fShowTime = false;
|
fShowTime = false;
|
||||||
fShowStatusIcon = true;
|
fShowStatusIcon = true;
|
||||||
@@ -109,7 +110,6 @@ PowerStatusView::_Init()
|
|||||||
fPercent = -1;
|
fPercent = -1;
|
||||||
fOnline = true;
|
fOnline = true;
|
||||||
fTimeLeft = 0;
|
fTimeLeft = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -118,13 +118,11 @@ PowerStatusView::AttachedToWindow()
|
|||||||
{
|
{
|
||||||
BView::AttachedToWindow();
|
BView::AttachedToWindow();
|
||||||
if (Parent())
|
if (Parent())
|
||||||
SetViewColor(Parent()->ViewColor());
|
SetLowColor(Parent()->ViewColor());
|
||||||
else
|
else
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
SetLowColor(ViewColor());
|
Update();
|
||||||
|
|
||||||
_Update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -140,7 +138,7 @@ PowerStatusView::MessageReceived(BMessage *message)
|
|||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kMsgUpdate:
|
case kMsgUpdate:
|
||||||
_Update();
|
Update();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -169,39 +167,55 @@ PowerStatusView::_DrawBattery(BRect rect)
|
|||||||
float left = rect.left;
|
float left = rect.left;
|
||||||
rect.left += rect.Width() / 11;
|
rect.left += rect.Width() / 11;
|
||||||
|
|
||||||
|
SetHighColor(84, 84, 84);
|
||||||
|
|
||||||
float gap = 1;
|
float gap = 1;
|
||||||
if (rect.Height() > 8) {
|
if (rect.Height() > 8) {
|
||||||
rect.InsetBy(1, 1);
|
gap = ceilf((rect.left - left) / 2);
|
||||||
SetPenSize(2);
|
|
||||||
gap = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
SetHighColor(92, 92, 92);
|
// left
|
||||||
|
FillRect(BRect(rect.left, rect.top, rect.left + gap - 1, rect.bottom));
|
||||||
|
// right
|
||||||
|
FillRect(BRect(rect.right - gap + 1, rect.top, rect.right,
|
||||||
|
rect.bottom));
|
||||||
|
// top
|
||||||
|
FillRect(BRect(rect.left + gap, rect.top, rect.right - gap,
|
||||||
|
rect.top + gap - 1));
|
||||||
|
// bottom
|
||||||
|
FillRect(BRect(rect.left + gap, rect.bottom + 1 - gap,
|
||||||
|
rect.right - gap, rect.bottom));
|
||||||
|
} else
|
||||||
|
StrokeRect(rect);
|
||||||
|
|
||||||
StrokeRect(rect);
|
|
||||||
|
|
||||||
SetPenSize(1);
|
|
||||||
FillRect(BRect(left, floorf(rect.top + rect.Height() / 4) + 1,
|
FillRect(BRect(left, floorf(rect.top + rect.Height() / 4) + 1,
|
||||||
rect.left, floorf(rect.bottom - rect.Height() / 4)));
|
rect.left - 1, floorf(rect.bottom - rect.Height() / 4)));
|
||||||
|
|
||||||
int32 percent = fPercent;
|
int32 percent = fPercent;
|
||||||
if (percent > 100 || percent < 0)
|
if (percent > 100 || percent < 0)
|
||||||
percent = 100;
|
percent = 100;
|
||||||
|
|
||||||
if (percent > 0) {
|
if (percent > 0) {
|
||||||
if (percent < 16)
|
rgb_color base;
|
||||||
SetHighColor(180, 0, 0);
|
if (fOnline) {
|
||||||
else
|
if (percent <= 15)
|
||||||
SetHighColor(20, 180, 0);
|
base.set_to(180, 0, 0);
|
||||||
|
else
|
||||||
rect.InsetBy(gap + 1, gap + 1);
|
base.set_to(20, 180, 0);
|
||||||
if (gap > 1) {
|
} else {
|
||||||
rect.right++;
|
base = HighColor();
|
||||||
rect.bottom++;
|
percent = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
rect.right = rect.left + rect.Width() * min_c(percent, 100) / 100.0;
|
rect.InsetBy(gap, gap);
|
||||||
FillRect(rect);
|
rect.right = rect.left + rect.Width() * percent / 100.0;
|
||||||
|
|
||||||
|
if (be_control_look != NULL)
|
||||||
|
be_control_look->DrawButtonBackground(this, rect, rect, base,
|
||||||
|
fOnline ? 0 : BControlLook::B_DISABLED);
|
||||||
|
//if (!)
|
||||||
|
|
||||||
|
else
|
||||||
|
FillRect(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetHighColor(0, 0, 0);
|
SetHighColor(0, 0, 0);
|
||||||
@@ -211,6 +225,11 @@ PowerStatusView::_DrawBattery(BRect rect)
|
|||||||
void
|
void
|
||||||
PowerStatusView::Draw(BRect updateRect)
|
PowerStatusView::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
|
bool drawBackground = Parent() == NULL
|
||||||
|
|| (Parent()->Flags() & B_DRAW_ON_CHILDREN) == 0;
|
||||||
|
if (drawBackground)
|
||||||
|
FillRect(updateRect, B_SOLID_LOW);
|
||||||
|
|
||||||
float aspect = Bounds().Width() / Bounds().Height();
|
float aspect = Bounds().Width() / Bounds().Height();
|
||||||
bool below = aspect <= 1.0f;
|
bool below = aspect <= 1.0f;
|
||||||
|
|
||||||
@@ -269,6 +288,17 @@ PowerStatusView::Draw(BRect updateRect)
|
|||||||
point.y += (Bounds().Height() - textHeight) / 2;
|
point.y += (Bounds().Height() - textHeight) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (drawBackground)
|
||||||
|
SetHighColor(ui_color(B_CONTROL_TEXT_COLOR));
|
||||||
|
else {
|
||||||
|
SetDrawingMode(B_OP_OVER);
|
||||||
|
rgb_color c = Parent()->LowColor();
|
||||||
|
if (c.red + c.green + c.blue > 128 * 3)
|
||||||
|
SetHighColor(0, 0, 0);
|
||||||
|
else
|
||||||
|
SetHighColor(255, 255, 255);
|
||||||
|
}
|
||||||
|
|
||||||
DrawString(text, point);
|
DrawString(text, point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,13 +333,13 @@ PowerStatusView::_SetLabel(char* buffer, size_t bufferLength)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PowerStatusView::_Update(bool force)
|
PowerStatusView::Update(bool force)
|
||||||
{
|
{
|
||||||
int32 previousPercent = fPercent;
|
int32 previousPercent = fPercent;
|
||||||
bool previousTimeLeft = fTimeLeft;
|
bool previousTimeLeft = fTimeLeft;
|
||||||
bool wasOnline = fOnline;
|
bool wasOnline = fOnline;
|
||||||
|
|
||||||
_GetBatteryInfo(&fBatteryInfo, fBatteryId);
|
_GetBatteryInfo(&fBatteryInfo, fBatteryID);
|
||||||
|
|
||||||
fPercent = (100 * fBatteryInfo.capacity) / fBatteryInfo.full_capacity;
|
fPercent = (100 * fBatteryInfo.capacity) / fBatteryInfo.full_capacity;
|
||||||
fTimeLeft = fBatteryInfo.time_left;
|
fTimeLeft = fBatteryInfo.time_left;
|
||||||
@@ -317,7 +347,7 @@ PowerStatusView::_Update(bool force)
|
|||||||
fOnline = true;
|
fOnline = true;
|
||||||
else
|
else
|
||||||
fOnline = false;
|
fOnline = false;
|
||||||
|
|
||||||
if (fInDeskbar) {
|
if (fInDeskbar) {
|
||||||
// make sure the tray icon is large enough
|
// make sure the tray icon is large enough
|
||||||
float width = fShowStatusIcon ? kMinIconWidth + 2 : 0;
|
float width = fShowStatusIcon ? kMinIconWidth + 2 : 0;
|
||||||
@@ -346,23 +376,24 @@ PowerStatusView::_Update(bool force)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PowerStatusView::_GetBatteryInfo(battery_info* batteryInfo, int batteryId)
|
PowerStatusView::_GetBatteryInfo(battery_info* batteryInfo, int batteryID)
|
||||||
{
|
{
|
||||||
if (batteryId >= 0) {
|
if (batteryID >= 0) {
|
||||||
fDriverInterface->GetBatteryInfo(batteryInfo, batteryId);
|
fDriverInterface->GetBatteryInfo(batteryInfo, batteryID);
|
||||||
}
|
} else {
|
||||||
else for (int i = 0; i < fDriverInterface->GetBatteryCount(); i++) {
|
for (int i = 0; i < fDriverInterface->GetBatteryCount(); i++) {
|
||||||
battery_info tmpInfo;
|
battery_info info;
|
||||||
fDriverInterface->GetBatteryInfo(&tmpInfo, i);
|
fDriverInterface->GetBatteryInfo(&info, i);
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
*batteryInfo = tmpInfo;
|
*batteryInfo = info;
|
||||||
else {
|
else {
|
||||||
batteryInfo->state &= tmpInfo.state;
|
batteryInfo->state &= info.state;
|
||||||
batteryInfo->capacity += tmpInfo.capacity;
|
batteryInfo->capacity += info.capacity;
|
||||||
batteryInfo->full_capacity += tmpInfo.full_capacity;
|
batteryInfo->full_capacity += info.full_capacity;
|
||||||
batteryInfo->time_left += tmpInfo.time_left;
|
batteryInfo->time_left += info.time_left;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,7 +402,7 @@ PowerStatusView::_GetBatteryInfo(battery_info* batteryInfo, int batteryId)
|
|||||||
|
|
||||||
|
|
||||||
PowerStatusReplicant::PowerStatusReplicant(BRect frame, int32 resizingMode,
|
PowerStatusReplicant::PowerStatusReplicant(BRect frame, int32 resizingMode,
|
||||||
bool inDeskbar)
|
bool inDeskbar)
|
||||||
:
|
:
|
||||||
PowerStatusView(NULL, frame, resizingMode, -1, inDeskbar)
|
PowerStatusView(NULL, frame, resizingMode, -1, inDeskbar)
|
||||||
{
|
{
|
||||||
@@ -386,7 +417,7 @@ PowerStatusReplicant::PowerStatusReplicant(BRect frame, int32 resizingMode,
|
|||||||
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||||
AddChild(dragger);
|
AddChild(dragger);
|
||||||
} else
|
} else
|
||||||
_Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -439,17 +470,17 @@ PowerStatusReplicant::MessageReceived(BMessage *message)
|
|||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kMsgToggleLabel:
|
case kMsgToggleLabel:
|
||||||
fShowLabel = !fShowLabel;
|
fShowLabel = !fShowLabel;
|
||||||
_Update(true);
|
Update(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgToggleTime:
|
case kMsgToggleTime:
|
||||||
fShowTime = !fShowTime;
|
fShowTime = !fShowTime;
|
||||||
_Update(true);
|
Update(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgToggleStatusIcon:
|
case kMsgToggleStatusIcon:
|
||||||
fShowStatusIcon = !fShowStatusIcon;
|
fShowStatusIcon = !fShowStatusIcon;
|
||||||
_Update(true);
|
Update(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgToggleExtInfo:
|
case kMsgToggleExtInfo:
|
||||||
@@ -488,9 +519,10 @@ PowerStatusReplicant::MouseDown(BPoint point)
|
|||||||
menu->AddItem(new BMenuItem(!fShowTime ? "Show Time" : "Show Percent",
|
menu->AddItem(new BMenuItem(!fShowTime ? "Show Time" : "Show Percent",
|
||||||
new BMessage(kMsgToggleTime)));
|
new BMessage(kMsgToggleTime)));
|
||||||
|
|
||||||
menu->AddItem(new BMenuItem("Battery Info",
|
menu->AddSeparatorItem();
|
||||||
|
menu->AddItem(new BMenuItem("Battery Info" B_UTF8_ELLIPSIS,
|
||||||
new BMessage(kMsgToggleExtInfo)));
|
new BMessage(kMsgToggleExtInfo)));
|
||||||
|
|
||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
menu->AddItem(new BMenuItem("About" B_UTF8_ELLIPSIS,
|
menu->AddItem(new BMenuItem("About" B_UTF8_ELLIPSIS,
|
||||||
new BMessage(B_ABOUT_REQUESTED)));
|
new BMessage(B_ABOUT_REQUESTED)));
|
||||||
@@ -535,7 +567,7 @@ PowerStatusReplicant::_Init()
|
|||||||
_Quit();
|
_Quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fExtendedWindow = NULL;
|
fExtendedWindow = NULL;
|
||||||
fMessengerExist = false;
|
fMessengerExist = false;
|
||||||
fExtWindowMessenger = NULL;
|
fExtWindowMessenger = NULL;
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
* Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Axel Dörfler, [email protected]
|
* Axel Dörfler, [email protected]
|
||||||
* Clemens Zeidler, [email protected]
|
* Clemens Zeidler, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef POWER_STATUS_VIEW_H
|
#ifndef POWER_STATUS_VIEW_H
|
||||||
#define POWER_STATUS_VIEW_H
|
#define POWER_STATUS_VIEW_H
|
||||||
|
|
||||||
@@ -17,77 +16,79 @@
|
|||||||
|
|
||||||
|
|
||||||
class PowerStatusView : public BView {
|
class PowerStatusView : public BView {
|
||||||
public:
|
public:
|
||||||
PowerStatusView(PowerStatusDriverInterface* interface,
|
PowerStatusView(
|
||||||
BRect frame, int32 resizingMode, int batteryId = -1,
|
PowerStatusDriverInterface* interface,
|
||||||
bool inDeskbar = false);
|
BRect frame, int32 resizingMode,
|
||||||
|
int batteryID = -1, bool inDeskbar = false);
|
||||||
virtual ~PowerStatusView();
|
|
||||||
|
|
||||||
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
virtual ~PowerStatusView();
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
||||||
virtual void DetachedFromWindow();
|
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void AttachedToWindow();
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void DetachedFromWindow();
|
||||||
virtual void GetPreferredSize(float *width, float *height);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
PowerStatusView(BMessage* archive);
|
|
||||||
|
|
||||||
virtual void _Update(bool force = false);
|
|
||||||
virtual void _GetBatteryInfo(battery_info* info, int batteryId);
|
|
||||||
|
|
||||||
PowerStatusDriverInterface* fDriverInterface;
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
virtual void Draw(BRect updateRect);
|
||||||
|
virtual void GetPreferredSize(float *width, float *height);
|
||||||
|
|
||||||
bool fShowLabel;
|
|
||||||
bool fShowTime;
|
|
||||||
bool fShowStatusIcon;
|
|
||||||
|
|
||||||
int fBatteryId;
|
|
||||||
bool fInDeskbar;
|
|
||||||
|
|
||||||
battery_info fBatteryInfo;
|
protected:
|
||||||
|
PowerStatusView(BMessage* archive);
|
||||||
|
|
||||||
private:
|
virtual void Update(bool force = false);
|
||||||
void _Init();
|
|
||||||
void _SetLabel(char* buffer, size_t bufferLength);
|
|
||||||
void _DrawBattery(BRect rect);
|
|
||||||
|
|
||||||
int32 fPercent;
|
private:
|
||||||
time_t fTimeLeft;
|
void _GetBatteryInfo(battery_info* info, int batteryID);
|
||||||
bool fOnline;
|
void _Init();
|
||||||
|
void _SetLabel(char* buffer, size_t bufferLength);
|
||||||
|
void _DrawBattery(BRect rect);
|
||||||
|
|
||||||
BSize fPreferredSize;
|
protected:
|
||||||
|
PowerStatusDriverInterface* fDriverInterface;
|
||||||
|
|
||||||
|
bool fShowLabel;
|
||||||
|
bool fShowTime;
|
||||||
|
bool fShowStatusIcon;
|
||||||
|
|
||||||
|
int fBatteryID;
|
||||||
|
bool fInDeskbar;
|
||||||
|
|
||||||
|
battery_info fBatteryInfo;
|
||||||
|
|
||||||
|
int32 fPercent;
|
||||||
|
time_t fTimeLeft;
|
||||||
|
bool fOnline;
|
||||||
|
|
||||||
|
BSize fPreferredSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class PowerStatusReplicant : public PowerStatusView
|
class PowerStatusReplicant : public PowerStatusView {
|
||||||
{
|
public:
|
||||||
public:
|
PowerStatusReplicant(BRect frame,
|
||||||
PowerStatusReplicant(BRect frame, int32 resizingMode,
|
int32 resizingMode, bool inDeskbar = false);
|
||||||
bool inDeskbar = false);
|
PowerStatusReplicant(BMessage* archive);
|
||||||
PowerStatusReplicant(BMessage* archive);
|
virtual ~PowerStatusReplicant();
|
||||||
|
|
||||||
virtual ~PowerStatusReplicant();
|
static PowerStatusReplicant* Instantiate(BMessage* archive);
|
||||||
|
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
||||||
|
|
||||||
static PowerStatusReplicant* Instantiate(BMessage* archive);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
virtual void MouseDown(BPoint where);
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage* message);
|
private:
|
||||||
virtual void MouseDown(BPoint where);
|
void _AboutRequested();
|
||||||
|
void _Init();
|
||||||
|
void _Quit();
|
||||||
|
|
||||||
private:
|
void _OpenExtendedWindow();
|
||||||
void _AboutRequested();
|
|
||||||
void _Init();
|
|
||||||
void _Quit();
|
|
||||||
|
|
||||||
void _OpenExtendedWindow();
|
|
||||||
|
|
||||||
BWindow* fExtendedWindow;
|
private:
|
||||||
bool fMessengerExist;
|
BWindow* fExtendedWindow;
|
||||||
BMessenger* fExtWindowMessenger;
|
bool fMessengerExist;
|
||||||
|
BMessenger* fExtWindowMessenger;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user