1 #include <Alert.h> 2 #include <Application.h> 3 #include <Button.h> 4 #include <String.h> 5 #include <Window.h> 6 7 #include "RefreshWindow.h" 8 #include "RefreshView.h" 9 #include "RefreshSlider.h" 10 #include "Constants.h" 11 12 RefreshWindow::RefreshWindow(BRect frame, int32 value) 13 : BWindow(frame, "Refresh Rate", B_MODAL_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_ALL_WORKSPACES) 14 { 15 BRect bounds(Bounds()); 16 bounds.InsetBy(-1, -1); 17 18 fRefreshView = new RefreshView(bounds, "RefreshView"); 19 AddChild(fRefreshView); 20 21 BRect sliderRect; 22 BString maxRefresh; 23 maxRefresh << gMaxRefresh; 24 BString minRefresh; 25 minRefresh << gMinRefresh; 26 27 sliderRect.Set(10.0, 35.0, 299.0, 60.0); 28 29 fRefreshSlider = new RefreshSlider(sliderRect); 30 31 fRefreshSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); 32 fRefreshSlider->SetHashMarkCount((gMaxRefresh-gMinRefresh)/5+1); 33 fRefreshSlider->SetLimitLabels(minRefresh.String(), maxRefresh.String()); 34 fRefreshSlider->SetKeyIncrementValue(1); 35 fRefreshSlider->SetValue(value); 36 fRefreshSlider->SetSnoozeAmount(1); 37 fRefreshSlider->SetModificationMessage(new BMessage(SLIDER_MODIFICATION_MSG)); 38 39 fRefreshView->AddChild(fRefreshSlider); 40 41 BRect ButtonRect(219.0, 97.0, 230.0, 120.0); 42 43 fDoneButton = new BButton(ButtonRect, "DoneButton", "Done", 44 new BMessage(BUTTON_DONE_MSG)); 45 46 fDoneButton->ResizeToPreferred(); 47 fDoneButton->MakeDefault(true); 48 49 fRefreshView->AddChild(fDoneButton); 50 51 ButtonRect.Set(130.0, 97.0, 200.0, 120.0); 52 53 fCancelButton = new BButton(ButtonRect, "CancelButton", "Cancel", 54 new BMessage(BUTTON_CANCEL_MSG)); 55 56 fCancelButton->ResizeToPreferred(); 57 58 fRefreshView->AddChild(fCancelButton); 59 } 60 61 62 void 63 RefreshWindow::WindowActivated(bool active) 64 { 65 fRefreshSlider->MakeFocus(active); 66 } 67 68 69 void 70 RefreshWindow::MessageReceived(BMessage* message) 71 { 72 switch(message->what) 73 { 74 case BUTTON_DONE_MSG: 75 { 76 BMessage message(SET_CUSTOM_REFRESH_MSG); 77 78 float value = (float)fRefreshSlider->Value() / 10; 79 80 message.AddFloat("refresh", value); 81 be_app->PostMessage(&message); 82 83 PostMessage(B_QUIT_REQUESTED); 84 85 break; 86 } 87 88 case BUTTON_CANCEL_MSG: 89 { 90 PostMessage(B_QUIT_REQUESTED); 91 92 break; 93 } 94 95 case SLIDER_INVOKE_MSG: 96 { 97 fRefreshSlider->MakeFocus(true); 98 99 break; 100 } 101 102 default: 103 BWindow::MessageReceived(message); 104 break; 105 } 106 } 107