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