1 /* 2 * Copyright 2002-2009 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 * Jerome Duval, jerome.duval@free.fr 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_TRANSLATION_CONTEXT 22 #define B_TRANSLATION_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 - BackgroundsApplication 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 const void *data; 71 ssize_t size; 72 73 if (message->WasDropped() && message->FindData("RGBColor", B_RGB_COLOR_TYPE, 74 &data, &size) == B_OK) { 75 // This is the desktop telling us that it was changed by a color drop 76 BMessenger(fWindow).SendMessage(message); 77 return; 78 } 79 switch (message->what) { 80 case B_SILENT_RELAUNCH: 81 fWindow->Activate(); 82 break; 83 default: 84 BApplication::MessageReceived(message); 85 break; 86 } 87 } 88 89 90 void 91 BackgroundsApplication::RefsReceived(BMessage* message) 92 { 93 fWindow->RefsReceived(message); 94 } 95 96 97 // #pragma mark - BackgroundsWindow 98 99 100 BackgroundsWindow::BackgroundsWindow() 101 : 102 BWindow(BRect(0, 0, 0, 0), B_TRANSLATE_SYSTEM_NAME("Backgrounds"), 103 B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE 104 | B_AUTO_UPDATE_SIZE_LIMITS, 105 B_ALL_WORKSPACES) 106 { 107 fBackgroundsView = new BackgroundsView(); 108 109 BLayoutBuilder::Group<>(this) 110 .AddGroup(B_HORIZONTAL, 0) 111 .Add(fBackgroundsView) 112 .End() 113 .End(); 114 115 if (!fBackgroundsView->FoundPositionSetting()) 116 CenterOnScreen(); 117 } 118 119 120 void 121 BackgroundsWindow::RefsReceived(BMessage* message) 122 { 123 fBackgroundsView->RefsReceived(message); 124 Activate(); 125 } 126 127 128 bool 129 BackgroundsWindow::QuitRequested() 130 { 131 fBackgroundsView->SaveSettings(); 132 be_app->PostMessage(B_QUIT_REQUESTED); 133 134 return true; 135 } 136 137 138 void 139 BackgroundsWindow::WorkspaceActivated(int32 oldWorkspaces, bool active) 140 { 141 fBackgroundsView->WorkspaceActivated(oldWorkspaces, active); 142 } 143 144 145 // #pragma mark - main method 146 147 148 int 149 main(int argc, char** argv) 150 { 151 BackgroundsApplication app; 152 app.Run(); 153 return 0; 154 } 155