1 /* 2 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Copyright 2014 Haiku, Inc. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 8 #include <Application.h> 9 #include <ListView.h> 10 #include <StringItem.h> 11 #include <Window.h> 12 13 #include <stdio.h> 14 15 16 class ColorfulItem: public BStringItem 17 { 18 public: 19 ColorfulItem(const char* label, rgb_color color); 20 virtual void DrawItem(BView* owner, BRect frame, 21 bool complete = false); 22 23 private: 24 rgb_color fColor; 25 }; 26 27 28 ColorfulItem::ColorfulItem(const char* label, rgb_color color) 29 : 30 BStringItem(label), 31 fColor(color) 32 { 33 } 34 35 36 void 37 ColorfulItem::DrawItem(BView* owner, BRect frame, bool complete) 38 { 39 owner->SetHighColor(fColor); 40 BStringItem::DrawItem(owner, frame, complete); 41 } 42 43 44 // #pragma mark - 45 46 47 class Window : public BWindow { 48 public: 49 Window(); 50 51 virtual bool QuitRequested(); 52 }; 53 54 55 Window::Window() 56 : BWindow(BRect(100, 100, 520, 430), "ListView-Test", 57 B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) 58 { 59 BRect rect(20, 10, 200, 300); 60 BListView *listView = new BListView(rect, "list"); 61 62 listView->AddItem(new BStringItem("normal item")); 63 listView->AddItem(new ColorfulItem("green item", make_color(0, 255, 0))); 64 listView->AddItem(new BStringItem("normal item")); 65 66 AddChild(listView); 67 } 68 69 70 bool 71 Window::QuitRequested() 72 { 73 be_app->PostMessage(B_QUIT_REQUESTED); 74 return true; 75 } 76 77 78 // #pragma mark - 79 80 81 class Application : public BApplication { 82 public: 83 Application(); 84 85 virtual void ReadyToRun(void); 86 }; 87 88 89 Application::Application() 90 : BApplication("application/x-vnd.obos-test") 91 { 92 } 93 94 95 void 96 Application::ReadyToRun(void) 97 { 98 BWindow *window = new Window(); 99 window->Show(); 100 } 101 102 103 // #pragma mark - 104 105 106 int 107 main(int argc, char **argv) 108 { 109 Application app; 110 111 app.Run(); 112 return 0; 113 } 114 115