* 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.
This commit is contained in:
Adrien Destugues 2014-12-10 13:27:53 +01:00
parent 04f884284c
commit 524288065b
2 changed files with 119 additions and 0 deletions

View File

@ -91,6 +91,11 @@ SimpleTest CheckBoxTest :
: be [ TargetLibsupc++ ]
;
SimpleTest ListViewTest :
ListViewTest.cpp
: be [ TargetLibsupc++ ]
;
SimpleTest ScreenTest :
ScreenTest.cpp
: be

View File

@ -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 <Application.h>
#include <ListView.h>
#include <StringItem.h>
#include <Window.h>
#include <stdio.h>
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;
}