1 /* 2 * Copyright 2001-2009, 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); 86 virtual int32 ValueForPoint(BPoint) const; 87 virtual void SetPosition(float); 88 float Position() const; 89 virtual void SetEnabled(bool on); 90 void GetLimits(int32* minimum, 91 int32* maximum) const; 92 93 virtual void Draw(BRect); 94 virtual void DrawSlider(); 95 virtual void DrawBar(); 96 virtual void DrawHashMarks(); 97 virtual void DrawThumb(); 98 virtual void DrawFocusMark(); 99 virtual void DrawText(); 100 virtual const char* UpdateText() const; 101 void UpdateTextChanged(); 102 103 virtual BRect BarFrame() const; 104 virtual BRect HashMarksFrame() const; 105 virtual BRect ThumbFrame() const; 106 107 virtual void SetFlags(uint32 flags); 108 virtual void SetResizingMode(uint32 mode); 109 110 virtual void GetPreferredSize(float* _width, 111 float* _height); 112 virtual void ResizeToPreferred(); 113 114 virtual status_t Invoke(BMessage* message = NULL); 115 virtual BHandler* ResolveSpecifier(BMessage* message, 116 int32 index, BMessage* specifier, 117 int32 form, const char* property); 118 virtual status_t GetSupportedSuites(BMessage* data); 119 120 virtual void SetModificationMessage(BMessage* message); 121 BMessage* ModificationMessage() const; 122 123 virtual void SetSnoozeAmount(int32); 124 int32 SnoozeAmount() const; 125 126 virtual void SetKeyIncrementValue(int32 value); 127 int32 KeyIncrementValue() const; 128 129 virtual void SetHashMarkCount(int32 count); 130 int32 HashMarkCount() const; 131 132 virtual void SetHashMarks(hash_mark_location where); 133 hash_mark_location HashMarks() const; 134 135 virtual void SetStyle(thumb_style style); 136 thumb_style Style() const; 137 138 virtual void SetBarColor(rgb_color color); 139 rgb_color BarColor() const; 140 virtual void UseFillColor(bool useFill, 141 const rgb_color* color = NULL); 142 bool FillColor(rgb_color* color) const; 143 144 BView* OffscreenView() const; 145 146 orientation Orientation() const; 147 virtual void SetOrientation(orientation); 148 149 float BarThickness() const; 150 virtual void SetBarThickness(float thickness); 151 152 virtual void SetFont(const BFont* font, 153 uint32 properties = B_FONT_ALL); 154 155 virtual void SetLimits(int32 minimum, int32 maximum); 156 157 virtual float MaxUpdateTextWidth(); 158 159 virtual BSize MinSize(); 160 virtual BSize MaxSize(); 161 virtual BSize PreferredSize(); 162 163 protected: 164 virtual void LayoutInvalidated(bool descendants); 165 166 private: 167 void _DrawBlockThumb(); 168 void _DrawTriangleThumb(); 169 170 BPoint _Location() const; 171 void _SetLocationForValue(int32 value); 172 173 float _MinPosition() const; 174 float _MaxPosition() const; 175 bool _ConstrainPoint(BPoint& point, 176 BPoint compare) const; 177 178 BSize _ValidateMinSize(); 179 180 void _InitBarColor(); 181 void _InitObject(); 182 183 private: 184 // FBC padding and forbidden methods 185 virtual void _ReservedSlider6(); 186 virtual void _ReservedSlider7(); 187 virtual void _ReservedSlider8(); 188 virtual void _ReservedSlider9(); 189 virtual void _ReservedSlider10(); 190 virtual void _ReservedSlider11(); 191 virtual void _ReservedSlider12(); 192 193 BSlider& operator=(const BSlider& other); 194 195 private: 196 BMessage* fModificationMessage; 197 int32 fSnoozeAmount; 198 199 rgb_color fBarColor; 200 rgb_color fFillColor; 201 bool fUseFillColor; 202 203 char* fMinLimitLabel; 204 char* fMaxLimitLabel; 205 const char* fUpdateText; 206 207 int32 fMinValue; 208 int32 fMaxValue; 209 int32 fKeyIncrementValue; 210 211 int32 fHashMarkCount; 212 hash_mark_location fHashMarks; 213 214 BBitmap* fOffScreenBits; 215 BView* fOffScreenView; 216 217 thumb_style fStyle; 218 219 BPoint fLocation; 220 BPoint fInitialLocation; 221 222 orientation fOrientation; 223 float fBarThickness; 224 225 BSize fMinSize; 226 227 float fMaxUpdateTextWidth; 228 229 uint32 _reserved[4]; 230 }; 231 232 #endif // _SLIDER_H 233