xref: /haiku/src/apps/powerstatus/ExtendedInfoWindow.cpp (revision 8b24b02f060e46f2714889158df0b1535850995d)
16aed176cSClemens Zeidler /*
26aed176cSClemens Zeidler  * Copyright 2006, Haiku, Inc. All Rights Reserved.
36aed176cSClemens Zeidler  * Distributed under the terms of the MIT License.
46aed176cSClemens Zeidler  *
56aed176cSClemens Zeidler  * Authors:
66aed176cSClemens Zeidler  *		Clemens Zeidler, haiku@Clemens-Zeidler.de
76aed176cSClemens Zeidler  */
86aed176cSClemens Zeidler 
96aed176cSClemens Zeidler #include "ExtendedInfoWindow.h"
106aed176cSClemens Zeidler 
116aed176cSClemens Zeidler #include <Box.h>
126aed176cSClemens Zeidler #include <GroupLayout.h>
136aed176cSClemens Zeidler #include <GroupView.h>
146aed176cSClemens Zeidler #include <SpaceLayoutItem.h>
15*8b24b02fSClemens Zeidler #include <Screen.h>
166aed176cSClemens Zeidler #include <String.h>
176aed176cSClemens Zeidler 
186aed176cSClemens Zeidler 
19e391ec67SClemens Zeidler FontString::FontString()
20e391ec67SClemens Zeidler {
21e391ec67SClemens Zeidler 	font = be_plain_font;
22e391ec67SClemens Zeidler }
23e391ec67SClemens Zeidler 
24e391ec67SClemens Zeidler 
25e391ec67SClemens Zeidler const int kLineSpacing = 5;
26e391ec67SClemens Zeidler 
27e391ec67SClemens Zeidler BatteryInfoView::BatteryInfoView()
286aed176cSClemens Zeidler 	:
29e391ec67SClemens Zeidler 	BView("battery info view", B_WILL_DRAW |
30e391ec67SClemens Zeidler 		B_FULL_UPDATE_ON_RESIZE),
31e391ec67SClemens Zeidler 	fPreferredSize(200, 200),
32e391ec67SClemens Zeidler 	fMaxStringSize(0, 0)
336aed176cSClemens Zeidler {
346aed176cSClemens Zeidler 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
356aed176cSClemens Zeidler }
366aed176cSClemens Zeidler 
376aed176cSClemens Zeidler 
38e391ec67SClemens Zeidler BatteryInfoView::~BatteryInfoView()
39e391ec67SClemens Zeidler {
40e391ec67SClemens Zeidler 	_ClearStringList();
41e391ec67SClemens Zeidler }
42e391ec67SClemens Zeidler 
43e391ec67SClemens Zeidler 
446aed176cSClemens Zeidler void
456aed176cSClemens Zeidler BatteryInfoView::Update(battery_info& info, acpi_extended_battery_info& extInfo)
466aed176cSClemens Zeidler {
476aed176cSClemens Zeidler 	fBatteryInfo = info;
486aed176cSClemens Zeidler 	fBatteryExtendedInfo = extInfo;
49e391ec67SClemens Zeidler 
50e391ec67SClemens Zeidler 	_FillStringList();
516aed176cSClemens Zeidler }
526aed176cSClemens Zeidler 
536aed176cSClemens Zeidler 
546aed176cSClemens Zeidler void
556aed176cSClemens Zeidler BatteryInfoView::Draw(BRect updateRect)
566aed176cSClemens Zeidler {
576aed176cSClemens Zeidler 	SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
586aed176cSClemens Zeidler 
59e391ec67SClemens Zeidler 	BPoint point(10, 10);
60e391ec67SClemens Zeidler 
61e391ec67SClemens Zeidler 	float space = _MeasureString("").height + kLineSpacing;
62e391ec67SClemens Zeidler 
63e391ec67SClemens Zeidler 	for (int i = 0; i < fStringList.CountItems(); i ++)
64e391ec67SClemens Zeidler 	{
65e391ec67SClemens Zeidler 		FontString* fontString = fStringList.ItemAt(i);
66e391ec67SClemens Zeidler 		SetFont(fontString->font);
67e391ec67SClemens Zeidler 		DrawString(fontString->string.String(), point);
68e391ec67SClemens Zeidler 		point.y += space;
69e391ec67SClemens Zeidler 	}
70e391ec67SClemens Zeidler }
71e391ec67SClemens Zeidler 
72e391ec67SClemens Zeidler 
73e391ec67SClemens Zeidler void
74e391ec67SClemens Zeidler BatteryInfoView::GetPreferredSize(float *width, float *height)
75e391ec67SClemens Zeidler {
76e391ec67SClemens Zeidler 	*width = fPreferredSize.width;
77e391ec67SClemens Zeidler 	*height = fPreferredSize.height;
78e391ec67SClemens Zeidler }
79e391ec67SClemens Zeidler 
80e391ec67SClemens Zeidler 
81*8b24b02fSClemens Zeidler void
82*8b24b02fSClemens Zeidler BatteryInfoView::AttachedToWindow()
83*8b24b02fSClemens Zeidler {
84*8b24b02fSClemens Zeidler 	BRect rect = BScreen().Frame();
85*8b24b02fSClemens Zeidler 	BRect windowFrame = Window()->Frame();
86*8b24b02fSClemens Zeidler 	BPoint position;
87*8b24b02fSClemens Zeidler 	// center window on screen
88*8b24b02fSClemens Zeidler 	position.x = (rect.Width() - windowFrame.Width()) / 2;
89*8b24b02fSClemens Zeidler 	position.y = (rect.Height() - windowFrame.Height()) / 2;
90*8b24b02fSClemens Zeidler 	Window()->MoveTo(position);
91*8b24b02fSClemens Zeidler }
92*8b24b02fSClemens Zeidler 
93*8b24b02fSClemens Zeidler 
94e391ec67SClemens Zeidler BSize
95e391ec67SClemens Zeidler BatteryInfoView::_MeasureString(const BString& string)
96e391ec67SClemens Zeidler {
97e391ec67SClemens Zeidler 	BFont font;
98e391ec67SClemens Zeidler 	GetFont(&font);
99e391ec67SClemens Zeidler 	BSize size;
100e391ec67SClemens Zeidler 
101e391ec67SClemens Zeidler 	size.width = font.StringWidth(string);
102e391ec67SClemens Zeidler 
103e391ec67SClemens Zeidler 	font_height height;
104e391ec67SClemens Zeidler 	font.GetHeight(&height);
105e391ec67SClemens Zeidler 	size.height = height.ascent + height.descent;
106e391ec67SClemens Zeidler 
107e391ec67SClemens Zeidler 	return size;
108e391ec67SClemens Zeidler }
109e391ec67SClemens Zeidler 
110e391ec67SClemens Zeidler 
111e391ec67SClemens Zeidler void
112e391ec67SClemens Zeidler BatteryInfoView::_FillStringList()
113e391ec67SClemens Zeidler {
114e391ec67SClemens Zeidler 	_ClearStringList();
115e391ec67SClemens Zeidler 
1166aed176cSClemens Zeidler 	BString powerUnit;
1176aed176cSClemens Zeidler 	BString rateUnit;
1186aed176cSClemens Zeidler 	switch (fBatteryExtendedInfo.power_unit) {
1196aed176cSClemens Zeidler 		case 0:
1206aed176cSClemens Zeidler 			powerUnit = " mWh";
1216aed176cSClemens Zeidler 			rateUnit = " mW";
1226aed176cSClemens Zeidler 			break;
1236aed176cSClemens Zeidler 
1246aed176cSClemens Zeidler 		case 1:
1256aed176cSClemens Zeidler 			powerUnit = " mAh";
1266aed176cSClemens Zeidler 			rateUnit = " mA";
1276aed176cSClemens Zeidler 			break;
1286aed176cSClemens Zeidler 	}
1296aed176cSClemens Zeidler 
130e391ec67SClemens Zeidler 	FontString* fontString;
131e391ec67SClemens Zeidler 
132e391ec67SClemens Zeidler 	fontString = new FontString;
133e391ec67SClemens Zeidler 	fStringList.AddItem(fontString);
134e391ec67SClemens Zeidler 	fontString->font = be_bold_font;
135e391ec67SClemens Zeidler 
1366aed176cSClemens Zeidler 	if (fBatteryInfo.state & BATTERY_CHARGING)
137e391ec67SClemens Zeidler 		fontString->string = "Battery charging";
1386aed176cSClemens Zeidler 	else if (fBatteryInfo.state & BATTERY_DISCHARGING)
139e391ec67SClemens Zeidler 		fontString->string = "Battery discharging";
1406aed176cSClemens Zeidler 	else if (fBatteryInfo.state & BATTERY_CRITICAL_STATE)
141e391ec67SClemens Zeidler 		fontString->string = "Empty Battery Slot";
1426aed176cSClemens Zeidler 	else
143e391ec67SClemens Zeidler 		fontString->string = "Battery unused";
1446aed176cSClemens Zeidler 
145e391ec67SClemens Zeidler 	fontString = new FontString;
146e391ec67SClemens Zeidler 	fontString->string = "Capacity: ";
147e391ec67SClemens Zeidler 	fontString->string << fBatteryInfo.capacity;
148e391ec67SClemens Zeidler 	fontString->string << powerUnit;
149e391ec67SClemens Zeidler 	_AddToStringList(fontString);
1506aed176cSClemens Zeidler 
151e391ec67SClemens Zeidler 	fontString = new FontString;
152e391ec67SClemens Zeidler 	fontString->string = "Last full Charge: ";
153e391ec67SClemens Zeidler 	fontString->string << fBatteryInfo.full_capacity;
154e391ec67SClemens Zeidler 	fontString->string << powerUnit;
155e391ec67SClemens Zeidler 	_AddToStringList(fontString);
1566aed176cSClemens Zeidler 
157e391ec67SClemens Zeidler 	fontString = new FontString;
158e391ec67SClemens Zeidler 	fontString->string = "Current Rate: ";
159e391ec67SClemens Zeidler 	fontString->string << fBatteryInfo.current_rate;
160e391ec67SClemens Zeidler 	fontString->string << rateUnit;
161e391ec67SClemens Zeidler 	_AddToStringList(fontString);
1626aed176cSClemens Zeidler 
163e391ec67SClemens Zeidler 	// empty line
164e391ec67SClemens Zeidler 	fontString = new FontString;
165e391ec67SClemens Zeidler 	_AddToStringList(fontString);
1666aed176cSClemens Zeidler 
167e391ec67SClemens Zeidler 	fontString = new FontString;
168e391ec67SClemens Zeidler 	fontString->string = "Design Capacity: ";
169e391ec67SClemens Zeidler 	fontString->string << fBatteryExtendedInfo.design_capacity;
170e391ec67SClemens Zeidler 	fontString->string << powerUnit;
171e391ec67SClemens Zeidler 	_AddToStringList(fontString);
1726aed176cSClemens Zeidler 
173e391ec67SClemens Zeidler 	fontString = new FontString;
174e391ec67SClemens Zeidler 	fontString->string = "Technology: ";
175b636a0ecSClemens Zeidler 	if (fBatteryExtendedInfo.technology == 0)
176b636a0ecSClemens Zeidler 		fontString->string << "non-rechargeable";
177b636a0ecSClemens Zeidler 	else if (fBatteryExtendedInfo.technology == 1)
178b636a0ecSClemens Zeidler 		fontString->string << "rechargeable";
179b636a0ecSClemens Zeidler 	else
180b636a0ecSClemens Zeidler 		fontString->string << "?";
181e391ec67SClemens Zeidler 	_AddToStringList(fontString);
1826aed176cSClemens Zeidler 
183e391ec67SClemens Zeidler 	fontString = new FontString;
184e391ec67SClemens Zeidler 	fontString->string = "Design Voltage: ";
185e391ec67SClemens Zeidler 	fontString->string << fBatteryExtendedInfo.design_voltage;
186e391ec67SClemens Zeidler 	fontString->string << " mV";
187e391ec67SClemens Zeidler 	_AddToStringList(fontString);
1886aed176cSClemens Zeidler 
189e391ec67SClemens Zeidler 	fontString = new FontString;
190e391ec67SClemens Zeidler 	fontString->string = "Design Capacity Warning: ";
191e391ec67SClemens Zeidler 	fontString->string << fBatteryExtendedInfo.design_capacity_warning;
192e391ec67SClemens Zeidler 	fontString->string << powerUnit;
193e391ec67SClemens Zeidler 	_AddToStringList(fontString);
1946aed176cSClemens Zeidler 
195e391ec67SClemens Zeidler 	fontString = new FontString;
196e391ec67SClemens Zeidler 	fontString->string = "Design Capacity low Warning: ";
197e391ec67SClemens Zeidler 	fontString->string << fBatteryExtendedInfo.design_capacity_low;
198e391ec67SClemens Zeidler 	fontString->string << powerUnit;
199e391ec67SClemens Zeidler 	_AddToStringList(fontString);
2006aed176cSClemens Zeidler 
201e391ec67SClemens Zeidler 	fontString = new FontString;
202e391ec67SClemens Zeidler 	fontString->string = "Capacity Granularity 1: ";
203e391ec67SClemens Zeidler 	fontString->string << fBatteryExtendedInfo.capacity_granularity_1;
204b636a0ecSClemens Zeidler 	fontString->string << powerUnit;
205e391ec67SClemens Zeidler 	_AddToStringList(fontString);
2066aed176cSClemens Zeidler 
207e391ec67SClemens Zeidler 	fontString = new FontString;
208e391ec67SClemens Zeidler 	fontString->string = "Capacity Granularity 2: ";
209e391ec67SClemens Zeidler 	fontString->string << fBatteryExtendedInfo.capacity_granularity_2;
210b636a0ecSClemens Zeidler 	fontString->string << powerUnit;
211e391ec67SClemens Zeidler 	_AddToStringList(fontString);
2126aed176cSClemens Zeidler 
213e391ec67SClemens Zeidler 	fontString = new FontString;
214e391ec67SClemens Zeidler 	fontString->string = "Model Number: ";
215e391ec67SClemens Zeidler 	fontString->string << fBatteryExtendedInfo.model_number;
216e391ec67SClemens Zeidler 	_AddToStringList(fontString);
2176aed176cSClemens Zeidler 
218e391ec67SClemens Zeidler 	fontString = new FontString;
219e391ec67SClemens Zeidler 	fontString->string = "Serial number: ";
220e391ec67SClemens Zeidler 	fontString->string << fBatteryExtendedInfo.serial_number;
221e391ec67SClemens Zeidler 	_AddToStringList(fontString);
2226aed176cSClemens Zeidler 
223e391ec67SClemens Zeidler 	fontString = new FontString;
224e391ec67SClemens Zeidler 	fontString->string = "Type: ";
225e391ec67SClemens Zeidler 	fontString->string += fBatteryExtendedInfo.type;
226e391ec67SClemens Zeidler 	_AddToStringList(fontString);
2276aed176cSClemens Zeidler 
228e391ec67SClemens Zeidler 	fontString = new FontString;
229e391ec67SClemens Zeidler 	fontString->string = "OEM Info: ";
230e391ec67SClemens Zeidler 	fontString->string += fBatteryExtendedInfo.oem_info;
231e391ec67SClemens Zeidler 	_AddToStringList(fontString);
2326aed176cSClemens Zeidler 
233e391ec67SClemens Zeidler 	fPreferredSize.width = fMaxStringSize.width + 10;
234e391ec67SClemens Zeidler 	fPreferredSize.height = (fMaxStringSize.height + kLineSpacing) *
235e391ec67SClemens Zeidler 		fStringList.CountItems();
236e391ec67SClemens Zeidler }
237e391ec67SClemens Zeidler 
238e391ec67SClemens Zeidler 
239e391ec67SClemens Zeidler void
240e391ec67SClemens Zeidler BatteryInfoView::_AddToStringList(FontString* fontString)
241e391ec67SClemens Zeidler {
242e391ec67SClemens Zeidler 	fStringList.AddItem(fontString);
243e391ec67SClemens Zeidler 	BSize stringSize = _MeasureString(fontString->string);
244e391ec67SClemens Zeidler 	if (fMaxStringSize.width < stringSize.width)
245e391ec67SClemens Zeidler 		fMaxStringSize = stringSize;
246e391ec67SClemens Zeidler }
247e391ec67SClemens Zeidler 
248e391ec67SClemens Zeidler 
249e391ec67SClemens Zeidler void
250e391ec67SClemens Zeidler BatteryInfoView::_ClearStringList()
251e391ec67SClemens Zeidler {
252e391ec67SClemens Zeidler 	for (int i = 0; i < fStringList.CountItems(); i ++)
253e391ec67SClemens Zeidler 		delete fStringList.ItemAt(i);
254e391ec67SClemens Zeidler 	fStringList.MakeEmpty();
255e391ec67SClemens Zeidler 	fMaxStringSize = BSize(0, 0);
2566aed176cSClemens Zeidler }
2576aed176cSClemens Zeidler 
2586aed176cSClemens Zeidler 
2596aed176cSClemens Zeidler ExtPowerStatusView::ExtPowerStatusView(PowerStatusDriverInterface* interface,
2606aed176cSClemens Zeidler 			BRect frame, int32 resizingMode, int batteryId,
2616aed176cSClemens Zeidler 			ExtendedInfoWindow* window)
2626aed176cSClemens Zeidler 	:
2636aed176cSClemens Zeidler 	PowerStatusView(interface, frame, resizingMode, batteryId),
2646aed176cSClemens Zeidler 	fExtendedInfoWindow(window),
2656aed176cSClemens Zeidler 	fBatteryInfoView(window->GetExtendedBatteryInfoView()),
2666aed176cSClemens Zeidler 	fSelected(false)
2676aed176cSClemens Zeidler {
2686aed176cSClemens Zeidler 
2696aed176cSClemens Zeidler }
2706aed176cSClemens Zeidler 
2716aed176cSClemens Zeidler 
2726aed176cSClemens Zeidler void
2736aed176cSClemens Zeidler ExtPowerStatusView::Draw(BRect updateRect)
2746aed176cSClemens Zeidler {
2756aed176cSClemens Zeidler 	if (fSelected) {
2766aed176cSClemens Zeidler 		SetLowColor(102, 152, 203);
2776aed176cSClemens Zeidler 		SetHighColor(102, 152, 203);
2786aed176cSClemens Zeidler 		FillRect(updateRect);
2796aed176cSClemens Zeidler 	}
2806aed176cSClemens Zeidler 	else {
2816aed176cSClemens Zeidler 		SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
2826aed176cSClemens Zeidler 		SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
2836aed176cSClemens Zeidler 		FillRect(updateRect);
2846aed176cSClemens Zeidler 	}
2856aed176cSClemens Zeidler 
2866aed176cSClemens Zeidler 	PowerStatusView::Draw(updateRect);
2876aed176cSClemens Zeidler }
2886aed176cSClemens Zeidler 
2896aed176cSClemens Zeidler 
2906aed176cSClemens Zeidler void
2916aed176cSClemens Zeidler ExtPowerStatusView::MouseDown(BPoint where)
2926aed176cSClemens Zeidler {
2936aed176cSClemens Zeidler 	if (!fSelected) {
2946aed176cSClemens Zeidler 		fSelected = true;
2956aed176cSClemens Zeidler 		_Update(true);
2966aed176cSClemens Zeidler 		fExtendedInfoWindow->BatterySelected(this);
2976aed176cSClemens Zeidler 	}
2986aed176cSClemens Zeidler }
2996aed176cSClemens Zeidler 
3006aed176cSClemens Zeidler 
3016aed176cSClemens Zeidler void
3026aed176cSClemens Zeidler ExtPowerStatusView::Select(bool select)
3036aed176cSClemens Zeidler {
3046aed176cSClemens Zeidler 	fSelected = select;
3056aed176cSClemens Zeidler 	_Update(true);
3066aed176cSClemens Zeidler }
3076aed176cSClemens Zeidler 
3086aed176cSClemens Zeidler 
3096aed176cSClemens Zeidler bool
3106aed176cSClemens Zeidler ExtPowerStatusView::IsValid()
3116aed176cSClemens Zeidler {
3126aed176cSClemens Zeidler 	if (fBatteryInfo.state & BATTERY_CRITICAL_STATE)
3136aed176cSClemens Zeidler 		return false;
3146aed176cSClemens Zeidler 	return true;
3156aed176cSClemens Zeidler }
3166aed176cSClemens Zeidler 
3176aed176cSClemens Zeidler 
3186aed176cSClemens Zeidler void
3196aed176cSClemens Zeidler ExtPowerStatusView::_Update(bool force)
3206aed176cSClemens Zeidler {
3216aed176cSClemens Zeidler 	PowerStatusView::_Update(force);
3226aed176cSClemens Zeidler 	if (!fSelected)
3236aed176cSClemens Zeidler 		return;
3246aed176cSClemens Zeidler 
3256aed176cSClemens Zeidler 	acpi_extended_battery_info extInfo;
3266aed176cSClemens Zeidler 	fDriverInterface->GetExtendedBatteryInfo(&extInfo, fBatteryId);
3276aed176cSClemens Zeidler 
3286aed176cSClemens Zeidler 	fBatteryInfoView->Update(fBatteryInfo, extInfo);
3296aed176cSClemens Zeidler 	fBatteryInfoView->Invalidate();
3306aed176cSClemens Zeidler }
3316aed176cSClemens Zeidler 
3326aed176cSClemens Zeidler 
3336aed176cSClemens Zeidler ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
3346aed176cSClemens Zeidler 	:
3356aed176cSClemens Zeidler 	BWindow(BRect(100, 150, 500, 500), "Extended Battery Info", B_TITLED_WINDOW,
336e391ec67SClemens Zeidler 		B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AVOID_FRONT |
337e391ec67SClemens Zeidler 		B_ASYNCHRONOUS_CONTROLS),
3386aed176cSClemens Zeidler 	fDriverInterface(interface),
3396aed176cSClemens Zeidler 	fSelectedView(NULL)
3406aed176cSClemens Zeidler {
3416aed176cSClemens Zeidler 	BView *view = new BView(Bounds(), "view", B_FOLLOW_ALL, 0);
3426aed176cSClemens Zeidler 	view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
3436aed176cSClemens Zeidler 	AddChild(view);
3446aed176cSClemens Zeidler 
3456aed176cSClemens Zeidler 	BGroupLayout* mainLayout = new BGroupLayout(B_VERTICAL);
3466aed176cSClemens Zeidler 	mainLayout->SetSpacing(10);
3476aed176cSClemens Zeidler 	mainLayout->SetInsets(10, 10, 10, 10);
3486aed176cSClemens Zeidler 	view->SetLayout(mainLayout);
3496aed176cSClemens Zeidler 
3506aed176cSClemens Zeidler 	BRect rect = Bounds();
3516aed176cSClemens Zeidler 	rect.InsetBy(5, 5);
3526aed176cSClemens Zeidler 	BBox *infoBox = new BBox(rect, "Power Status Box");
3536aed176cSClemens Zeidler 	infoBox->SetLabel("Battery Info");
3546aed176cSClemens Zeidler 	BGroupLayout* infoLayout = new BGroupLayout(B_HORIZONTAL);
3556aed176cSClemens Zeidler 	infoLayout->SetInsets(10, infoBox->TopBorderOffset() * 2 + 10, 10, 10);
3566aed176cSClemens Zeidler 	infoLayout->SetSpacing(10);
3576aed176cSClemens Zeidler 	infoBox->SetLayout(infoLayout);
3586aed176cSClemens Zeidler 	mainLayout->AddView(infoBox);
3596aed176cSClemens Zeidler 
3606aed176cSClemens Zeidler 	BGroupView* batteryView = new BGroupView(B_VERTICAL);
3616aed176cSClemens Zeidler 	batteryView->GroupLayout()->SetSpacing(10);
3626aed176cSClemens Zeidler 	infoLayout->AddView(batteryView);
3636aed176cSClemens Zeidler 
364e391ec67SClemens Zeidler 	// create before the battery views
365e391ec67SClemens Zeidler 	fBatteryInfoView = new BatteryInfoView();
3666aed176cSClemens Zeidler 
3676aed176cSClemens Zeidler 	BGroupLayout* batteryLayout = batteryView->GroupLayout();
3686aed176cSClemens Zeidler 	BRect batteryRect(0, 0, 50, 30);
3696aed176cSClemens Zeidler 	for (int i = 0; i < interface->GetBatteryCount(); i++) {
3706aed176cSClemens Zeidler 		ExtPowerStatusView* view = new ExtPowerStatusView(interface,
371e391ec67SClemens Zeidler 			batteryRect, B_FOLLOW_NONE, i, this);
372e391ec67SClemens Zeidler 		view->SetExplicitMaxSize(BSize(70, 80));
373e391ec67SClemens Zeidler 		view->SetExplicitMinSize(BSize(70, 80));
374e391ec67SClemens Zeidler 
3756aed176cSClemens Zeidler 		batteryLayout->AddView(view);
3766aed176cSClemens Zeidler 		fBatteryViewList.AddItem(view);
3776aed176cSClemens Zeidler 		fDriverInterface->StartWatching(view);
3786aed176cSClemens Zeidler 		if (view->IsValid())
3796aed176cSClemens Zeidler 			fSelectedView = view;
3806aed176cSClemens Zeidler 	}
3816aed176cSClemens Zeidler 
3826aed176cSClemens Zeidler 	batteryLayout->AddItem(BSpaceLayoutItem::CreateGlue());
3836aed176cSClemens Zeidler 
384e391ec67SClemens Zeidler 	infoLayout->AddView(fBatteryInfoView);
3856aed176cSClemens Zeidler 
3866aed176cSClemens Zeidler 	if (!fSelectedView && fBatteryViewList.CountItems() > 0)
3876aed176cSClemens Zeidler 		fSelectedView = fBatteryViewList.ItemAt(0);
3886aed176cSClemens Zeidler 	fSelectedView->Select();
3896aed176cSClemens Zeidler 
3906aed176cSClemens Zeidler 	BSize size = mainLayout->PreferredSize();
3916aed176cSClemens Zeidler 	ResizeTo(size.width, size.height);
3926aed176cSClemens Zeidler }
3936aed176cSClemens Zeidler 
3946aed176cSClemens Zeidler 
3956aed176cSClemens Zeidler ExtendedInfoWindow::~ExtendedInfoWindow()
3966aed176cSClemens Zeidler {
3976aed176cSClemens Zeidler 	for (int i = 0; i < fBatteryViewList.CountItems(); i++) {
3986aed176cSClemens Zeidler 		fDriverInterface->StopWatching(fBatteryViewList.ItemAt(i));
3996aed176cSClemens Zeidler 	}
4006aed176cSClemens Zeidler }
4016aed176cSClemens Zeidler 
4026aed176cSClemens Zeidler 
4036aed176cSClemens Zeidler BatteryInfoView*
4046aed176cSClemens Zeidler ExtendedInfoWindow::GetExtendedBatteryInfoView()
4056aed176cSClemens Zeidler {
4066aed176cSClemens Zeidler 	return fBatteryInfoView;
4076aed176cSClemens Zeidler }
4086aed176cSClemens Zeidler 
4096aed176cSClemens Zeidler 
4106aed176cSClemens Zeidler void
4116aed176cSClemens Zeidler ExtendedInfoWindow::BatterySelected(ExtPowerStatusView* view)
4126aed176cSClemens Zeidler {
4136aed176cSClemens Zeidler 	if (fSelectedView) {
4146aed176cSClemens Zeidler 		fSelectedView->Select(false);
4156aed176cSClemens Zeidler 		fSelectedView->Invalidate();
4166aed176cSClemens Zeidler 	}
4176aed176cSClemens Zeidler 
4186aed176cSClemens Zeidler 	fSelectedView = view;
4196aed176cSClemens Zeidler }
420