xref: /haiku/src/preferences/appearance/APRWindow.cpp (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
1 /*
2  * Copyright 2002-2006, Haiku. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		DarkWyrm (darkwyrm@earthlink.net)
7  */
8 #include "APRWindow.h"
9 
10 #include <Button.h>
11 #include <Catalog.h>
12 #include <GroupLayoutBuilder.h>
13 #include <Locale.h>
14 #include <Messenger.h>
15 #include <SpaceLayoutItem.h>
16 #include <TabView.h>
17 
18 #include "APRView.h"
19 #include "defs.h"
20 
21 #define TR_CONTEXT "APRWindow"
22 
23 static const uint32 kMsgSetDefaults = 'dflt';
24 static const uint32 kMsgRevert = 'rvrt';
25 
26 APRWindow::APRWindow(BRect frame)
27  :	BWindow(frame, TR("Appearance"), B_TITLED_WINDOW,
28  		B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS,
29  		B_ALL_WORKSPACES)
30 {
31 
32 	SetLayout(new BGroupLayout(B_HORIZONTAL));
33 
34 	fDefaultsButton = new BButton("defaults", TR("Defaults"),
35 		new BMessage(kMsgSetDefaults), B_WILL_DRAW);
36 
37 	fRevertButton = new BButton("revert", TR("Revert"),
38 		new BMessage(kMsgRevert), B_WILL_DRAW);
39 
40 	BTabView* tabView = new BTabView("tabview", B_WIDTH_FROM_LABEL);
41 
42 	fAntialiasingSettings = new AntialiasingSettingsView(TR("Antialiasing"));
43 	fColorsView = new APRView(TR("Colors"), B_WILL_DRAW);
44 
45 	tabView->AddTab(fColorsView);
46 	tabView->AddTab(fAntialiasingSettings);
47 
48 	fDefaultsButton->SetEnabled(fColorsView->IsDefaultable()
49 		|| fAntialiasingSettings->IsDefaultable());
50 	fRevertButton->SetEnabled(false);
51 
52 	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
53 		.Add(tabView)
54 		.Add(BSpaceLayoutItem::CreateVerticalStrut(5))
55 		.Add(BGroupLayoutBuilder(B_HORIZONTAL)
56 			.Add(fRevertButton)
57 			.AddGlue()
58 			.Add(fDefaultsButton)
59 		)
60 		.SetInsets(5, 5, 5, 5)
61 	);
62 }
63 
64 
65 void
66 APRWindow::MessageReceived(BMessage *message)
67 {
68 	switch (message->what) {
69 		case kMsgUpdate:
70 			fDefaultsButton->SetEnabled(fColorsView->IsDefaultable()
71 								|| fAntialiasingSettings->IsDefaultable());
72 			fRevertButton->SetEnabled(true);
73 			break;
74 		case kMsgSetDefaults:
75 			fColorsView -> MessageReceived(new BMessage(DEFAULT_SETTINGS));
76 			fAntialiasingSettings->SetDefaults();
77 			fDefaultsButton->SetEnabled(false);
78 			fRevertButton->SetEnabled(true);
79 			break;
80 
81 		case kMsgRevert:
82 			fColorsView -> MessageReceived(new BMessage(REVERT_SETTINGS));
83 			fAntialiasingSettings->Revert();
84 			fDefaultsButton->SetEnabled(fColorsView->IsDefaultable()
85 								|| fAntialiasingSettings->IsDefaultable());
86 			fRevertButton->SetEnabled(false);
87 			break;
88 
89 		default:
90 			BWindow::MessageReceived(message);
91 			break;
92 	}
93 }
94 
95 
96 bool
97 APRWindow::QuitRequested(void)
98 {
99 	be_app->PostMessage(B_QUIT_REQUESTED);
100 	return(true);
101 }
102