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> 20*c9e8f97aSAdrien 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 26*c9e8f97aSAdrien Destugues #undef B_TRANSLATE_CONTEXT 27*c9e8f97aSAdrien Destugues #define B_TRANSLATE_CONTEXT "Screen" 28*c9e8f97aSAdrien Destugues 29*c9e8f97aSAdrien Destugues 30c5d10f7aSAxel Dörfler RefreshWindow::RefreshWindow(BPoint position, float current, float min, float max) 31*c9e8f97aSAdrien Destugues : 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); 38c5d10f7aSAxel Dörfler topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 39c5d10f7aSAxel Dörfler AddChild(topView); 40a10cf76eSAxel Dörfler 41c5d10f7aSAxel Dörfler BRect rect = Bounds().InsetByCopy(8, 8); 42c5d10f7aSAxel Dörfler BStringView* stringView = new BStringView(rect, "info", 43*c9e8f97aSAdrien Destugues B_TRANSLATE("Type or use the left and right arrow keys.")); 44c5d10f7aSAxel Dörfler stringView->ResizeToPreferred(); 45c5d10f7aSAxel Dörfler topView->AddChild(stringView); 46a10cf76eSAxel Dörfler 47c5d10f7aSAxel Dörfler rect.top += stringView->Bounds().Height() + 14; 48c5d10f7aSAxel Dörfler fRefreshSlider = new RefreshSlider(rect, min, max, B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT); 49099e08d5SStefano Ceccherini fRefreshSlider->SetValue((int32)rintf(current * 10)); 50a10cf76eSAxel Dörfler fRefreshSlider->SetModificationMessage(new BMessage(SLIDER_MODIFICATION_MSG)); 51c5d10f7aSAxel Dörfler float width, height; 52c5d10f7aSAxel Dörfler fRefreshSlider->GetPreferredSize(&width, &height); 53c5d10f7aSAxel Dörfler fRefreshSlider->ResizeTo(rect.Width(), height); 54c5d10f7aSAxel Dörfler topView->AddChild(fRefreshSlider); 55a10cf76eSAxel Dörfler 56*c9e8f97aSAdrien Destugues BButton* doneButton = new BButton(rect, "DoneButton", B_TRANSLATE("Done"), 57c5d10f7aSAxel Dörfler new BMessage(BUTTON_DONE_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 58c5d10f7aSAxel Dörfler doneButton->ResizeToPreferred(); 59c5d10f7aSAxel Dörfler doneButton->MoveTo(Bounds().Width() - doneButton->Bounds().Width() - 8, 60c5d10f7aSAxel Dörfler Bounds().Height() - doneButton->Bounds().Height() - 8); 61c5d10f7aSAxel Dörfler topView->AddChild(doneButton); 62a10cf76eSAxel Dörfler 63*c9e8f97aSAdrien Destugues BButton* button = new BButton(doneButton->Frame(), "CancelButton", 64*c9e8f97aSAdrien Destugues B_TRANSLATE("Cancel"), new BMessage(B_QUIT_REQUESTED), 65*c9e8f97aSAdrien Destugues B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 66c5d10f7aSAxel Dörfler button->ResizeToPreferred(); 67c5d10f7aSAxel Dörfler button->MoveBy(-button->Bounds().Width() - 10, 0); 68c5d10f7aSAxel Dörfler topView->AddChild(button); 69a10cf76eSAxel Dörfler 70c5d10f7aSAxel Dörfler doneButton->MakeDefault(true); 71a10cf76eSAxel Dörfler 72c5d10f7aSAxel Dörfler width = stringView->Bounds().Width() + 100; 73c5d10f7aSAxel Dörfler if (width < Bounds().Width()) 74c5d10f7aSAxel Dörfler width = Bounds().Width(); 75c5d10f7aSAxel Dörfler height = fRefreshSlider->Frame().bottom + button->Bounds().Height() + 20.0f; 76a10cf76eSAxel Dörfler 77c5d10f7aSAxel Dörfler ResizeTo(width, height); 78c5d10f7aSAxel Dörfler MoveTo(position.x - width / 2.5f, position.y - height / 1.9f); 79a10cf76eSAxel Dörfler } 80a10cf76eSAxel Dörfler 81a10cf76eSAxel Dörfler 82a10cf76eSAxel Dörfler void 83a10cf76eSAxel Dörfler RefreshWindow::WindowActivated(bool active) 84a10cf76eSAxel Dörfler { 85a10cf76eSAxel Dörfler fRefreshSlider->MakeFocus(active); 86a10cf76eSAxel Dörfler } 87a10cf76eSAxel Dörfler 88a10cf76eSAxel Dörfler 89a10cf76eSAxel Dörfler void 90a10cf76eSAxel Dörfler RefreshWindow::MessageReceived(BMessage* message) 91a10cf76eSAxel Dörfler { 92c5d10f7aSAxel Dörfler switch (message->what) { 93a10cf76eSAxel Dörfler case BUTTON_DONE_MSG: 94a10cf76eSAxel Dörfler { 95a10cf76eSAxel Dörfler float value = (float)fRefreshSlider->Value() / 10; 96a10cf76eSAxel Dörfler 97c5d10f7aSAxel Dörfler BMessage message(SET_CUSTOM_REFRESH_MSG); 98a10cf76eSAxel Dörfler message.AddFloat("refresh", value); 99a10cf76eSAxel Dörfler be_app->PostMessage(&message); 100a10cf76eSAxel Dörfler 101a10cf76eSAxel Dörfler PostMessage(B_QUIT_REQUESTED); 102a10cf76eSAxel Dörfler break; 103a10cf76eSAxel Dörfler } 104a10cf76eSAxel Dörfler 105a10cf76eSAxel Dörfler case SLIDER_INVOKE_MSG: 106a10cf76eSAxel Dörfler fRefreshSlider->MakeFocus(true); 107a10cf76eSAxel Dörfler break; 108a10cf76eSAxel Dörfler 109a10cf76eSAxel Dörfler default: 110a10cf76eSAxel Dörfler BWindow::MessageReceived(message); 111a10cf76eSAxel Dörfler break; 112a10cf76eSAxel Dörfler } 113a10cf76eSAxel Dörfler } 114