From 8feaf19bda3dfcbd7e368f078080d16e940790f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 16 Jun 2006 09:49:23 +0000 Subject: [PATCH] Added a short test app for the BStatusBar class. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17856 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/kits/interface/Jamfile | 5 + src/tests/kits/interface/StatusBarTest.cpp | 126 +++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 src/tests/kits/interface/StatusBarTest.cpp diff --git a/src/tests/kits/interface/Jamfile b/src/tests/kits/interface/Jamfile index fcffff2036..f9b5814cbb 100644 --- a/src/tests/kits/interface/Jamfile +++ b/src/tests/kits/interface/Jamfile @@ -90,6 +90,11 @@ SimpleTest ScreenTest : : be ; +SimpleTest StatusBarTest : + StatusBarTest.cpp + : be + ; + SimpleTest GetMouseTest : GetMouseTest.cpp : be diff --git a/src/tests/kits/interface/StatusBarTest.cpp b/src/tests/kits/interface/StatusBarTest.cpp new file mode 100644 index 0000000000..001c27ddda --- /dev/null +++ b/src/tests/kits/interface/StatusBarTest.cpp @@ -0,0 +1,126 @@ +/* + * Copyright 2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include +#include + +#include + + +const uint32 kMsgUpdate = 'updt'; + +class Window : public BWindow { + public: + Window(); + + virtual void MessageReceived(BMessage* message); + virtual bool QuitRequested(); + + private: + BMessageRunner* fUpdater; + BStatusBar* fStatusBar; +}; + + +Window::Window() + : BWindow(BRect(100, 100, 520, 200), "StatusBar-Test", + B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) +{ + BView* main = new BView(Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW); + main->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(main); + + BRect rect(20, 10, 400, 30); + fStatusBar = new BStatusBar(rect, NULL, "label", "trailing label"); + fStatusBar->SetResizingMode(B_FOLLOW_LEFT_RIGHT); + //fStatusBar->ResizeToPreferred(); + float width, height; + fStatusBar->GetPreferredSize(&width, &height); + fStatusBar->ResizeTo(rect.Width(), height); + fStatusBar->SetMaxValue(50.0f); + main->AddChild(fStatusBar); + + BMessage update(kMsgUpdate); + fUpdater = new BMessageRunner(this, &update, 10000LL); +} + + +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); + } +} + + +bool +Window::QuitRequested() +{ + be_app->PostMessage(B_QUIT_REQUESTED); + delete fUpdater; + return true; +} + + +// #pragma mark - + + +class Application : public BApplication { + public: + Application(); + + virtual void ReadyToRun(void); +}; + + +Application::Application() + : BApplication("application/x-vnd.haiku-test") +{ +} + + +void +Application::ReadyToRun(void) +{ + BWindow *window = new Window(); + window->Show(); +} + + +// #pragma mark - + + +int +main(int argc, char **argv) +{ + Application app; + + app.Run(); + return 0; +} +