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