1 /* 2 * Copyright 2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 * Ingo Weinhold <bonefish@cs.tu-berlin.de> 8 */ 9 10 #ifndef POPUP_SLIDER_H 11 #define POPUP_SLIDER_H 12 13 #include <String.h> 14 15 #include "MDividable.h" 16 17 #include "PopupControl.h" 18 19 class MDividable; 20 class SliderView; 21 22 class PopupSlider : public PopupControl, 23 public MDividable { 24 public: 25 PopupSlider(const char* name = NULL, 26 const char* label = NULL, 27 BMessage* model = NULL, 28 BHandler* target = NULL, 29 int32 min = 0, 30 int32 max = 100, 31 int32 value = 0, 32 const char* formatString = "%ld"); 33 virtual ~PopupSlider(); 34 35 // MView 36 virtual minimax layoutprefs(); 37 virtual BRect layout(BRect frame); 38 39 // BHandler 40 virtual void MessageReceived(BMessage* message); 41 42 // BView 43 virtual void AttachedToWindow(); 44 virtual void Draw(BRect updateRect); 45 virtual void MouseDown(BPoint where); 46 47 // PopupControl 48 virtual void PopupShown(); 49 virtual void PopupHidden(bool canceled); 50 51 // PopupSlider 52 void SetValue(int32 value); 53 int32 Value() const; 54 void SetEnabled(bool enabled); 55 bool IsEnabled() const; 56 void TriggerValueChanged(const BMessage* message) const; 57 bool IsTracking() const; 58 // override this to take some action 59 virtual void ValueChanged(int32 newValue); 60 virtual void DrawSlider(BRect frame, bool enabled); 61 virtual float Scale(float ratio) const; 62 virtual float DeScale(float ratio) const; 63 64 void SetMessage(BMessage* message); 65 const BMessage* Message() const 66 { return fModel; } 67 void SetPressedMessage(BMessage* message); 68 void SetReleasedMessage(BMessage* message); 69 70 virtual void SetMin(int32 min); 71 int32 Min() const; 72 73 virtual void SetMax(int32 max); 74 int32 Max() const; 75 76 virtual void SetLabel(const char* label); 77 const char* Label() const; 78 79 // support for MDividable 80 virtual float LabelWidth(); 81 82 // TODO: change design to implement these features: 83 // you can override this function 84 // to have costum value strings 85 virtual const char* StringForValue(int32 value); 86 // but you should override this 87 // as well to make sure the width 88 // of the slider is calculated properly 89 virtual float MaxValueStringWidth(); 90 91 virtual void SetFormatString(const char* formatString); 92 const char* FormatString() const; 93 94 protected: 95 BRect SliderFrame() const 96 { return fSliderButtonRect; } 97 98 99 private: 100 float _MinLabelWidth() const; 101 102 SliderView* fSlider; 103 BMessage* fModel; 104 BMessage* fPressModel; 105 BMessage* fReleaseModel; 106 BHandler* fTarget; 107 BString fLabel; 108 BRect fSliderButtonRect; 109 bool fEnabled; 110 bool fTracking; 111 }; 112 /* 113 class PercentSlider : public PopupSlider { 114 public: 115 116 virtual const char* StringForValue(int32 value); 117 virtual float MaxValueStringWidth(); 118 119 }; 120 */ 121 122 #endif // POPUP_SLIDER_H 123