1 /* 2 * Copyright 2001-2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Rafael Romo 7 * Stefano Ceccherini (burton666@libero.it) 8 * Axel Dörfler, axeld@pinc-software.de 9 */ 10 11 12 #include "RefreshWindow.h" 13 14 #include "Constants.h" 15 #include "RefreshSlider.h" 16 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> 24 25 26 #undef B_TRANSLATION_CONTEXT 27 #define B_TRANSLATION_CONTEXT "Screen" 28 29 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) 33 { 34 min = ceilf(min); 35 max = floorf(max); 36 37 BView* topView = new BView(Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW); 38 topView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); 39 topView->SetHighUIColor(B_PANEL_TEXT_COLOR); 40 AddChild(topView); 41 42 BRect rect = Bounds().InsetByCopy(8, 8); 43 BStringView* stringView = new BStringView(rect, "info", 44 B_TRANSLATE("Type or use the left and right arrow keys.")); 45 stringView->ResizeToPreferred(); 46 topView->AddChild(stringView); 47 48 rect.top += stringView->Bounds().Height() + 14; 49 fRefreshSlider = new RefreshSlider(rect, min, max, B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT); 50 fRefreshSlider->SetValue((int32)rintf(current * 10)); 51 fRefreshSlider->SetModificationMessage(new BMessage(SLIDER_MODIFICATION_MSG)); 52 float width, height; 53 fRefreshSlider->GetPreferredSize(&width, &height); 54 fRefreshSlider->ResizeTo(rect.Width(), height); 55 topView->AddChild(fRefreshSlider); 56 57 BButton* doneButton = new BButton(rect, "DoneButton", B_TRANSLATE("Done"), 58 new BMessage(BUTTON_DONE_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 59 doneButton->ResizeToPreferred(); 60 doneButton->MoveTo(Bounds().Width() - doneButton->Bounds().Width() - 8, 61 Bounds().Height() - doneButton->Bounds().Height() - 8); 62 topView->AddChild(doneButton); 63 64 BButton* button = new BButton(doneButton->Frame(), "CancelButton", 65 B_TRANSLATE("Cancel"), new BMessage(B_QUIT_REQUESTED), 66 B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 67 button->ResizeToPreferred(); 68 button->MoveBy(-button->Bounds().Width() - 10, 0); 69 topView->AddChild(button); 70 71 doneButton->MakeDefault(true); 72 73 width = stringView->Bounds().Width() + 100; 74 if (width < Bounds().Width()) 75 width = Bounds().Width(); 76 height = fRefreshSlider->Frame().bottom + button->Bounds().Height() + 20.0f; 77 78 ResizeTo(width, height); 79 MoveTo(position.x - width / 2.5f, position.y - height / 1.9f); 80 } 81 82 83 void 84 RefreshWindow::WindowActivated(bool active) 85 { 86 fRefreshSlider->MakeFocus(active); 87 } 88 89 90 void 91 RefreshWindow::MessageReceived(BMessage* message) 92 { 93 switch (message->what) { 94 case BUTTON_DONE_MSG: 95 { 96 float value = (float)fRefreshSlider->Value() / 10; 97 98 BMessage message(SET_CUSTOM_REFRESH_MSG); 99 message.AddFloat("refresh", value); 100 be_app->PostMessage(&message); 101 102 PostMessage(B_QUIT_REQUESTED); 103 break; 104 } 105 106 case SLIDER_INVOKE_MSG: 107 fRefreshSlider->MakeFocus(true); 108 break; 109 110 default: 111 BWindow::MessageReceived(message); 112 break; 113 } 114 } 115