xref: /haiku/src/preferences/appearance/APRWindow.cpp (revision 1294543de9ac0eff000eaea1b18368c36435d08e)
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 #undef B_TRANSLATE_CONTEXT
22 #define B_TRANSLATE_CONTEXT "APRWindow"
23 
24 static const uint32 kMsgSetDefaults = 'dflt';
25 static const uint32 kMsgRevert = 'rvrt';
26 
27 APRWindow::APRWindow(BRect frame)
28  :	BWindow(frame, B_TRANSLATE("Appearance"), B_TITLED_WINDOW,
29  		B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS,
30  		B_ALL_WORKSPACES)
31 {
32 
33 	SetLayout(new BGroupLayout(B_HORIZONTAL));
34 
35 	fDefaultsButton = new BButton("defaults", B_TRANSLATE("Defaults"),
36 		new BMessage(kMsgSetDefaults), B_WILL_DRAW);
37 
38 	fRevertButton = new BButton("revert", B_TRANSLATE("Revert"),
39 		new BMessage(kMsgRevert), B_WILL_DRAW);
40 
41 	BTabView* tabView = new BTabView("tabview", B_WIDTH_FROM_LABEL);
42 
43 	fAntialiasingSettings = new AntialiasingSettingsView(
44 		B_TRANSLATE("Antialiasing"));
45 	fColorsView = new APRView(B_TRANSLATE("Colors"), B_WILL_DRAW);
46 
47 	tabView->AddTab(fColorsView);
48 	tabView->AddTab(fAntialiasingSettings);
49 
50 	fDefaultsButton->SetEnabled(fColorsView->IsDefaultable()
51 		|| fAntialiasingSettings->IsDefaultable());
52 	fRevertButton->SetEnabled(false);
53 
54 	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
55 		.Add(tabView)
56 		.Add(BSpaceLayoutItem::CreateVerticalStrut(5))
57 		.Add(BGroupLayoutBuilder(B_HORIZONTAL)
58 			.Add(fRevertButton)
59 			.AddGlue()
60 			.Add(fDefaultsButton)
61 		)
62 		.SetInsets(5, 5, 5, 5)
63 	);
64 }
65 
66 
67 void
68 APRWindow::MessageReceived(BMessage *message)
69 {
70 	switch (message->what) {
71 		case kMsgUpdate:
72 			fDefaultsButton->SetEnabled(fColorsView->IsDefaultable()
73 								|| fAntialiasingSettings->IsDefaultable());
74 			fRevertButton->SetEnabled(true);
75 			break;
76 		case kMsgSetDefaults:
77 			fColorsView -> MessageReceived(new BMessage(DEFAULT_SETTINGS));
78 			fAntialiasingSettings->SetDefaults();
79 			fDefaultsButton->SetEnabled(false);
80 			fRevertButton->SetEnabled(true);
81 			break;
82 
83 		case kMsgRevert:
84 			fColorsView -> MessageReceived(new BMessage(REVERT_SETTINGS));
85 			fAntialiasingSettings->Revert();
86 			fDefaultsButton->SetEnabled(fColorsView->IsDefaultable()
87 								|| fAntialiasingSettings->IsDefaultable());
88 			fRevertButton->SetEnabled(false);
89 			break;
90 
91 		default:
92 			BWindow::MessageReceived(message);
93 			break;
94 	}
95 }
96 
97 
98 bool
99 APRWindow::QuitRequested(void)
100 {
101 	be_app->PostMessage(B_QUIT_REQUESTED);
102 	return(true);
103 }
104