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
12 #include "PrefsWindow.h"
15 #include "ConfigView.h"
20 #include <TextControl.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
),
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
);
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();
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
);
64 deskbarView
->GetPreferredSize(&width
, &height
);
65 normalView
->ResizeTo(width
, height
);
66 miniView
->ResizeTo(width
, height
);
67 deskbarView
->ResizeTo(width
, height
);
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();
104 PrefsWindow::MessageReceived(BMessage
*message
)
106 switch (message
->what
) {
112 ConfigView
*deskbar
= (ConfigView
*)FindView(
113 B_TRANSLATE("Deskbar mode"));
114 deskbar
->UpdateDeskbarIconWidth();
116 PostMessage(B_QUIT_REQUESTED
);
120 case PRV_BOTTOM_DEFAULTS
:
122 BTab
*tab
= fTabView
->TabAt(fTabView
->Selection());
123 BView
*view
= tab
->View();
124 view
->MessageReceived(message
);
129 BWindow::MessageReceived(message
);
136 PrefsWindow::QuitRequested()
138 fTarget
.SendMessage(new BMessage(PRV_QUIT
));