BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / pulse / PrefsWindow.cpp
blob3521b81c48afe3d299ca46444c785441d2f0ba29
1 /*
2 * Copyright 2002-2009, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT license.
5 * Copyright 1999, Be Incorporated. All Rights Reserved.
6 * This file may be used under the terms of the Be Sample Code License.
8 * Written by: Daniel Switkin
9 */
12 #include "PrefsWindow.h"
13 #include "Common.h"
14 #include "PulseApp.h"
15 #include "ConfigView.h"
17 #include <Catalog.h>
18 #include <Button.h>
19 #include <TabView.h>
20 #include <TextControl.h>
22 #include <stdlib.h>
23 #include <stdio.h>
25 #undef B_TRANSLATION_CONTEXT
26 #define B_TRANSLATION_CONTEXT "PrefsWindow"
29 PrefsWindow::PrefsWindow(BRect frame, const char *name,
30 BMessenger *messenger, Prefs *prefs)
31 : BWindow(frame, name, B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
32 | B_NOT_MINIMIZABLE | B_ASYNCHRONOUS_CONTROLS),
33 fTarget(*messenger),
34 fPrefs(prefs)
36 // This gives a nice look, and sets the background color correctly
37 BRect bounds = Bounds();
38 BView* topView = new BView(bounds, "ParentView", B_FOLLOW_ALL, B_WILL_DRAW);
39 topView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
40 AddChild(topView);
42 bounds.top += 10;
43 bounds.bottom -= 45;
44 fTabView = new BTabView(bounds, "TabView", B_WIDTH_FROM_LABEL);
45 fTabView->SetFont(be_plain_font);
46 topView->AddChild(fTabView);
48 BRect rect = fTabView->ContainerView()->Bounds();
49 rect.InsetBy(5, 5);
51 ConfigView *normalView = new ConfigView(rect, B_TRANSLATE("Normal mode"),
52 PRV_NORMAL_CHANGE_COLOR, fTarget, prefs);
53 fTabView->AddTab(normalView);
55 ConfigView *miniView = new ConfigView(rect, B_TRANSLATE("Mini mode"),
56 PRV_MINI_CHANGE_COLOR, fTarget, prefs);
57 fTabView->AddTab(miniView);
59 ConfigView *deskbarView = new ConfigView(rect, B_TRANSLATE("Deskbar mode"),
60 PRV_DESKBAR_CHANGE_COLOR, fTarget, prefs);
61 fTabView->AddTab(deskbarView);
63 float width, height;
64 deskbarView->GetPreferredSize(&width, &height);
65 normalView->ResizeTo(width, height);
66 miniView->ResizeTo(width, height);
67 deskbarView->ResizeTo(width, height);
69 fTabView->Select(0L);
70 fTabView->ResizeTo(deskbarView->Bounds().Width() + 16.0f,
71 deskbarView->Bounds().Height() +
72 fTabView->ContainerView()->Frame().top + 16.0f);
74 BButton *okButton = new BButton(rect, "ok", B_TRANSLATE("OK"),
75 new BMessage(PRV_BOTTOM_OK), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
76 okButton->ResizeToPreferred();
77 okButton->MoveTo(Bounds().Width() - 8.0f - okButton->Bounds().Width(),
78 Bounds().Height() - 8.0f - okButton->Bounds().Height());
79 topView->AddChild(okButton);
81 BButton *defaultsButton = new BButton(okButton->Frame(), "defaults",
82 B_TRANSLATE("Defaults"), new BMessage(PRV_BOTTOM_DEFAULTS),
83 B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
84 defaultsButton->ResizeToPreferred();
85 defaultsButton->MoveBy(-defaultsButton->Bounds().Width() - 10.0f, 0.0f);
86 topView->AddChild(defaultsButton);
88 okButton->MakeDefault(true);
90 fTabView->SetResizingMode(B_FOLLOW_NONE);
91 ResizeTo(fTabView->Frame().Width(), fTabView->Frame().bottom + 16.0f
92 + okButton->Bounds().Height());
96 PrefsWindow::~PrefsWindow()
98 fPrefs->prefs_window_rect = Frame();
99 fPrefs->Save();
103 void
104 PrefsWindow::MessageReceived(BMessage *message)
106 switch (message->what) {
107 case PRV_BOTTOM_OK:
109 Hide();
111 fTabView->Select(2);
112 ConfigView *deskbar = (ConfigView *)FindView(
113 B_TRANSLATE("Deskbar mode"));
114 deskbar->UpdateDeskbarIconWidth();
116 PostMessage(B_QUIT_REQUESTED);
117 break;
120 case PRV_BOTTOM_DEFAULTS:
122 BTab *tab = fTabView->TabAt(fTabView->Selection());
123 BView *view = tab->View();
124 view->MessageReceived(message);
125 break;
128 default:
129 BWindow::MessageReceived(message);
130 break;
135 bool
136 PrefsWindow::QuitRequested()
138 fTarget.SendMessage(new BMessage(PRV_QUIT));
139 return true;