1 /* 2 * Copyright 2002-2009, 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 <Application.h> 12 #include <Catalog.h> 13 #include <LayoutBuilder.h> 14 #include <Locale.h> 15 #include <TrackerAddOnAppLaunch.h> 16 #include <Window.h> 17 18 #include "BackgroundsView.h" 19 20 21 #undef B_TRANSLATE_CONTEXT 22 #define B_TRANSLATE_CONTEXT "Main Window" 23 24 25 static const char* kSignature = "application/x-vnd.Haiku-Backgrounds"; 26 27 28 class BackgroundsWindow : public BWindow { 29 public: 30 BackgroundsWindow(); 31 32 void RefsReceived(BMessage* message); 33 34 protected: 35 virtual bool QuitRequested(); 36 virtual void WorkspaceActivated(int32 oldWorkspaces, 37 bool active); 38 39 BackgroundsView* fBackgroundsView; 40 }; 41 42 43 class BackgroundsApplication : public BApplication { 44 public: 45 BackgroundsApplication(); 46 virtual void MessageReceived(BMessage* message); 47 virtual void RefsReceived(BMessage* message); 48 49 private: 50 BackgroundsWindow* fWindow; 51 }; 52 53 54 // #pragma mark - 55 56 57 BackgroundsApplication::BackgroundsApplication() 58 : 59 BApplication(kSignature), 60 fWindow(NULL) 61 { 62 fWindow = new BackgroundsWindow(); 63 fWindow->Show(); 64 } 65 66 67 void 68 BackgroundsApplication::MessageReceived(BMessage* message) 69 { 70 switch (message->what) { 71 case B_SILENT_RELAUNCH: 72 fWindow->Activate(); 73 break; 74 default: 75 BApplication::MessageReceived(message); 76 break; 77 } 78 } 79 80 81 void 82 BackgroundsApplication::RefsReceived(BMessage* message) 83 { 84 fWindow->RefsReceived(message); 85 } 86 87 88 // #pragma mark - 89 90 91 BackgroundsWindow::BackgroundsWindow() 92 : 93 BWindow(BRect(0, 0, 0, 0), B_TRANSLATE("Backgrounds"), B_TITLED_WINDOW, 94 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS, 95 B_ALL_WORKSPACES) 96 { 97 fBackgroundsView = new BackgroundsView(); 98 99 BLayoutBuilder::Group<>(this) 100 .AddGroup(B_HORIZONTAL, 0) 101 .Add(fBackgroundsView) 102 .End() 103 .End(); 104 105 if (!fBackgroundsView->FoundPositionSetting()) 106 CenterOnScreen(); 107 } 108 109 110 void 111 BackgroundsWindow::RefsReceived(BMessage* message) 112 { 113 fBackgroundsView->RefsReceived(message); 114 Activate(); 115 } 116 117 118 bool 119 BackgroundsWindow::QuitRequested() 120 { 121 fBackgroundsView->SaveSettings(); 122 be_app->PostMessage(B_QUIT_REQUESTED); 123 124 return true; 125 } 126 127 128 void 129 BackgroundsWindow::WorkspaceActivated(int32 oldWorkspaces, bool active) 130 { 131 fBackgroundsView->WorkspaceActivated(oldWorkspaces, active); 132 } 133 134 135 // #pragma mark - 136 137 138 int 139 main(int argc, char** argv) 140 { 141 BackgroundsApplication app; 142 app.Run(); 143 return 0; 144 } 145 146