fat: Greatly simplify and clean up dosfs_get_file_map().
[haiku.git] / src / preferences / backgrounds / Backgrounds.cpp
blob84836d3ee3f0726d3374347d949292be3aa72a8c
1 /*
2 * Copyright 2002-2009 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Axel Dörfler, axeld@pinc-software.de
7 * Jerome Duval, jerome.duval@free.fr
8 */
11 #include <Application.h>
12 #include <Catalog.h>
13 #include <LayoutBuilder.h>
14 #include <Locale.h>
15 #include <TrackerAddOnAppLaunch.h>
16 #include <Window.h>
18 #include "BackgroundsView.h"
21 #undef B_TRANSLATION_CONTEXT
22 #define B_TRANSLATION_CONTEXT "Main Window"
25 static const char* kSignature = "application/x-vnd.Haiku-Backgrounds";
28 class BackgroundsWindow : public BWindow {
29 public:
30 BackgroundsWindow();
32 void RefsReceived(BMessage* message);
34 protected:
35 virtual bool QuitRequested();
36 virtual void WorkspaceActivated(int32 oldWorkspaces,
37 bool active);
39 BackgroundsView* fBackgroundsView;
43 class BackgroundsApplication : public BApplication {
44 public:
45 BackgroundsApplication();
46 virtual void MessageReceived(BMessage* message);
47 virtual void RefsReceived(BMessage* message);
49 private:
50 BackgroundsWindow* fWindow;
54 // #pragma mark - BackgroundsApplication
57 BackgroundsApplication::BackgroundsApplication()
59 BApplication(kSignature),
60 fWindow(NULL)
62 fWindow = new BackgroundsWindow();
63 fWindow->Show();
67 void
68 BackgroundsApplication::MessageReceived(BMessage* message)
70 const void *data;
71 ssize_t size;
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;
79 switch (message->what) {
80 case B_SILENT_RELAUNCH:
81 fWindow->Activate();
82 break;
83 default:
84 BApplication::MessageReceived(message);
85 break;
90 void
91 BackgroundsApplication::RefsReceived(BMessage* message)
93 fWindow->RefsReceived(message);
97 // #pragma mark - BackgroundsWindow
100 BackgroundsWindow::BackgroundsWindow()
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)
107 fBackgroundsView = new BackgroundsView();
109 BLayoutBuilder::Group<>(this)
110 .AddGroup(B_HORIZONTAL, 0)
111 .Add(fBackgroundsView)
112 .End()
113 .End();
115 if (!fBackgroundsView->FoundPositionSetting())
116 CenterOnScreen();
120 void
121 BackgroundsWindow::RefsReceived(BMessage* message)
123 fBackgroundsView->RefsReceived(message);
124 Activate();
128 bool
129 BackgroundsWindow::QuitRequested()
131 fBackgroundsView->SaveSettings();
132 be_app->PostMessage(B_QUIT_REQUESTED);
134 return true;
138 void
139 BackgroundsWindow::WorkspaceActivated(int32 oldWorkspaces, bool active)
141 fBackgroundsView->WorkspaceActivated(oldWorkspaces, active);
145 // #pragma mark - main method
149 main(int argc, char** argv)
151 BackgroundsApplication app;
152 app.Run();
153 return 0;