1 /* 2 * Copyright 2008, Haiku Inc. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 9 10 #include <Application.h> 11 #include <String.h> 12 #include <Window.h> 13 #include <View.h> 14 15 #include <stdio.h> 16 17 18 class Application : public BApplication { 19 public: 20 Application(); 21 22 virtual void ReadyToRun(); 23 }; 24 25 class Window : public BWindow { 26 public: 27 Window(); 28 virtual ~Window(); 29 30 virtual void WorkspaceActivated(int32 workspace, bool active); 31 virtual bool QuitRequested(); 32 }; 33 34 class View : public BView { 35 public: 36 View(BRect rect); 37 virtual ~View(); 38 39 virtual void Draw(BRect updateRect); 40 }; 41 42 43 View::View(BRect rect) 44 : BView(rect, "workspace", B_FOLLOW_ALL, B_WILL_DRAW) 45 { 46 } 47 48 49 View::~View() 50 { 51 } 52 53 54 void 55 View::Draw(BRect updateRect) 56 { 57 BFont font; 58 font.SetSize(200); 59 60 font_height fontHeight; 61 font.GetHeight(&fontHeight); 62 63 SetFont(&font); 64 MovePenTo(20, ceilf(20 + fontHeight.ascent)); 65 66 BString current; 67 current << current_workspace(); 68 69 DrawString(current.String()); 70 } 71 72 73 // #pragma mark - 74 75 76 Window::Window() 77 : BWindow(BRect(100, 100, 400, 400), "WorkspaceActivated-Test", 78 B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) 79 { 80 BView *view = new View(BRect(10, 10, 290, 290)); 81 AddChild(view); 82 } 83 84 85 Window::~Window() 86 { 87 } 88 89 90 void 91 Window::WorkspaceActivated(int32 workspace, bool active) 92 { 93 printf("Workspace %ld (%ld), active %d\n", 94 workspace, current_workspace(), active); 95 } 96 97 98 bool 99 Window::QuitRequested() 100 { 101 be_app->PostMessage(B_QUIT_REQUESTED); 102 return true; 103 } 104 105 106 // #pragma mark - 107 108 109 Application::Application() 110 : BApplication("application/x-vnd.haiku-workspace_activated") 111 { 112 } 113 114 115 void 116 Application::ReadyToRun() 117 { 118 Window *window = new Window(); 119 window->Show(); 120 } 121 122 123 // #pragma mark - 124 125 126 int 127 main(int argc, char** argv) 128 { 129 Application app; 130 131 app.Run(); 132 return 0; 133 } 134