xref: /haiku/src/preferences/appearance/APRWindow.cpp (revision 04a0e9c7b68cbe3a43d38e2bca8e860fd80936fb)
1 /*
2  * Copyright 2002-2011, Haiku. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		DarkWyrm (darkwyrm@earthlink.net)
7  *		Alexander von Gluck, kallisti5@unixzen.com
8  *		Stephan Aßmus <superstippi@gmx.de>
9  */
10 
11 
12 #include "APRWindow.h"
13 
14 #include <Button.h>
15 #include <Catalog.h>
16 #include <GroupLayoutBuilder.h>
17 #include <Locale.h>
18 #include <Messenger.h>
19 #include <SpaceLayoutItem.h>
20 #include <TabView.h>
21 
22 #include "AntialiasingSettingsView.h"
23 #include "APRView.h"
24 #include "defs.h"
25 #include "FontView.h"
26 #include "LookAndFeelSettingsView.h"
27 
28 
29 #undef B_TRANSLATION_CONTEXT
30 #define B_TRANSLATION_CONTEXT "APRWindow"
31 
32 
33 static const uint32 kMsgSetDefaults = 'dflt';
34 static const uint32 kMsgRevert = 'rvrt';
35 
36 
37 APRWindow::APRWindow(BRect frame)
38 	:
39 	BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Appearance"), B_TITLED_WINDOW,
40 		B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS
41 			| B_QUIT_ON_WINDOW_CLOSE, B_ALL_WORKSPACES)
42 {
43 	SetLayout(new BGroupLayout(B_HORIZONTAL));
44 
45 	fDefaultsButton = new BButton("defaults", B_TRANSLATE("Defaults"),
46 		new BMessage(kMsgSetDefaults), B_WILL_DRAW);
47 
48 	fRevertButton = new BButton("revert", B_TRANSLATE("Revert"),
49 		new BMessage(kMsgRevert), B_WILL_DRAW);
50 
51 	BTabView* tabView = new BTabView("tabview", B_WIDTH_FROM_LABEL);
52 
53 	fFontSettings = new FontView(B_TRANSLATE("Fonts"));
54 
55 	fColorsView = new APRView(B_TRANSLATE("Colors"));
56 
57 	fLookAndFeelSettings = new LookAndFeelSettingsView(
58 		B_TRANSLATE("Look and feel"));
59 
60 	fAntialiasingSettings = new AntialiasingSettingsView(
61 		B_TRANSLATE("Antialiasing"));
62 
63 	tabView->AddTab(fFontSettings);
64 	tabView->AddTab(fColorsView);
65 	tabView->AddTab(fLookAndFeelSettings);
66 	tabView->AddTab(fAntialiasingSettings);
67 
68 	_UpdateButtons();
69 
70 	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
71 		.Add(tabView)
72 		.Add(BSpaceLayoutItem::CreateVerticalStrut(5))
73 		.Add(BGroupLayoutBuilder(B_HORIZONTAL)
74 			.Add(fDefaultsButton)
75 			.Add(fRevertButton)
76 			.AddGlue()
77 		)
78 		.SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING,
79 			B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
80 	);
81 }
82 
83 
84 void
85 APRWindow::MessageReceived(BMessage *message)
86 {
87 	switch (message->what) {
88 		case kMsgUpdate:
89 			_UpdateButtons();
90 			break;
91 
92 		case kMsgSetDefaults:
93 			fFontSettings->SetDefaults();
94 			fColorsView->SetDefaults();
95 			fLookAndFeelSettings->SetDefaults();
96 			fAntialiasingSettings->SetDefaults();
97 
98 			_UpdateButtons();
99 			break;
100 
101 		case kMsgRevert:
102 			fFontSettings->Revert();
103 			fColorsView->Revert();
104 			fLookAndFeelSettings->Revert();
105 			fAntialiasingSettings->Revert();
106 
107 			_UpdateButtons();
108 			break;
109 
110 		default:
111 			BWindow::MessageReceived(message);
112 			break;
113 	}
114 }
115 
116 
117 void
118 APRWindow::_UpdateButtons()
119 {
120 	fDefaultsButton->SetEnabled(_IsDefaultable());
121 	fRevertButton->SetEnabled(_IsRevertable());
122 }
123 
124 
125 bool
126 APRWindow::_IsDefaultable() const
127 {
128 //	printf("fonts defaultable: %d\n", fFontSettings->IsDefaultable());
129 //	printf("colors defaultable: %d\n", fColorsView->IsDefaultable());
130 //	printf("AA defaultable: %d\n", fAntialiasingSettings->IsDefaultable());
131 //	printf("decor defaultable: %d\n", fLookAndFeelSettings->IsDefaultable());
132 	return fFontSettings->IsDefaultable()
133 		|| fColorsView->IsDefaultable()
134 		|| fLookAndFeelSettings->IsDefaultable()
135 		|| fAntialiasingSettings->IsDefaultable();
136 }
137 
138 
139 bool
140 APRWindow::_IsRevertable() const
141 {
142 //	printf("fonts revertable: %d\n", fFontSettings->IsRevertable());
143 //	printf("colors revertable: %d\n", fColorsView->IsRevertable());
144 //	printf("AA revertable: %d\n", fAntialiasingSettings->IsRevertable());
145 //	printf("decor revertable: %d\n", fLookAndFeelSettings->IsRevertable());
146 	return fFontSettings->IsRevertable()
147 		|| fColorsView->IsRevertable()
148 		|| fLookAndFeelSettings->IsRevertable()
149 		|| fAntialiasingSettings->IsRevertable();
150 }
151