1 /* 2 * Copyright 2001-2013, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _SLIDER_H 6 #define _SLIDER_H 7 8 9 #include <Control.h> 10 11 12 enum hash_mark_location { 13 B_HASH_MARKS_NONE = 0, 14 B_HASH_MARKS_TOP = 1, 15 B_HASH_MARKS_LEFT = 1, 16 B_HASH_MARKS_BOTTOM = 2, 17 B_HASH_MARKS_RIGHT = 2, 18 B_HASH_MARKS_BOTH = 3 19 }; 20 21 enum thumb_style { 22 B_BLOCK_THUMB, 23 B_TRIANGLE_THUMB 24 }; 25 26 27 class BSlider : public BControl { 28 public: 29 BSlider(BRect frame, const char* name, 30 const char* label, BMessage* message, 31 int32 minValue, int32 maxValue, 32 thumb_style thumbType = B_BLOCK_THUMB, 33 uint32 resizingMode 34 = B_FOLLOW_LEFT | B_FOLLOW_TOP, 35 uint32 flags = B_NAVIGABLE | B_WILL_DRAW 36 | B_FRAME_EVENTS); 37 38 BSlider(BRect frame, const char* name, 39 const char* label, BMessage* message, 40 int32 minValue, int32 maxValue, 41 orientation posture, 42 thumb_style thumbType = B_BLOCK_THUMB, 43 uint32 resizingMode 44 = B_FOLLOW_LEFT | B_FOLLOW_TOP, 45 uint32 flags = B_NAVIGABLE | B_WILL_DRAW 46 | B_FRAME_EVENTS); 47 48 BSlider(const char* name, const char* label, 49 BMessage* message, int32 minValue, 50 int32 maxValue, orientation posture, 51 thumb_style thumbType = B_BLOCK_THUMB, 52 uint32 flags = B_NAVIGABLE | B_WILL_DRAW 53 | B_FRAME_EVENTS); 54 55 BSlider(BMessage* archive); 56 virtual ~BSlider(); 57 58 static BArchivable* Instantiate(BMessage* archive); 59 virtual status_t Archive(BMessage* archive, 60 bool deep = true) const; 61 virtual status_t Perform(perform_code code, void* data); 62 63 virtual void WindowActivated(bool state); 64 virtual void AttachedToWindow(); 65 virtual void AllAttached(); 66 virtual void AllDetached(); 67 virtual void DetachedFromWindow(); 68 69 virtual void MessageReceived(BMessage* message); 70 virtual void FrameMoved(BPoint newPosition); 71 virtual void FrameResized(float width, float height); 72 virtual void KeyDown(const char* bytes, int32 numBytes); 73 virtual void KeyUp(const char* bytes, int32 numBytes); 74 virtual void MouseDown(BPoint point); 75 virtual void MouseUp(BPoint point); 76 virtual void MouseMoved(BPoint point, uint32 transit, 77 const BMessage* dragMessage); 78 virtual void Pulse(); 79 80 virtual void SetLabel(const char* label); 81 virtual void SetLimitLabels(const char* minLabel, 82 const char* maxLabel); 83 const char* MinLimitLabel() const; 84 const char* MaxLimitLabel() const; 85 virtual void SetValue(int32 value); 86 virtual int32 ValueForPoint(BPoint point) const; 87 virtual void SetPosition(float); 88 float Position() const; 89 virtual void SetEnabled(bool on); 90 void GetLimits(int32* minimum, int32* maximum) const; 91 92 virtual void Draw(BRect updateRect); 93 virtual void DrawSlider(); 94 virtual void DrawBar(); 95 virtual void DrawHashMarks(); 96 virtual void DrawThumb(); 97 virtual void DrawFocusMark(); 98 virtual void DrawText(); 99 virtual const char* UpdateText() const; 100 void UpdateTextChanged(); 101 102 virtual BRect BarFrame() const; 103 virtual BRect HashMarksFrame() const; 104 virtual BRect ThumbFrame() const; 105 106 virtual void SetFlags(uint32 flags); 107 virtual void SetResizingMode(uint32 mode); 108 109 virtual void GetPreferredSize(float* _width, 110 float* _height); 111 virtual void ResizeToPreferred(); 112 113 virtual status_t Invoke(BMessage* message = NULL); 114 virtual BHandler* ResolveSpecifier(BMessage* message, 115 int32 index, BMessage* specifier, 116 int32 form, const char* property); 117 virtual status_t GetSupportedSuites(BMessage* data); 118 119 virtual void SetModificationMessage(BMessage* message); 120 BMessage* ModificationMessage() const; 121 122 virtual void SetSnoozeAmount(int32 microSeconds); 123 int32 SnoozeAmount() const; 124 125 virtual void SetKeyIncrementValue(int32 value); 126 int32 KeyIncrementValue() const; 127 128 virtual void SetHashMarkCount(int32 count); 129 int32 HashMarkCount() const; 130 131 virtual void SetHashMarks(hash_mark_location where); 132 hash_mark_location HashMarks() const; 133 134 virtual void SetStyle(thumb_style style); 135 thumb_style Style() const; 136 137 virtual void SetBarColor(rgb_color color); 138 rgb_color BarColor() const; 139 virtual void UseFillColor(bool useFill, 140 const rgb_color* color = NULL); 141 bool FillColor(rgb_color* color) const; 142 143 BView* OffscreenView() const; 144 145 orientation Orientation() const; 146 virtual void SetOrientation(orientation); 147 148 float BarThickness() const; 149 virtual void SetBarThickness(float thickness); 150 151 virtual void SetFont(const BFont* font, 152 uint32 properties = B_FONT_ALL); 153 154 virtual void SetLimits(int32 minimum, int32 maximum); 155 156 virtual float MaxUpdateTextWidth(); 157 158 virtual BSize MinSize(); 159 virtual BSize MaxSize(); 160 virtual BSize PreferredSize(); 161 162 protected: 163 virtual void LayoutInvalidated(bool descendants); 164 165 private: 166 void _DrawBlockThumb(); 167 void _DrawTriangleThumb(); 168 169 BPoint _Location() const; 170 void _SetLocationForValue(int32 value); 171 172 float _MinPosition() const; 173 float _MaxPosition() const; 174 bool _ConstrainPoint(BPoint& point, 175 BPoint compare) const; 176 177 BSize _ValidateMinSize(); 178 179 void _InitBarColor(); 180 void _InitObject(); 181 182 private: 183 // FBC padding and forbidden methods 184 virtual void _ReservedSlider6(); 185 virtual void _ReservedSlider7(); 186 virtual void _ReservedSlider8(); 187 virtual void _ReservedSlider9(); 188 virtual void _ReservedSlider10(); 189 virtual void _ReservedSlider11(); 190 virtual void _ReservedSlider12(); 191 192 BSlider& operator=(const BSlider& other); 193 194 private: 195 BMessage* fModificationMessage; 196 int32 fSnoozeAmount; 197 198 rgb_color fBarColor; 199 rgb_color fFillColor; 200 bool fUseFillColor; 201 202 char* fMinLimitLabel; 203 char* fMaxLimitLabel; 204 const char* fUpdateText; 205 206 int32 fMinValue; 207 int32 fMaxValue; 208 int32 fKeyIncrementValue; 209 210 int32 fHashMarkCount; 211 hash_mark_location fHashMarks; 212 213 BBitmap* fOffScreenBits; 214 BView* fOffScreenView; 215 216 thumb_style fStyle; 217 218 BPoint fLocation; 219 BPoint fInitialLocation; 220 221 orientation fOrientation; 222 float fBarThickness; 223 224 BSize fMinSize; 225 226 float fMaxUpdateTextWidth; 227 228 uint32 _reserved[4]; 229 }; 230 231 232 #endif // _SLIDER_H 233