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 <String.h> 21 #include <StringView.h> 22 #include <Window.h> 23 24 25 RefreshWindow::RefreshWindow(BPoint position, float current, float min, float max) 26 : BWindow(BRect(0, 0, 300, 200), "Refresh Rate", B_MODAL_WINDOW, 27 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS, B_ALL_WORKSPACES) 28 { 29 min = ceilf(min); 30 max = floorf(max); 31 32 BView* topView = new BView(Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW); 33 topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 34 AddChild(topView); 35 36 BRect rect = Bounds().InsetByCopy(8, 8); 37 BStringView* stringView = new BStringView(rect, "info", 38 "Type or use the left and right arrow keys."); 39 stringView->ResizeToPreferred(); 40 topView->AddChild(stringView); 41 42 rect.top += stringView->Bounds().Height() + 14; 43 fRefreshSlider = new RefreshSlider(rect, min, max, B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT); 44 fRefreshSlider->SetValue(rint(current * 10)); 45 fRefreshSlider->SetModificationMessage(new BMessage(SLIDER_MODIFICATION_MSG)); 46 float width, height; 47 fRefreshSlider->GetPreferredSize(&width, &height); 48 fRefreshSlider->ResizeTo(rect.Width(), height); 49 topView->AddChild(fRefreshSlider); 50 51 BButton* doneButton = new BButton(rect, "DoneButton", "Done", 52 new BMessage(BUTTON_DONE_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 53 doneButton->ResizeToPreferred(); 54 doneButton->MoveTo(Bounds().Width() - doneButton->Bounds().Width() - 8, 55 Bounds().Height() - doneButton->Bounds().Height() - 8); 56 topView->AddChild(doneButton); 57 58 BButton* button = new BButton(doneButton->Frame(), "CancelButton", "Cancel", 59 new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); 60 button->ResizeToPreferred(); 61 button->MoveBy(-button->Bounds().Width() - 10, 0); 62 topView->AddChild(button); 63 64 doneButton->MakeDefault(true); 65 66 width = stringView->Bounds().Width() + 100; 67 if (width < Bounds().Width()) 68 width = Bounds().Width(); 69 height = fRefreshSlider->Frame().bottom + button->Bounds().Height() + 20.0f; 70 71 ResizeTo(width, height); 72 MoveTo(position.x - width / 2.5f, position.y - height / 1.9f); 73 } 74 75 76 void 77 RefreshWindow::WindowActivated(bool active) 78 { 79 fRefreshSlider->MakeFocus(active); 80 } 81 82 83 void 84 RefreshWindow::MessageReceived(BMessage* message) 85 { 86 switch (message->what) { 87 case BUTTON_DONE_MSG: 88 { 89 float value = (float)fRefreshSlider->Value() / 10; 90 91 BMessage message(SET_CUSTOM_REFRESH_MSG); 92 message.AddFloat("refresh", value); 93 be_app->PostMessage(&message); 94 95 PostMessage(B_QUIT_REQUESTED); 96 break; 97 } 98 99 case SLIDER_INVOKE_MSG: 100 fRefreshSlider->MakeFocus(true); 101 break; 102 103 default: 104 BWindow::MessageReceived(message); 105 break; 106 } 107 } 108