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