void Window::MessageReceived(BMessage* message) { switch (message->what) { case kMsgUpdate: { char buffer[100]; snprintf(buffer, sizeof(buffer), "%ld ", (int32)fStatusBar->CurrentValue()); fStatusBar->Update(1, fStatusBar->CurrentValue() > 25 ? " updated!" : NULL, buffer); if (fStatusBar->CurrentValue() >= fStatusBar->MaxValue()) { #if 1 fStatusBar->Reset("-", "????"); #else fStatusBar->Reset(); fStatusBar->SetText("-"); fStatusBar->SetTrailingText("????"); #endif fStatusBar->SetMaxValue(50.0); } } default: BWindow::MessageReceived(message); } }
void NSDownloadWindow::Failure(const char* error) { bar->LockLooper(); bar->Update(0, NULL, error); bar->SetBarColor(ui_color(B_FAILURE_COLOR)); bar->UnlockLooper(); }
void NSDownloadWindow::Progress(int size) { progress += size; char* buffer = human_friendly_bytesize(progress); strcat(buffer, "/"); bar->LockLooper(); bar->Update(size, NULL, buffer); bar->Invalidate(); bar->UnlockLooper(); }
NotificationView::NotificationView(NotificationWindow* win, BNotification* notification, bigtime_t timeout) : BView("NotificationView", B_WILL_DRAW), fParent(win), fNotification(notification), fTimeout(timeout), fRunner(NULL), fBitmap(NULL), fCloseClicked(false) { if (fNotification->Icon() != NULL) fBitmap = new BBitmap(fNotification->Icon()); if (fTimeout <= 0) fTimeout = fParent->Timeout() * 1000000; BGroupLayout* layout = new BGroupLayout(B_VERTICAL); SetLayout(layout); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); switch (fNotification->Type()) { case B_IMPORTANT_NOTIFICATION: fStripeColor = ui_color(B_CONTROL_HIGHLIGHT_COLOR); break; case B_ERROR_NOTIFICATION: fStripeColor = ui_color(B_FAILURE_COLOR); break; case B_PROGRESS_NOTIFICATION: { BStatusBar* progress = new BStatusBar("progress"); progress->SetBarHeight(12.0f); progress->SetMaxValue(1.0f); progress->Update(fNotification->Progress()); BString label = ""; label << (int)(fNotification->Progress() * 100) << " %"; progress->SetTrailingText(label); layout->AddView(progress); } // fall through. case B_INFORMATION_NOTIFICATION: fStripeColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT); break; } }
static int haikuProgressBarSetValueAttrib(Ihandle* ih, const char* value) { if (ih->data->marquee) return 0; if (!value) ih->data->value = 0; else ih->data->value = atof(value); iProgressBarCropValue(ih); BStatusBar* bar = (BStatusBar*)ih->handle; float val = bar->CurrentValue(); bar->Update(ih->data->value - val); return 1; }
void ProgressWindow::MessageReceived(BMessage* message) { switch (message->what) { case B_UPDATE_STATUS_BAR: char count[100]; snprintf(count, sizeof(count), "%" B_PRId32, (int32)fStatusBar->CurrentValue() + 1); fStatusBar->Update(1, NULL, count); break; case B_CANCEL: fAbortButton->SetEnabled(false); if (fQuitListener != NULL) *fQuitListener = true; break; default: BWindow::MessageReceived(message); break; } }
ViewsWindow(BRect frame) : BWindow(frame, "ALM Views", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE) { BButton* button1 = new BButton("BButton"); BRadioButton* radioButton = new BRadioButton("BRadioButton", NULL); BButton* button3 = new BButton("3"); BButton* button4 = new BButton("4"); button4->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER)); BButton* button5 = new BButton("5"); BButton* button6 = new BButton("6"); BTextView* textView1 = new BTextView("textView1"); textView1->SetText("BTextView"); BStatusBar* statusBar = new BStatusBar("BStatusBar", "label", "trailing label"); statusBar->Update(50); BMenu* menu = new BMenu("Menu 1"); BMenuField* menu1 = new BMenuField("MenuField 1", menu); menu->AddItem(new BPopUpMenu("Menu 1")); BStringView* stringView1 = new BStringView("string 1", "string 1"); menu = new BMenu("Menu 2 + long text"); BMenuField* menu2 = new BMenuField("MenuField 2", menu); menu->AddItem(new BPopUpMenu("Menu 2")); BStringView* stringView2 = new BStringView("string 2", "string 2"); BALM::BALMLayout* layout = new BALMLayout(10, 10); BALM::BALMLayoutBuilder(this, layout) .SetInsets(10) .Add(button1, layout->Left(), layout->Top()) .StartingAt(button1) .AddToRight(radioButton) .AddToRight(BSpaceLayoutItem::CreateGlue()) .AddToRight(button3) .StartingAt(radioButton) .AddBelow(textView1, NULL, NULL, layout->RightOf(button3)) .AddBelow(button4) .AddToRight(button5, layout->Right()) .AddBelow(button6) .AddBelow(menu1, layout->AddYTab(), layout->Left(), layout->AddXTab()) .AddToRight(stringView1) .AddToRight(BSpaceLayoutItem::CreateGlue(), layout->Right()) .AddBelow(statusBar, NULL, layout->Left(), layout->Right()); // start over so that layout->RightOf() can return accurate results BALM::BALMLayoutBuilder(layout) .StartingAt(statusBar) .AddBelow(menu2, layout->Bottom(), layout->Left(), layout->RightOf(menu1)) .AddToRight(stringView2) .AddToRight(BSpaceLayoutItem::CreateGlue(), layout->Right()); layout->Solver()->AddConstraint(2, layout->TopOf(menu1), -1, layout->Bottom(), OperatorType(kEQ), 0); // test size limits BSize min = layout->MinSize(); BSize max = layout->MaxSize(); SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height()); }
status_t PProgressBar::SetProperty(const char *name, PValue *value, const int32 &index) { if (!name || !value) return B_ERROR; BString str(name); PProperty *prop = FindProperty(name,index); if (!prop) return B_NAME_NOT_FOUND; if (FlagsForProperty(prop) & PROPERTY_READ_ONLY) return B_READ_ONLY; BStatusBar *backend = (BStatusBar*)fView; BoolValue boolval; ColorValue colorval; FloatValue floatval; IntValue intval; PointValue pointval; RectValue rectval; StringValue stringval; status_t status = prop->SetValue(value); if (status != B_OK) return status; if (backend->Window()) backend->Window()->Lock(); if (str.ICompare("BarColor") == 0) { prop->GetValue(&colorval); backend->SetBarColor(*colorval.value); } else if (str.ICompare("BarHeight") == 0) { prop->GetValue(&floatval); backend->SetBarHeight(*floatval.value); } else if (str.ICompare("CurrentValue") == 0) { prop->GetValue(&floatval); float current = backend->CurrentValue(); backend->Update((*floatval.value) - current); } else if (str.ICompare("MaxValue") == 0) { prop->GetValue(&floatval); backend->SetMaxValue(*floatval.value); } else if (str.ICompare("Text") == 0) { prop->GetValue(&stringval); backend->SetText(*stringval.value); } else if (str.ICompare("TrailingText") == 0) { prop->GetValue(&stringval); backend->SetTrailingText(*stringval.value); } else { if (backend->Window()) backend->Window()->Unlock(); return PView::SetProperty(name, value, index); } if (backend->Window()) backend->Window()->Unlock(); return prop->GetValue(value); }