1cd2d1ffdSAxel Dörfler /* 2dca191e9SJonas Sundström * Copyright 2002-2009, Haiku, Inc. All Rights Reserved. 3cd2d1ffdSAxel Dörfler * Distributed under the terms of the MIT License. 4cd2d1ffdSAxel Dörfler * 5cd2d1ffdSAxel Dörfler * Authors: 6cd2d1ffdSAxel Dörfler * Jerome Duval (jerome.duval@free.fr) 7cd2d1ffdSAxel Dörfler * Axel Dörfler, axeld@pinc-software.de 8cd2d1ffdSAxel Dörfler */ 9cd2d1ffdSAxel Dörfler 10cd2d1ffdSAxel Dörfler 11cd2d1ffdSAxel Dörfler #include <Application.h> 12eb32e334SJonas Sundström #include <LayoutBuilder.h> 1391147eefSJonas Sundström #include <TrackerAddOnAppLaunch.h> 14cd2d1ffdSAxel Dörfler #include <Window.h> 15cd2d1ffdSAxel Dörfler 16dca191e9SJonas Sundström #include "BackgroundsView.h" 17dca191e9SJonas Sundström 18cd2d1ffdSAxel Dörfler 1975c92c56SRyan Leavengood static const char* kSignature = "application/x-vnd.Haiku-Backgrounds"; 20cd2d1ffdSAxel Dörfler 21cd2d1ffdSAxel Dörfler 22cd2d1ffdSAxel Dörfler class BackgroundsWindow : public BWindow { 23cd2d1ffdSAxel Dörfler public: 24eb32e334SJonas Sundström BackgroundsWindow(); 25eb32e334SJonas Sundström 26eb32e334SJonas Sundström void RefsReceived(BMessage* message); 27cd2d1ffdSAxel Dörfler 28cd2d1ffdSAxel Dörfler protected: 29cd2d1ffdSAxel Dörfler virtual bool QuitRequested(); 30*529ff59fSJonas Sundström virtual void WorkspaceActivated(int32 oldWorkspaces, 31*529ff59fSJonas Sundström bool active); 32cd2d1ffdSAxel Dörfler 33cd2d1ffdSAxel Dörfler BackgroundsView* fBackgroundsView; 34eb32e334SJonas Sundström }; 35eb32e334SJonas Sundström 36eb32e334SJonas Sundström 37eb32e334SJonas Sundström class BackgroundsApplication : public BApplication { 38eb32e334SJonas Sundström public: 39eb32e334SJonas Sundström BackgroundsApplication(); 40*529ff59fSJonas Sundström virtual void MessageReceived(BMessage* message); 41eb32e334SJonas Sundström virtual void RefsReceived(BMessage* message); 42eb32e334SJonas Sundström 43eb32e334SJonas Sundström private: 44eb32e334SJonas Sundström BackgroundsWindow* fWindow; 45cd2d1ffdSAxel Dörfler }; 46cd2d1ffdSAxel Dörfler 47cd2d1ffdSAxel Dörfler 48cd2d1ffdSAxel Dörfler // #pragma mark - 49cd2d1ffdSAxel Dörfler 50cd2d1ffdSAxel Dörfler 51cd2d1ffdSAxel Dörfler BackgroundsApplication::BackgroundsApplication() 52eb32e334SJonas Sundström : 53eb32e334SJonas Sundström BApplication(kSignature), 54eb32e334SJonas Sundström fWindow(new BackgroundsWindow()) 55cd2d1ffdSAxel Dörfler { 56eb32e334SJonas Sundström fWindow->Show(); 57cd2d1ffdSAxel Dörfler } 58cd2d1ffdSAxel Dörfler 59cd2d1ffdSAxel Dörfler 600a74004cSRyan Leavengood void 61*529ff59fSJonas Sundström BackgroundsApplication::MessageReceived(BMessage* message) 62*529ff59fSJonas Sundström { 63*529ff59fSJonas Sundström switch (message->what) { 64*529ff59fSJonas Sundström case B_SILENT_RELAUNCH: 65*529ff59fSJonas Sundström fWindow->Activate(); 66*529ff59fSJonas Sundström break; 67*529ff59fSJonas Sundström default; 68*529ff59fSJonas Sundström BApplication::MessageReceived(message); 69*529ff59fSJonas Sundström break; 70*529ff59fSJonas Sundström } 71*529ff59fSJonas Sundström } 72*529ff59fSJonas Sundström 73*529ff59fSJonas Sundström 74*529ff59fSJonas Sundström void 750a74004cSRyan Leavengood BackgroundsApplication::RefsReceived(BMessage* message) 760a74004cSRyan Leavengood { 77eb32e334SJonas Sundström fWindow->RefsReceived(message); 780a74004cSRyan Leavengood } 790a74004cSRyan Leavengood 80dca191e9SJonas Sundström 81cd2d1ffdSAxel Dörfler // #pragma mark - 82cd2d1ffdSAxel Dörfler 83cd2d1ffdSAxel Dörfler 84eb32e334SJonas Sundström BackgroundsWindow::BackgroundsWindow() 85eb32e334SJonas Sundström : 86eb32e334SJonas Sundström BWindow(BRect(0, 0, 0, 0), "Backgrounds", B_TITLED_WINDOW, 87eb32e334SJonas Sundström B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS, 88eb32e334SJonas Sundström B_ALL_WORKSPACES) 89cd2d1ffdSAxel Dörfler { 90eb32e334SJonas Sundström fBackgroundsView = new BackgroundsView(); 91eb32e334SJonas Sundström 92eb32e334SJonas Sundström BLayoutBuilder::Group<>(this) 93eb32e334SJonas Sundström .AddGroup(B_HORIZONTAL, 0) 94eb32e334SJonas Sundström .Add(fBackgroundsView) 95eb32e334SJonas Sundström .End() 96eb32e334SJonas Sundström .End(); 97eb32e334SJonas Sundström 98eb32e334SJonas Sundström if (!fBackgroundsView->FoundPositionSetting()) 99eb32e334SJonas Sundström CenterOnScreen(); 100eb32e334SJonas Sundström } 101eb32e334SJonas Sundström 102eb32e334SJonas Sundström 103eb32e334SJonas Sundström void 104eb32e334SJonas Sundström BackgroundsWindow::RefsReceived(BMessage* message) 105eb32e334SJonas Sundström { 106eb32e334SJonas Sundström fBackgroundsView->RefsReceived(message); 107*529ff59fSJonas Sundström Activate(); 108cd2d1ffdSAxel Dörfler } 109cd2d1ffdSAxel Dörfler 110cd2d1ffdSAxel Dörfler 111cd2d1ffdSAxel Dörfler bool 112cd2d1ffdSAxel Dörfler BackgroundsWindow::QuitRequested() 113cd2d1ffdSAxel Dörfler { 114cd2d1ffdSAxel Dörfler fBackgroundsView->SaveSettings(); 115cd2d1ffdSAxel Dörfler be_app->PostMessage(B_QUIT_REQUESTED); 116cd2d1ffdSAxel Dörfler 117cd2d1ffdSAxel Dörfler return true; 118cd2d1ffdSAxel Dörfler } 119cd2d1ffdSAxel Dörfler 120cd2d1ffdSAxel Dörfler 121cd2d1ffdSAxel Dörfler void 122cd2d1ffdSAxel Dörfler BackgroundsWindow::WorkspaceActivated(int32 oldWorkspaces, bool active) 123cd2d1ffdSAxel Dörfler { 124cd2d1ffdSAxel Dörfler fBackgroundsView->WorkspaceActivated(oldWorkspaces, active); 125cd2d1ffdSAxel Dörfler } 126cd2d1ffdSAxel Dörfler 127cd2d1ffdSAxel Dörfler 128cd2d1ffdSAxel Dörfler // #pragma mark - 129cd2d1ffdSAxel Dörfler 130cd2d1ffdSAxel Dörfler 131cd2d1ffdSAxel Dörfler int 132cd2d1ffdSAxel Dörfler main(int argc, char** argv) 133cd2d1ffdSAxel Dörfler { 134cd2d1ffdSAxel Dörfler BApplication* app = new BackgroundsApplication; 135cd2d1ffdSAxel Dörfler app->Run(); 136cd2d1ffdSAxel Dörfler delete app; 137cd2d1ffdSAxel Dörfler 138cd2d1ffdSAxel Dörfler return 0; 139cd2d1ffdSAxel Dörfler } 140cd2d1ffdSAxel Dörfler 141