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_TRANSLATION_CONTEXT
22#define B_TRANSLATION_CONTEXT "Main Window"
23
24
25static const char* kSignature = "application/x-vnd.Haiku-Backgrounds";
26
27
28class BackgroundsWindow : public BWindow {
29public:
30							BackgroundsWindow();
31
32			void			RefsReceived(BMessage* message);
33
34protected:
35	virtual	bool			QuitRequested();
36	virtual	void			WorkspaceActivated(int32 oldWorkspaces,
37								bool active);
38
39			BackgroundsView*	fBackgroundsView;
40};
41
42
43class BackgroundsApplication : public BApplication {
44public:
45							BackgroundsApplication();
46	virtual	void			MessageReceived(BMessage* message);
47	virtual	void			RefsReceived(BMessage* message);
48
49private:
50			BackgroundsWindow*	fWindow;
51};
52
53
54//	#pragma mark -
55
56
57BackgroundsApplication::BackgroundsApplication()
58	:
59	BApplication(kSignature),
60	fWindow(NULL)
61{
62	fWindow = new BackgroundsWindow();
63	fWindow->Show();
64}
65
66
67void
68BackgroundsApplication::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
81void
82BackgroundsApplication::RefsReceived(BMessage* message)
83{
84	fWindow->RefsReceived(message);
85}
86
87
88//	#pragma mark -
89
90
91BackgroundsWindow::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
111void
112BackgroundsWindow::RefsReceived(BMessage* message)
113{
114	fBackgroundsView->RefsReceived(message);
115	Activate();
116}
117
118
119bool
120BackgroundsWindow::QuitRequested()
121{
122	fBackgroundsView->SaveSettings();
123	be_app->PostMessage(B_QUIT_REQUESTED);
124
125	return true;
126}
127
128
129void
130BackgroundsWindow::WorkspaceActivated(int32 oldWorkspaces, bool active)
131{
132	fBackgroundsView->WorkspaceActivated(oldWorkspaces, active);
133}
134
135
136//	#pragma mark -
137
138
139int
140main(int argc, char** argv)
141{
142	BackgroundsApplication app;
143	app.Run();
144	return 0;
145}
146
147