docs/ikteam: Delete most files.
[haiku.git] / src / preferences / screen / RefreshWindow.cpp
blobda1b47521a3f64197570978f55195b3ea8d4daca
1 /*
2 * Copyright 2001-2006, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Rafael Romo
7 * Stefano Ceccherini (burton666@libero.it)
8 * Axel Dörfler, axeld@pinc-software.de
9 */
12 #include "RefreshWindow.h"
14 #include "Constants.h"
15 #include "RefreshSlider.h"
17 #include <Alert.h>
18 #include <Application.h>
19 #include <Button.h>
20 #include <Catalog.h>
21 #include <String.h>
22 #include <StringView.h>
23 #include <Window.h>
26 #undef B_TRANSLATION_CONTEXT
27 #define B_TRANSLATION_CONTEXT "Screen"
30 RefreshWindow::RefreshWindow(BPoint position, float current, float min, float max)
31 : BWindow(BRect(0, 0, 300, 200), B_TRANSLATE("Refresh rate"), B_MODAL_WINDOW,
32 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS, B_ALL_WORKSPACES)
34 min = ceilf(min);
35 max = floorf(max);
37 BView* topView = new BView(Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW);
38 topView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
39 AddChild(topView);
41 BRect rect = Bounds().InsetByCopy(8, 8);
42 BStringView* stringView = new BStringView(rect, "info",
43 B_TRANSLATE("Type or use the left and right arrow keys."));
44 stringView->ResizeToPreferred();
45 topView->AddChild(stringView);
47 rect.top += stringView->Bounds().Height() + 14;
48 fRefreshSlider = new RefreshSlider(rect, min, max, B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);
49 fRefreshSlider->SetValue((int32)rintf(current * 10));
50 fRefreshSlider->SetModificationMessage(new BMessage(SLIDER_MODIFICATION_MSG));
51 float width, height;
52 fRefreshSlider->GetPreferredSize(&width, &height);
53 fRefreshSlider->ResizeTo(rect.Width(), height);
54 topView->AddChild(fRefreshSlider);
56 BButton* doneButton = new BButton(rect, "DoneButton", B_TRANSLATE("Done"),
57 new BMessage(BUTTON_DONE_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
58 doneButton->ResizeToPreferred();
59 doneButton->MoveTo(Bounds().Width() - doneButton->Bounds().Width() - 8,
60 Bounds().Height() - doneButton->Bounds().Height() - 8);
61 topView->AddChild(doneButton);
63 BButton* button = new BButton(doneButton->Frame(), "CancelButton",
64 B_TRANSLATE("Cancel"), new BMessage(B_QUIT_REQUESTED),
65 B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
66 button->ResizeToPreferred();
67 button->MoveBy(-button->Bounds().Width() - 10, 0);
68 topView->AddChild(button);
70 doneButton->MakeDefault(true);
72 width = stringView->Bounds().Width() + 100;
73 if (width < Bounds().Width())
74 width = Bounds().Width();
75 height = fRefreshSlider->Frame().bottom + button->Bounds().Height() + 20.0f;
77 ResizeTo(width, height);
78 MoveTo(position.x - width / 2.5f, position.y - height / 1.9f);
82 void
83 RefreshWindow::WindowActivated(bool active)
85 fRefreshSlider->MakeFocus(active);
89 void
90 RefreshWindow::MessageReceived(BMessage* message)
92 switch (message->what) {
93 case BUTTON_DONE_MSG:
95 float value = (float)fRefreshSlider->Value() / 10;
97 BMessage message(SET_CUSTOM_REFRESH_MSG);
98 message.AddFloat("refresh", value);
99 be_app->PostMessage(&message);
101 PostMessage(B_QUIT_REQUESTED);
102 break;
105 case SLIDER_INVOKE_MSG:
106 fRefreshSlider->MakeFocus(true);
107 break;
109 default:
110 BWindow::MessageReceived(message);
111 break;