xref: /haiku/src/preferences/backgrounds/Backgrounds.cpp (revision 560ff4478d5c85455ea3e5ed5e392ef93132d545)
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 #undef B_TRANSLATE_CONTEXT
22 #define B_TRANSLATE_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 -
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 	switch (message->what) {
71 		case B_SILENT_RELAUNCH:
72 			fWindow->Activate();
73 			break;
74 		default:
75 			BApplication::MessageReceived(message);
76 			break;
77 	}
78 }
79 
80 
81 void
82 BackgroundsApplication::RefsReceived(BMessage* message)
83 {
84 	fWindow->RefsReceived(message);
85 }
86 
87 
88 //	#pragma mark -
89 
90 
91 BackgroundsWindow::BackgroundsWindow()
92 	:
93 	BWindow(BRect(0, 0, 0, 0), B_TRANSLATE_SYSTEM_NAME("Backgrounds"),
94 		B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
95 			| 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