1 /* 2 * Copyright 2002-2008, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Jerome Duval (jerome.duval@free.fr) 7 * Axel Dörfler, axeld@pinc-software.de 8 */ 9 10 11 #include "BackgroundsView.h" 12 13 #include <Application.h> 14 #include <TrackerAddOnAppLaunch.h> 15 #include <Window.h> 16 17 18 static const char *kSignature = "application/x-vnd.Haiku-Backgrounds"; 19 20 21 class BackgroundsApplication : public BApplication { 22 public: 23 BackgroundsApplication(); 24 virtual void RefsReceived(BMessage* message); 25 }; 26 27 class BackgroundsWindow : public BWindow { 28 public: 29 BackgroundsWindow(BRect frame, bool standalone = true); 30 31 protected: 32 virtual bool QuitRequested(); 33 virtual void WorkspaceActivated(int32 oldWorkspaces, bool active); 34 35 BackgroundsView *fBackgroundsView; 36 bool fIsStandalone; 37 }; 38 39 40 // #pragma mark - 41 42 43 BackgroundsApplication::BackgroundsApplication() 44 : BApplication(kSignature) 45 { 46 BWindow* window = new BackgroundsWindow(BRect(100, 100, 570, 325)); 47 window->Show(); 48 } 49 50 51 void 52 BackgroundsApplication::RefsReceived(BMessage* message) 53 { 54 if (CountWindows() > 0) { 55 BWindow* window = WindowAt(0); 56 BMessenger(window->ChildAt(0)).SendMessage(message); 57 } 58 59 } 60 61 // #pragma mark - 62 63 64 BackgroundsWindow::BackgroundsWindow(BRect frame, bool standalone) 65 : BWindow(frame, "Backgrounds", B_TITLED_WINDOW, 66 B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_ALL_WORKSPACES), 67 fIsStandalone(standalone) 68 { 69 fBackgroundsView = new BackgroundsView(Bounds(), "BackgroundsView", 70 B_FOLLOW_ALL, B_WILL_DRAW); 71 AddChild(fBackgroundsView); 72 } 73 74 75 bool 76 BackgroundsWindow::QuitRequested() 77 { 78 fBackgroundsView->SaveSettings(); 79 if (fIsStandalone) 80 be_app->PostMessage(B_QUIT_REQUESTED); 81 82 return true; 83 } 84 85 86 void 87 BackgroundsWindow::WorkspaceActivated(int32 oldWorkspaces, bool active) 88 { 89 fBackgroundsView->WorkspaceActivated(oldWorkspaces, active); 90 } 91 92 93 // #pragma mark - 94 95 96 int 97 main(int argc, char** argv) 98 { 99 BApplication* app = new BackgroundsApplication; 100 101 // This function doesn't return until the application quits 102 app->Run(); 103 delete app; 104 105 return 0; 106 } 107 108