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