xref: /haiku/src/preferences/screen/RefreshWindow.cpp (revision 0a5286c1200652bbb4c2bf0684447611534dceef)
129e8a73aSAxel Dörfler /*
229e8a73aSAxel Dörfler  * Copyright 2001-2006, Haiku.
329e8a73aSAxel Dörfler  * Distributed under the terms of the MIT License.
429e8a73aSAxel Dörfler  *
529e8a73aSAxel Dörfler  * Authors:
629e8a73aSAxel Dörfler  *		Rafael Romo
729e8a73aSAxel Dörfler  *		Stefano Ceccherini (burton666@libero.it)
829e8a73aSAxel Dörfler  *		Axel Dörfler, axeld@pinc-software.de
929e8a73aSAxel Dörfler  */
1029e8a73aSAxel Dörfler 
11a10cf76eSAxel Dörfler 
12a10cf76eSAxel Dörfler #include "RefreshWindow.h"
13c5d10f7aSAxel Dörfler 
14a10cf76eSAxel Dörfler #include "Constants.h"
15c5d10f7aSAxel Dörfler #include "RefreshSlider.h"
16a10cf76eSAxel Dörfler 
1729e8a73aSAxel Dörfler #include <Alert.h>
1829e8a73aSAxel Dörfler #include <Application.h>
1929e8a73aSAxel Dörfler #include <Button.h>
20c9e8f97aSAdrien Destugues #include <Catalog.h>
2129e8a73aSAxel Dörfler #include <String.h>
22c5d10f7aSAxel Dörfler #include <StringView.h>
2329e8a73aSAxel Dörfler #include <Window.h>
2429e8a73aSAxel Dörfler 
2529e8a73aSAxel Dörfler 
26546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
27546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "Screen"
28c9e8f97aSAdrien Destugues 
29c9e8f97aSAdrien Destugues 
RefreshWindow(BPoint position,float current,float min,float max)30c5d10f7aSAxel Dörfler RefreshWindow::RefreshWindow(BPoint position, float current, float min, float max)
31551c9f15SSiarzhuk Zharski 	: BWindow(BRect(0, 0, 300, 200), B_TRANSLATE("Refresh rate"), B_MODAL_WINDOW,
32c5d10f7aSAxel Dörfler 		B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS, B_ALL_WORKSPACES)
33a10cf76eSAxel Dörfler {
3429e8a73aSAxel Dörfler 	min = ceilf(min);
3529e8a73aSAxel Dörfler 	max = floorf(max);
3629e8a73aSAxel Dörfler 
37c5d10f7aSAxel Dörfler 	BView* topView = new BView(Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW);
38f0650dc9Slooncraz 	topView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
39*0a5286c1SNiklas Poslovski 	topView->SetHighUIColor(B_PANEL_TEXT_COLOR);
40c5d10f7aSAxel Dörfler 	AddChild(topView);
41a10cf76eSAxel Dörfler 
42c5d10f7aSAxel Dörfler 	BRect rect = Bounds().InsetByCopy(8, 8);
43c5d10f7aSAxel Dörfler 	BStringView* stringView = new BStringView(rect, "info",
44c9e8f97aSAdrien Destugues 		B_TRANSLATE("Type or use the left and right arrow keys."));
45c5d10f7aSAxel Dörfler 	stringView->ResizeToPreferred();
46c5d10f7aSAxel Dörfler 	topView->AddChild(stringView);
47a10cf76eSAxel Dörfler 
48c5d10f7aSAxel Dörfler 	rect.top += stringView->Bounds().Height() + 14;
49c5d10f7aSAxel Dörfler 	fRefreshSlider = new RefreshSlider(rect, min, max, B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);
50099e08d5SStefano Ceccherini 	fRefreshSlider->SetValue((int32)rintf(current * 10));
51a10cf76eSAxel Dörfler 	fRefreshSlider->SetModificationMessage(new BMessage(SLIDER_MODIFICATION_MSG));
52c5d10f7aSAxel Dörfler 	float width, height;
53c5d10f7aSAxel Dörfler 	fRefreshSlider->GetPreferredSize(&width, &height);
54c5d10f7aSAxel Dörfler 	fRefreshSlider->ResizeTo(rect.Width(), height);
55c5d10f7aSAxel Dörfler 	topView->AddChild(fRefreshSlider);
56a10cf76eSAxel Dörfler 
57c9e8f97aSAdrien Destugues 	BButton* doneButton = new BButton(rect, "DoneButton", B_TRANSLATE("Done"),
58c5d10f7aSAxel Dörfler 		new BMessage(BUTTON_DONE_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
59c5d10f7aSAxel Dörfler 	doneButton->ResizeToPreferred();
60c5d10f7aSAxel Dörfler 	doneButton->MoveTo(Bounds().Width() - doneButton->Bounds().Width() - 8,
61c5d10f7aSAxel Dörfler 		Bounds().Height() - doneButton->Bounds().Height() - 8);
62c5d10f7aSAxel Dörfler 	topView->AddChild(doneButton);
63a10cf76eSAxel Dörfler 
64c9e8f97aSAdrien Destugues 	BButton* button = new BButton(doneButton->Frame(), "CancelButton",
65c9e8f97aSAdrien Destugues 		B_TRANSLATE("Cancel"), new BMessage(B_QUIT_REQUESTED),
66c9e8f97aSAdrien Destugues 		B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
67c5d10f7aSAxel Dörfler 	button->ResizeToPreferred();
68c5d10f7aSAxel Dörfler 	button->MoveBy(-button->Bounds().Width() - 10, 0);
69c5d10f7aSAxel Dörfler 	topView->AddChild(button);
70a10cf76eSAxel Dörfler 
71c5d10f7aSAxel Dörfler 	doneButton->MakeDefault(true);
72a10cf76eSAxel Dörfler 
73c5d10f7aSAxel Dörfler 	width = stringView->Bounds().Width() + 100;
74c5d10f7aSAxel Dörfler 	if (width < Bounds().Width())
75c5d10f7aSAxel Dörfler 		width = Bounds().Width();
76c5d10f7aSAxel Dörfler 	height = fRefreshSlider->Frame().bottom + button->Bounds().Height() + 20.0f;
77a10cf76eSAxel Dörfler 
78c5d10f7aSAxel Dörfler 	ResizeTo(width, height);
79c5d10f7aSAxel Dörfler 	MoveTo(position.x - width / 2.5f, position.y - height / 1.9f);
80a10cf76eSAxel Dörfler }
81a10cf76eSAxel Dörfler 
82a10cf76eSAxel Dörfler 
83a10cf76eSAxel Dörfler void
WindowActivated(bool active)84a10cf76eSAxel Dörfler RefreshWindow::WindowActivated(bool active)
85a10cf76eSAxel Dörfler {
86a10cf76eSAxel Dörfler 	fRefreshSlider->MakeFocus(active);
87a10cf76eSAxel Dörfler }
88a10cf76eSAxel Dörfler 
89a10cf76eSAxel Dörfler 
90a10cf76eSAxel Dörfler void
MessageReceived(BMessage * message)91a10cf76eSAxel Dörfler RefreshWindow::MessageReceived(BMessage* message)
92a10cf76eSAxel Dörfler {
93c5d10f7aSAxel Dörfler 	switch (message->what) {
94a10cf76eSAxel Dörfler 		case BUTTON_DONE_MSG:
95a10cf76eSAxel Dörfler 		{
96a10cf76eSAxel Dörfler 			float value = (float)fRefreshSlider->Value() / 10;
97a10cf76eSAxel Dörfler 
98c5d10f7aSAxel Dörfler 			BMessage message(SET_CUSTOM_REFRESH_MSG);
99a10cf76eSAxel Dörfler 			message.AddFloat("refresh", value);
100a10cf76eSAxel Dörfler 			be_app->PostMessage(&message);
101a10cf76eSAxel Dörfler 
102a10cf76eSAxel Dörfler 			PostMessage(B_QUIT_REQUESTED);
103a10cf76eSAxel Dörfler 			break;
104a10cf76eSAxel Dörfler 		}
105a10cf76eSAxel Dörfler 
106a10cf76eSAxel Dörfler 		case SLIDER_INVOKE_MSG:
107a10cf76eSAxel Dörfler 			fRefreshSlider->MakeFocus(true);
108a10cf76eSAxel Dörfler 			break;
109a10cf76eSAxel Dörfler 
110a10cf76eSAxel Dörfler 		default:
111a10cf76eSAxel Dörfler 			BWindow::MessageReceived(message);
112a10cf76eSAxel Dörfler 			break;
113a10cf76eSAxel Dörfler 	}
114a10cf76eSAxel Dörfler }
115