hrev48478 adds 2 changesets to branch 'master' old head: 04f884284c433bedf44c6279c8fa82fb620c6822 new head: cbb8ebbbbb21f6a29ccd3830e32cb808e62a92bc overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=cbb8ebb+%5E04f8842 ---------------------------------------------------------------------------- 5242880: 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. cbb8ebb: Set item colors in BListView instead of BStringItem * Fixes #3970 without introducing the bugs from BeOS * Makes it easy to override BStringItem just to change the text color. * Makes it easy to implement custom list items using the correct colors. [ Adrien Destugues <pulkomandy@xxxxxxxxx> ] ---------------------------------------------------------------------------- 4 files changed, 136 insertions(+), 18 deletions(-) src/kits/interface/ListView.cpp | 17 +++- src/kits/interface/StringItem.cpp | 18 +--- src/tests/kits/interface/Jamfile | 5 ++ src/tests/kits/interface/ListViewTest.cpp | 114 ++++++++++++++++++++++++++ ############################################################################ Commit: 524288065b175be47ff8b3b9268459ac9d73edb9 URL: http://cgit.haiku-os.org/haiku/commit/?id=5242880 Author: Adrien Destugues <pulkomandy@xxxxxxxxx> Date: Wed Dec 10 12:27:53 2014 UTC Ticket: https://dev.haiku-os.org/ticket/3970 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. ---------------------------------------------------------------------------- diff --git a/src/tests/kits/interface/Jamfile b/src/tests/kits/interface/Jamfile index f053dee..6ba39ae 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 0000000..6c82ef2 --- /dev/null +++ b/src/tests/kits/interface/ListViewTest.cpp @@ -0,0 +1,114 @@ +/* + * Copyright 2005, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx. 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; +} + ############################################################################ Revision: hrev48478 Commit: cbb8ebbbbb21f6a29ccd3830e32cb808e62a92bc URL: http://cgit.haiku-os.org/haiku/commit/?id=cbb8ebb Author: Adrien Destugues <pulkomandy@xxxxxxxxx> Date: Wed Dec 10 12:31:23 2014 UTC Ticket: https://dev.haiku-os.org/ticket/3970 Set item colors in BListView instead of BStringItem * Fixes #3970 without introducing the bugs from BeOS * Makes it easy to override BStringItem just to change the text color. * Makes it easy to implement custom list items using the correct colors. ---------------------------------------------------------------------------- diff --git a/src/kits/interface/ListView.cpp b/src/kits/interface/ListView.cpp index c2bdbd2..4b4aa71 100644 --- a/src/kits/interface/ListView.cpp +++ b/src/kits/interface/ListView.cpp @@ -207,8 +207,23 @@ BListView::Draw(BRect updateRect) BListItem* item = ItemAt(i); itemFrame.bottom = itemFrame.top + ceilf(item->Height()) - 1; - if (itemFrame.Intersects(updateRect)) + rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR); + rgb_color disabledColor; + if (textColor.red + textColor.green + textColor.blue > 128 * 3) + disabledColor = tint_color(textColor, B_DARKEN_2_TINT); + else + disabledColor = tint_color(textColor, B_LIGHTEN_2_TINT); + + if (itemFrame.Intersects(updateRect)) { + if (!item->IsEnabled()) + SetHighColor(disabledColor); + else if (item->IsSelected()) + SetHighColor(ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR)); + else + SetHighColor(ui_color(B_LIST_ITEM_TEXT_COLOR)); + DrawItem(item, itemFrame); + } itemFrame.top = itemFrame.bottom + 1; } diff --git a/src/kits/interface/StringItem.cpp b/src/kits/interface/StringItem.cpp index d692185..9d4c14b 100644 --- a/src/kits/interface/StringItem.cpp +++ b/src/kits/interface/StringItem.cpp @@ -75,7 +75,6 @@ BStringItem::DrawItem(BView* owner, BRect frame, bool complete) if (fText == NULL) return; - rgb_color highColor = owner->HighColor(); rgb_color lowColor = owner->LowColor(); if (IsSelected() || complete) { @@ -86,30 +85,15 @@ BStringItem::DrawItem(BView* owner, BRect frame, bool complete) color = owner->ViewColor(); owner->SetLowColor(color); - owner->SetHighColor(color); - owner->FillRect(frame); + owner->FillRect(frame, B_SOLID_LOW); } else owner->SetLowColor(owner->ViewColor()); owner->MovePenTo(frame.left + be_control_look->DefaultLabelSpacing(), frame.top + fBaselineOffset); - if (!IsEnabled()) { - rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR); - if (textColor.red + textColor.green + textColor.blue > 128 * 3) - owner->SetHighColor(tint_color(textColor, B_DARKEN_2_TINT)); - else - owner->SetHighColor(tint_color(textColor, B_LIGHTEN_2_TINT)); - } else { - if (IsSelected()) - owner->SetHighColor(ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR)); - else - owner->SetHighColor(ui_color(B_LIST_ITEM_TEXT_COLOR)); - } - owner->DrawString(fText); - owner->SetHighColor(highColor); owner->SetLowColor(lowColor); }