16aed176cSClemens Zeidler /* 2bd767f5aSAxel Dörfler * Copyright 2009, 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 9bd767f5aSAxel Dörfler 106aed176cSClemens Zeidler #include "ExtendedInfoWindow.h" 116aed176cSClemens Zeidler 126aed176cSClemens Zeidler #include <Box.h> 133bd54e05SAdrien Destugues #include <Catalog.h> 146aed176cSClemens Zeidler #include <GroupView.h> 156aed176cSClemens Zeidler #include <SpaceLayoutItem.h> 166aed176cSClemens Zeidler 176aed176cSClemens Zeidler 18*546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT 19*546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "PowerStatus" 203bd54e05SAdrien Destugues 213bd54e05SAdrien Destugues 22bd767f5aSAxel Dörfler const int kLineSpacing = 5; 23bd767f5aSAxel Dörfler 24bd767f5aSAxel Dörfler 25e391ec67SClemens Zeidler FontString::FontString() 26e391ec67SClemens Zeidler { 27e391ec67SClemens Zeidler font = be_plain_font; 28e391ec67SClemens Zeidler } 29e391ec67SClemens Zeidler 30e391ec67SClemens Zeidler 31bd767f5aSAxel Dörfler // #pragma mark - 32bd767f5aSAxel Dörfler 33e391ec67SClemens Zeidler 34e391ec67SClemens Zeidler BatteryInfoView::BatteryInfoView() 356aed176cSClemens Zeidler : 36bd767f5aSAxel Dörfler BView("battery info view", B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE), 37e391ec67SClemens Zeidler fPreferredSize(200, 200), 38e391ec67SClemens Zeidler fMaxStringSize(0, 0) 396aed176cSClemens Zeidler { 406aed176cSClemens Zeidler SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 416aed176cSClemens Zeidler } 426aed176cSClemens Zeidler 436aed176cSClemens Zeidler 44e391ec67SClemens Zeidler BatteryInfoView::~BatteryInfoView() 45e391ec67SClemens Zeidler { 46e391ec67SClemens Zeidler _ClearStringList(); 47e391ec67SClemens Zeidler } 48e391ec67SClemens Zeidler 49e391ec67SClemens Zeidler 506aed176cSClemens Zeidler void 516aed176cSClemens Zeidler BatteryInfoView::Update(battery_info& info, acpi_extended_battery_info& extInfo) 526aed176cSClemens Zeidler { 536aed176cSClemens Zeidler fBatteryInfo = info; 546aed176cSClemens Zeidler fBatteryExtendedInfo = extInfo; 55e391ec67SClemens Zeidler 56e391ec67SClemens Zeidler _FillStringList(); 576aed176cSClemens Zeidler } 586aed176cSClemens Zeidler 596aed176cSClemens Zeidler 606aed176cSClemens Zeidler void 616aed176cSClemens Zeidler BatteryInfoView::Draw(BRect updateRect) 626aed176cSClemens Zeidler { 636aed176cSClemens Zeidler SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 646aed176cSClemens Zeidler 65e391ec67SClemens Zeidler BPoint point(10, 10); 66e391ec67SClemens Zeidler 67e391ec67SClemens Zeidler float space = _MeasureString("").height + kLineSpacing; 68e391ec67SClemens Zeidler 69bd767f5aSAxel Dörfler for (int i = 0; i < fStringList.CountItems(); i++) { 70e391ec67SClemens Zeidler FontString* fontString = fStringList.ItemAt(i); 71e391ec67SClemens Zeidler SetFont(fontString->font); 72e391ec67SClemens Zeidler DrawString(fontString->string.String(), point); 73e391ec67SClemens Zeidler point.y += space; 74e391ec67SClemens Zeidler } 75e391ec67SClemens Zeidler } 76e391ec67SClemens Zeidler 77e391ec67SClemens Zeidler 78e391ec67SClemens Zeidler void 79e391ec67SClemens Zeidler BatteryInfoView::GetPreferredSize(float* width, float* height) 80e391ec67SClemens Zeidler { 81e391ec67SClemens Zeidler *width = fPreferredSize.width; 82e391ec67SClemens Zeidler *height = fPreferredSize.height; 83e391ec67SClemens Zeidler } 84e391ec67SClemens Zeidler 85e391ec67SClemens Zeidler 868b24b02fSClemens Zeidler void 878b24b02fSClemens Zeidler BatteryInfoView::AttachedToWindow() 888b24b02fSClemens Zeidler { 893e1f071cSClemens Zeidler Window()->CenterOnScreen(); 908b24b02fSClemens Zeidler } 918b24b02fSClemens Zeidler 928b24b02fSClemens Zeidler 93e391ec67SClemens Zeidler BSize 94e391ec67SClemens Zeidler BatteryInfoView::_MeasureString(const BString& string) 95e391ec67SClemens Zeidler { 96e391ec67SClemens Zeidler BFont font; 97e391ec67SClemens Zeidler GetFont(&font); 98e391ec67SClemens Zeidler BSize size; 99e391ec67SClemens Zeidler 100e391ec67SClemens Zeidler size.width = font.StringWidth(string); 101e391ec67SClemens Zeidler 102e391ec67SClemens Zeidler font_height height; 103e391ec67SClemens Zeidler font.GetHeight(&height); 104e391ec67SClemens Zeidler size.height = height.ascent + height.descent; 105e391ec67SClemens Zeidler 106e391ec67SClemens Zeidler return size; 107e391ec67SClemens Zeidler } 108e391ec67SClemens Zeidler 109e391ec67SClemens Zeidler 110e391ec67SClemens Zeidler void 111e391ec67SClemens Zeidler BatteryInfoView::_FillStringList() 112e391ec67SClemens Zeidler { 113e391ec67SClemens Zeidler _ClearStringList(); 114e391ec67SClemens Zeidler 1156aed176cSClemens Zeidler BString powerUnit; 1166aed176cSClemens Zeidler BString rateUnit; 1176aed176cSClemens Zeidler switch (fBatteryExtendedInfo.power_unit) { 1186aed176cSClemens Zeidler case 0: 1193bd54e05SAdrien Destugues powerUnit = B_TRANSLATE(" mWh"); 1203bd54e05SAdrien Destugues rateUnit = B_TRANSLATE(" mW"); 1216aed176cSClemens Zeidler break; 1226aed176cSClemens Zeidler 1236aed176cSClemens Zeidler case 1: 1243bd54e05SAdrien Destugues powerUnit = B_TRANSLATE(" mAh"); 1253bd54e05SAdrien Destugues rateUnit = B_TRANSLATE(" mA"); 1266aed176cSClemens Zeidler break; 1276aed176cSClemens Zeidler } 1286aed176cSClemens Zeidler 129e391ec67SClemens Zeidler FontString* fontString; 130e391ec67SClemens Zeidler 131e391ec67SClemens Zeidler fontString = new FontString; 132e391ec67SClemens Zeidler fStringList.AddItem(fontString); 133e391ec67SClemens Zeidler fontString->font = be_bold_font; 134e391ec67SClemens Zeidler 135a11e2f43SAxel Dörfler if ((fBatteryInfo.state & BATTERY_CHARGING) != 0) 1363bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Battery charging"); 137a11e2f43SAxel Dörfler else if ((fBatteryInfo.state & BATTERY_DISCHARGING) != 0) 1383bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Battery discharging"); 139a11e2f43SAxel Dörfler else if ((fBatteryInfo.state & BATTERY_CRITICAL_STATE) != 0 140829200a0SAlexander von Gluck IV && fBatteryExtendedInfo.model_number[0] == '\0' 141829200a0SAlexander von Gluck IV && fBatteryExtendedInfo.serial_number[0] == '\0' 142829200a0SAlexander von Gluck IV && fBatteryExtendedInfo.type[0] == '\0' 143829200a0SAlexander von Gluck IV && fBatteryExtendedInfo.oem_info[0] == '\0') 1443bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Empty battery slot"); 145a11e2f43SAxel Dörfler else if ((fBatteryInfo.state & BATTERY_CRITICAL_STATE) != 0) 146042aefc4SAlexander von Gluck IV fontString->string = B_TRANSLATE("Damaged battery"); 1476aed176cSClemens Zeidler else 1483bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Battery unused"); 1496aed176cSClemens Zeidler 150e391ec67SClemens Zeidler fontString = new FontString; 1513bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Capacity: "); 152e391ec67SClemens Zeidler fontString->string << fBatteryInfo.capacity; 153e391ec67SClemens Zeidler fontString->string << powerUnit; 154e391ec67SClemens Zeidler _AddToStringList(fontString); 1556aed176cSClemens Zeidler 156e391ec67SClemens Zeidler fontString = new FontString; 1573bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Last full charge: "); 158e391ec67SClemens Zeidler fontString->string << fBatteryInfo.full_capacity; 159e391ec67SClemens Zeidler fontString->string << powerUnit; 160e391ec67SClemens Zeidler _AddToStringList(fontString); 1616aed176cSClemens Zeidler 162e391ec67SClemens Zeidler fontString = new FontString; 1633bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Current rate: "); 164e391ec67SClemens Zeidler fontString->string << fBatteryInfo.current_rate; 165e391ec67SClemens Zeidler fontString->string << rateUnit; 166e391ec67SClemens Zeidler _AddToStringList(fontString); 1676aed176cSClemens Zeidler 168e391ec67SClemens Zeidler // empty line 169e391ec67SClemens Zeidler fontString = new FontString; 170e391ec67SClemens Zeidler _AddToStringList(fontString); 1716aed176cSClemens Zeidler 172e391ec67SClemens Zeidler fontString = new FontString; 1733bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Design capacity: "); 174e391ec67SClemens Zeidler fontString->string << fBatteryExtendedInfo.design_capacity; 175e391ec67SClemens Zeidler fontString->string << powerUnit; 176e391ec67SClemens Zeidler _AddToStringList(fontString); 1776aed176cSClemens Zeidler 178e391ec67SClemens Zeidler fontString = new FontString; 1793bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Technology: "); 180b636a0ecSClemens Zeidler if (fBatteryExtendedInfo.technology == 0) 1813bd54e05SAdrien Destugues fontString->string << B_TRANSLATE("non-rechargeable"); 182b636a0ecSClemens Zeidler else if (fBatteryExtendedInfo.technology == 1) 1833bd54e05SAdrien Destugues fontString->string << B_TRANSLATE("rechargeable"); 184b636a0ecSClemens Zeidler else 185b636a0ecSClemens Zeidler fontString->string << "?"; 186e391ec67SClemens Zeidler _AddToStringList(fontString); 1876aed176cSClemens Zeidler 188e391ec67SClemens Zeidler fontString = new FontString; 1893bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Design voltage: "); 190e391ec67SClemens Zeidler fontString->string << fBatteryExtendedInfo.design_voltage; 1913bd54e05SAdrien Destugues fontString->string << B_TRANSLATE(" mV"); 192e391ec67SClemens Zeidler _AddToStringList(fontString); 1936aed176cSClemens Zeidler 194e391ec67SClemens Zeidler fontString = new FontString; 1953bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Design capacity warning: "); 196e391ec67SClemens Zeidler fontString->string << fBatteryExtendedInfo.design_capacity_warning; 197e391ec67SClemens Zeidler fontString->string << powerUnit; 198e391ec67SClemens Zeidler _AddToStringList(fontString); 1996aed176cSClemens Zeidler 200e391ec67SClemens Zeidler fontString = new FontString; 2013bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Design capacity low warning: "); 202e391ec67SClemens Zeidler fontString->string << fBatteryExtendedInfo.design_capacity_low; 203e391ec67SClemens Zeidler fontString->string << powerUnit; 204e391ec67SClemens Zeidler _AddToStringList(fontString); 2056aed176cSClemens Zeidler 206e391ec67SClemens Zeidler fontString = new FontString; 2073bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Capacity granularity 1: "); 208e391ec67SClemens Zeidler fontString->string << fBatteryExtendedInfo.capacity_granularity_1; 209b636a0ecSClemens Zeidler fontString->string << powerUnit; 210e391ec67SClemens Zeidler _AddToStringList(fontString); 2116aed176cSClemens Zeidler 212e391ec67SClemens Zeidler fontString = new FontString; 2133bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Capacity granularity 2: "); 214e391ec67SClemens Zeidler fontString->string << fBatteryExtendedInfo.capacity_granularity_2; 215b636a0ecSClemens Zeidler fontString->string << powerUnit; 216e391ec67SClemens Zeidler _AddToStringList(fontString); 2176aed176cSClemens Zeidler 218e391ec67SClemens Zeidler fontString = new FontString; 2193bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Model number: "); 220e391ec67SClemens Zeidler fontString->string << fBatteryExtendedInfo.model_number; 221e391ec67SClemens Zeidler _AddToStringList(fontString); 2226aed176cSClemens Zeidler 223e391ec67SClemens Zeidler fontString = new FontString; 2243bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Serial number: "); 225e391ec67SClemens Zeidler fontString->string << fBatteryExtendedInfo.serial_number; 226e391ec67SClemens Zeidler _AddToStringList(fontString); 2276aed176cSClemens Zeidler 228e391ec67SClemens Zeidler fontString = new FontString; 2293bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("Type: "); 230e391ec67SClemens Zeidler fontString->string += fBatteryExtendedInfo.type; 231e391ec67SClemens Zeidler _AddToStringList(fontString); 2326aed176cSClemens Zeidler 233e391ec67SClemens Zeidler fontString = new FontString; 2343bd54e05SAdrien Destugues fontString->string = B_TRANSLATE("OEM info: "); 235e391ec67SClemens Zeidler fontString->string += fBatteryExtendedInfo.oem_info; 236e391ec67SClemens Zeidler _AddToStringList(fontString); 2376aed176cSClemens Zeidler 238e391ec67SClemens Zeidler fPreferredSize.width = fMaxStringSize.width + 10; 239e391ec67SClemens Zeidler fPreferredSize.height = (fMaxStringSize.height + kLineSpacing) * 240e391ec67SClemens Zeidler fStringList.CountItems(); 241e391ec67SClemens Zeidler } 242e391ec67SClemens Zeidler 243e391ec67SClemens Zeidler 244e391ec67SClemens Zeidler void 245e391ec67SClemens Zeidler BatteryInfoView::_AddToStringList(FontString* fontString) 246e391ec67SClemens Zeidler { 247e391ec67SClemens Zeidler fStringList.AddItem(fontString); 248e391ec67SClemens Zeidler BSize stringSize = _MeasureString(fontString->string); 249e391ec67SClemens Zeidler if (fMaxStringSize.width < stringSize.width) 250e391ec67SClemens Zeidler fMaxStringSize = stringSize; 251e391ec67SClemens Zeidler } 252e391ec67SClemens Zeidler 253e391ec67SClemens Zeidler 254e391ec67SClemens Zeidler void 255e391ec67SClemens Zeidler BatteryInfoView::_ClearStringList() 256e391ec67SClemens Zeidler { 257e391ec67SClemens Zeidler for (int i = 0; i < fStringList.CountItems(); i ++) 258e391ec67SClemens Zeidler delete fStringList.ItemAt(i); 259e391ec67SClemens Zeidler fStringList.MakeEmpty(); 260e391ec67SClemens Zeidler fMaxStringSize = BSize(0, 0); 2616aed176cSClemens Zeidler } 2626aed176cSClemens Zeidler 2636aed176cSClemens Zeidler 264bd767f5aSAxel Dörfler // #pragma mark - 265bd767f5aSAxel Dörfler 266bd767f5aSAxel Dörfler 2676aed176cSClemens Zeidler ExtPowerStatusView::ExtPowerStatusView(PowerStatusDriverInterface* interface, 268bd767f5aSAxel Dörfler BRect frame, int32 resizingMode, int batteryID, 2696aed176cSClemens Zeidler ExtendedInfoWindow* window) 2706aed176cSClemens Zeidler : 271bd767f5aSAxel Dörfler PowerStatusView(interface, frame, resizingMode, batteryID), 2726aed176cSClemens Zeidler fExtendedInfoWindow(window), 2736aed176cSClemens Zeidler fBatteryInfoView(window->GetExtendedBatteryInfoView()), 2746aed176cSClemens Zeidler fSelected(false) 2756aed176cSClemens Zeidler { 2766aed176cSClemens Zeidler } 2776aed176cSClemens Zeidler 2786aed176cSClemens Zeidler 2796aed176cSClemens Zeidler void 2806aed176cSClemens Zeidler ExtPowerStatusView::Draw(BRect updateRect) 2816aed176cSClemens Zeidler { 282bd767f5aSAxel Dörfler if (fSelected) 2836aed176cSClemens Zeidler SetLowColor(102, 152, 203); 284bd767f5aSAxel Dörfler else 2856aed176cSClemens Zeidler SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 2866aed176cSClemens Zeidler 2876aed176cSClemens Zeidler PowerStatusView::Draw(updateRect); 2886aed176cSClemens Zeidler } 2896aed176cSClemens Zeidler 2906aed176cSClemens Zeidler 2916aed176cSClemens Zeidler void 2926aed176cSClemens Zeidler ExtPowerStatusView::MouseDown(BPoint where) 2936aed176cSClemens Zeidler { 2946aed176cSClemens Zeidler if (!fSelected) { 2956aed176cSClemens Zeidler fSelected = true; 296bd767f5aSAxel Dörfler Update(true); 297bd767f5aSAxel Dörfler if (ExtendedInfoWindow* window 298bd767f5aSAxel Dörfler = dynamic_cast<ExtendedInfoWindow*>(Window())) 299bd767f5aSAxel Dörfler window->BatterySelected(this); 3006aed176cSClemens Zeidler } 3016aed176cSClemens Zeidler } 3026aed176cSClemens Zeidler 3036aed176cSClemens Zeidler 3046aed176cSClemens Zeidler void 3056aed176cSClemens Zeidler ExtPowerStatusView::Select(bool select) 3066aed176cSClemens Zeidler { 3076aed176cSClemens Zeidler fSelected = select; 308bd767f5aSAxel Dörfler Update(true); 3096aed176cSClemens Zeidler } 3106aed176cSClemens Zeidler 3116aed176cSClemens Zeidler 3126aed176cSClemens Zeidler bool 313bd767f5aSAxel Dörfler ExtPowerStatusView::IsCritical() 3146aed176cSClemens Zeidler { 315bd767f5aSAxel Dörfler return (fBatteryInfo.state & BATTERY_CRITICAL_STATE) != 0; 3166aed176cSClemens Zeidler } 3176aed176cSClemens Zeidler 3186aed176cSClemens Zeidler 3196aed176cSClemens Zeidler void 320bd767f5aSAxel Dörfler ExtPowerStatusView::Update(bool force) 3216aed176cSClemens Zeidler { 322bd767f5aSAxel Dörfler PowerStatusView::Update(force); 3236aed176cSClemens Zeidler if (!fSelected) 3246aed176cSClemens Zeidler return; 3256aed176cSClemens Zeidler 3266aed176cSClemens Zeidler acpi_extended_battery_info extInfo; 327bd767f5aSAxel Dörfler fDriverInterface->GetExtendedBatteryInfo(&extInfo, fBatteryID); 3286aed176cSClemens Zeidler 3296aed176cSClemens Zeidler fBatteryInfoView->Update(fBatteryInfo, extInfo); 3306aed176cSClemens Zeidler fBatteryInfoView->Invalidate(); 3316aed176cSClemens Zeidler } 3326aed176cSClemens Zeidler 3336aed176cSClemens Zeidler 334bd767f5aSAxel Dörfler // #pragma mark - 335bd767f5aSAxel Dörfler 336bd767f5aSAxel Dörfler 3376aed176cSClemens Zeidler ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface) 3386aed176cSClemens Zeidler : 3393bd54e05SAdrien Destugues BWindow(BRect(100, 150, 500, 500), B_TRANSLATE("Extended battery info"), 3403bd54e05SAdrien Destugues B_TITLED_WINDOW, 341e391ec67SClemens Zeidler B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AVOID_FRONT | 342e391ec67SClemens Zeidler B_ASYNCHRONOUS_CONTROLS), 3436aed176cSClemens Zeidler fDriverInterface(interface), 3446aed176cSClemens Zeidler fSelectedView(NULL) 3456aed176cSClemens Zeidler { 34608145692SClemens Zeidler fDriverInterface->AcquireReference(); 34708145692SClemens Zeidler 3486aed176cSClemens Zeidler BView *view = new BView(Bounds(), "view", B_FOLLOW_ALL, 0); 3496aed176cSClemens Zeidler view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 3506aed176cSClemens Zeidler AddChild(view); 3516aed176cSClemens Zeidler 3526aed176cSClemens Zeidler BGroupLayout* mainLayout = new BGroupLayout(B_VERTICAL); 3536aed176cSClemens Zeidler mainLayout->SetSpacing(10); 3546aed176cSClemens Zeidler mainLayout->SetInsets(10, 10, 10, 10); 3556aed176cSClemens Zeidler view->SetLayout(mainLayout); 3566aed176cSClemens Zeidler 3576aed176cSClemens Zeidler BRect rect = Bounds(); 3586aed176cSClemens Zeidler rect.InsetBy(5, 5); 3593bd54e05SAdrien Destugues BBox *infoBox = new BBox(rect, B_TRANSLATE("Power status box")); 3603bd54e05SAdrien Destugues infoBox->SetLabel(B_TRANSLATE("Battery info")); 3616aed176cSClemens Zeidler BGroupLayout* infoLayout = new BGroupLayout(B_HORIZONTAL); 3626aed176cSClemens Zeidler infoLayout->SetInsets(10, infoBox->TopBorderOffset() * 2 + 10, 10, 10); 3636aed176cSClemens Zeidler infoLayout->SetSpacing(10); 3646aed176cSClemens Zeidler infoBox->SetLayout(infoLayout); 3656aed176cSClemens Zeidler mainLayout->AddView(infoBox); 3666aed176cSClemens Zeidler 3676aed176cSClemens Zeidler BGroupView* batteryView = new BGroupView(B_VERTICAL); 3686aed176cSClemens Zeidler batteryView->GroupLayout()->SetSpacing(10); 3696aed176cSClemens Zeidler infoLayout->AddView(batteryView); 3706aed176cSClemens Zeidler 371e391ec67SClemens Zeidler // create before the battery views 372e391ec67SClemens Zeidler fBatteryInfoView = new BatteryInfoView(); 3736aed176cSClemens Zeidler 3746aed176cSClemens Zeidler BGroupLayout* batteryLayout = batteryView->GroupLayout(); 3756aed176cSClemens Zeidler BRect batteryRect(0, 0, 50, 30); 3766aed176cSClemens Zeidler for (int i = 0; i < interface->GetBatteryCount(); i++) { 3776aed176cSClemens Zeidler ExtPowerStatusView* view = new ExtPowerStatusView(interface, 378e391ec67SClemens Zeidler batteryRect, B_FOLLOW_NONE, i, this); 379e391ec67SClemens Zeidler view->SetExplicitMaxSize(BSize(70, 80)); 380e391ec67SClemens Zeidler view->SetExplicitMinSize(BSize(70, 80)); 381e391ec67SClemens Zeidler 3826aed176cSClemens Zeidler batteryLayout->AddView(view); 3836aed176cSClemens Zeidler fBatteryViewList.AddItem(view); 3846aed176cSClemens Zeidler fDriverInterface->StartWatching(view); 385bd767f5aSAxel Dörfler if (!view->IsCritical()) 3866aed176cSClemens Zeidler fSelectedView = view; 3876aed176cSClemens Zeidler } 3886aed176cSClemens Zeidler 3896aed176cSClemens Zeidler batteryLayout->AddItem(BSpaceLayoutItem::CreateGlue()); 3906aed176cSClemens Zeidler 391e391ec67SClemens Zeidler infoLayout->AddView(fBatteryInfoView); 3926aed176cSClemens Zeidler 3936aed176cSClemens Zeidler if (!fSelectedView && fBatteryViewList.CountItems() > 0) 3946aed176cSClemens Zeidler fSelectedView = fBatteryViewList.ItemAt(0); 3956aed176cSClemens Zeidler fSelectedView->Select(); 3966aed176cSClemens Zeidler 3976aed176cSClemens Zeidler BSize size = mainLayout->PreferredSize(); 3986aed176cSClemens Zeidler ResizeTo(size.width, size.height); 3996aed176cSClemens Zeidler } 4006aed176cSClemens Zeidler 4016aed176cSClemens Zeidler 4026aed176cSClemens Zeidler ExtendedInfoWindow::~ExtendedInfoWindow() 4036aed176cSClemens Zeidler { 40408145692SClemens Zeidler for (int i = 0; i < fBatteryViewList.CountItems(); i++) 4056aed176cSClemens Zeidler fDriverInterface->StopWatching(fBatteryViewList.ItemAt(i)); 40608145692SClemens Zeidler 40708145692SClemens Zeidler fDriverInterface->ReleaseReference(); 4086aed176cSClemens Zeidler } 4096aed176cSClemens Zeidler 4106aed176cSClemens Zeidler 4116aed176cSClemens Zeidler BatteryInfoView* 4126aed176cSClemens Zeidler ExtendedInfoWindow::GetExtendedBatteryInfoView() 4136aed176cSClemens Zeidler { 4146aed176cSClemens Zeidler return fBatteryInfoView; 4156aed176cSClemens Zeidler } 4166aed176cSClemens Zeidler 4176aed176cSClemens Zeidler 4186aed176cSClemens Zeidler void 4196aed176cSClemens Zeidler ExtendedInfoWindow::BatterySelected(ExtPowerStatusView* view) 4206aed176cSClemens Zeidler { 4216aed176cSClemens Zeidler if (fSelectedView) { 4226aed176cSClemens Zeidler fSelectedView->Select(false); 4236aed176cSClemens Zeidler fSelectedView->Invalidate(); 4246aed176cSClemens Zeidler } 4256aed176cSClemens Zeidler 4266aed176cSClemens Zeidler fSelectedView = view; 4276aed176cSClemens Zeidler } 428