2 * Copyright 2001-2006, Haiku.
3 * Distributed under the terms of the MIT License.
7 * Stefano Ceccherini (burton666@libero.it)
8 * Axel Dörfler, axeld@pinc-software.de
12 #include "RefreshWindow.h"
14 #include "Constants.h"
15 #include "RefreshSlider.h"
18 #include <Application.h>
22 #include <StringView.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
)
37 BView
* topView
= new BView(Bounds(), NULL
, B_FOLLOW_ALL
, B_WILL_DRAW
);
38 topView
->SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
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
));
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
);
83 RefreshWindow::WindowActivated(bool active
)
85 fRefreshSlider
->MakeFocus(active
);
90 RefreshWindow::MessageReceived(BMessage
* message
)
92 switch (message
->what
) {
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
);
105 case SLIDER_INVOKE_MSG
:
106 fRefreshSlider
->MakeFocus(true);
110 BWindow::MessageReceived(message
);