xref: /haiku/src/preferences/appearance/APRWindow.cpp (revision 21258e2674226d6aa732321b6f8494841895af5f)
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 <LayoutBuilder.h>
17 #include <Locale.h>
18 #include <Messenger.h>
19 #include <SeparatorView.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 	fDefaultsButton = new BButton("defaults", B_TRANSLATE("Defaults"),
44 		new BMessage(kMsgSetDefaults), B_WILL_DRAW);
45 
46 	fRevertButton = new BButton("revert", B_TRANSLATE("Revert"),
47 		new BMessage(kMsgRevert), B_WILL_DRAW);
48 
49 	BTabView* tabView = new BTabView("tabview", B_WIDTH_FROM_LABEL);
50 
51 	fFontSettings = new FontView(B_TRANSLATE("Fonts"));
52 
53 	fColorsView = new APRView(B_TRANSLATE("Colors"));
54 
55 	fLookAndFeelSettings = new LookAndFeelSettingsView(
56 		B_TRANSLATE("Look and feel"));
57 
58 	fAntialiasingSettings = new AntialiasingSettingsView(
59 		B_TRANSLATE("Antialiasing"));
60 
61 	tabView->AddTab(fFontSettings);
62 	tabView->AddTab(fColorsView);
63 	tabView->AddTab(fLookAndFeelSettings);
64 	tabView->AddTab(fAntialiasingSettings);
65 	tabView->SetBorder(B_NO_BORDER);
66 
67 	_UpdateButtons();
68 
69 	BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
70 		.SetInsets(0, B_USE_DEFAULT_SPACING, 0, B_USE_DEFAULT_SPACING)
71 		.Add(tabView)
72 		.Add(new BSeparatorView(B_HORIZONTAL))
73 		.AddGroup(B_HORIZONTAL)
74 			.Add(fDefaultsButton)
75 			.Add(fRevertButton)
76 			.SetInsets(B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING,
77 				B_USE_DEFAULT_SPACING, 0)
78 			.AddGlue();
79 }
80 
81 
82 void
83 APRWindow::MessageReceived(BMessage *message)
84 {
85 	switch (message->what) {
86 		case kMsgUpdate:
87 			_UpdateButtons();
88 			break;
89 
90 		case kMsgSetDefaults:
91 			fFontSettings->SetDefaults();
92 			fColorsView->SetDefaults();
93 			fLookAndFeelSettings->SetDefaults();
94 			fAntialiasingSettings->SetDefaults();
95 
96 			_UpdateButtons();
97 			break;
98 
99 		case kMsgRevert:
100 			fFontSettings->Revert();
101 			fColorsView->Revert();
102 			fLookAndFeelSettings->Revert();
103 			fAntialiasingSettings->Revert();
104 
105 			_UpdateButtons();
106 			break;
107 
108 		default:
109 			BWindow::MessageReceived(message);
110 			break;
111 	}
112 }
113 
114 
115 void
116 APRWindow::_UpdateButtons()
117 {
118 	fDefaultsButton->SetEnabled(_IsDefaultable());
119 	fRevertButton->SetEnabled(_IsRevertable());
120 }
121 
122 
123 bool
124 APRWindow::_IsDefaultable() const
125 {
126 //	printf("fonts defaultable: %d\n", fFontSettings->IsDefaultable());
127 //	printf("colors defaultable: %d\n", fColorsView->IsDefaultable());
128 //	printf("AA defaultable: %d\n", fAntialiasingSettings->IsDefaultable());
129 //	printf("decor defaultable: %d\n", fLookAndFeelSettings->IsDefaultable());
130 	return fFontSettings->IsDefaultable()
131 		|| fColorsView->IsDefaultable()
132 		|| fLookAndFeelSettings->IsDefaultable()
133 		|| fAntialiasingSettings->IsDefaultable();
134 }
135 
136 
137 bool
138 APRWindow::_IsRevertable() const
139 {
140 //	printf("fonts revertable: %d\n", fFontSettings->IsRevertable());
141 //	printf("colors revertable: %d\n", fColorsView->IsRevertable());
142 //	printf("AA revertable: %d\n", fAntialiasingSettings->IsRevertable());
143 //	printf("decor revertable: %d\n", fLookAndFeelSettings->IsRevertable());
144 	return fFontSettings->IsRevertable()
145 		|| fColorsView->IsRevertable()
146 		|| fLookAndFeelSettings->IsRevertable()
147 		|| fAntialiasingSettings->IsRevertable();
148 }
149