From 524288065b175be47ff8b3b9268459ac9d73edb9 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Wed, 10 Dec 2014 13:27:53 +0100 Subject: [PATCH] Test for #3970. * This shows the problem in Haiku, it is not easily possible to change the color of BStringItem. * It also shows that the BeOS implementation doesn't restore the view state after drawing items, so the last item in the list also draws green, and selecting the first also makes it green. --- src/tests/kits/interface/Jamfile | 5 + src/tests/kits/interface/ListViewTest.cpp | 114 ++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 src/tests/kits/interface/ListViewTest.cpp diff --git a/src/tests/kits/interface/Jamfile b/src/tests/kits/interface/Jamfile index f053deef39..6ba39ae22b 100644 --- a/src/tests/kits/interface/Jamfile +++ b/src/tests/kits/interface/Jamfile @@ -91,6 +91,11 @@ SimpleTest CheckBoxTest : : be [ TargetLibsupc++ ] ; +SimpleTest ListViewTest : + ListViewTest.cpp + : be [ TargetLibsupc++ ] + ; + SimpleTest ScreenTest : ScreenTest.cpp : be diff --git a/src/tests/kits/interface/ListViewTest.cpp b/src/tests/kits/interface/ListViewTest.cpp new file mode 100644 index 0000000000..6c82ef26f8 --- /dev/null +++ b/src/tests/kits/interface/ListViewTest.cpp @@ -0,0 +1,114 @@ +/* + * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2014 Haiku, Inc. + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include +#include + +#include + + +class ColorfulItem: public BStringItem +{ + public: + ColorfulItem(const char* label, rgb_color color); + virtual void DrawItem(BView* owner, BRect frame, + bool complete = false); + + private: + rgb_color fColor; +}; + + +ColorfulItem::ColorfulItem(const char* label, rgb_color color) + : + BStringItem(label), + fColor(color) +{ +} + + +void +ColorfulItem::DrawItem(BView* owner, BRect frame, bool complete) +{ + owner->SetHighColor(fColor); + BStringItem::DrawItem(owner, frame, complete); +} + + +// #pragma mark - + + +class Window : public BWindow { + public: + Window(); + + virtual bool QuitRequested(); +}; + + +Window::Window() + : BWindow(BRect(100, 100, 520, 430), "ListView-Test", + B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) +{ + BRect rect(20, 10, 200, 300); + BListView *listView = new BListView(rect, "list"); + + listView->AddItem(new BStringItem("normal item")); + listView->AddItem(new ColorfulItem("green item", make_color(0, 255, 0))); + listView->AddItem(new BStringItem("normal item")); + + AddChild(listView); +} + + +bool +Window::QuitRequested() +{ + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} + + +// #pragma mark - + + +class Application : public BApplication { + public: + Application(); + + virtual void ReadyToRun(void); +}; + + +Application::Application() + : BApplication("application/x-vnd.obos-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; +} +