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 MouseDown(BPoint point); 74 virtual void MouseUp(BPoint point); 75 virtual void MouseMoved(BPoint point, uint32 transit, 76 const BMessage* dragMessage); 77 virtual void Pulse(); 78 79 virtual void SetLabel(const char* label); 80 virtual void SetLimitLabels(const char* minLabel, 81 const char* maxLabel); 82 const char* MinLimitLabel() const; 83 const char* MaxLimitLabel() const; 84 virtual void SetValue(int32); 85 virtual int32 ValueForPoint(BPoint) const; 86 virtual void SetPosition(float); 87 float Position() const; 88 virtual void SetEnabled(bool on); 89 void GetLimits(int32* minimum, 90 int32* maximum) const; 91 92 virtual void Draw(BRect); 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); 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 void InvalidateLayout(bool descendants = false); 159 160 virtual BSize MinSize(); 161 virtual BSize MaxSize(); 162 virtual BSize PreferredSize(); 163 164 private: 165 void _DrawBlockThumb(); 166 void _DrawTriangleThumb(); 167 168 BPoint _Location() const; 169 void _SetLocation(BPoint point); 170 171 float _MinPosition() const; 172 float _MaxPosition() const; 173 bool _ConstrainPoint(BPoint& point, 174 BPoint compare) const; 175 176 BSize _ValidateMinSize(); 177 178 void _InitBarColor(); 179 void _InitObject(); 180 181 private: 182 // FBC padding and forbidden methods 183 virtual void _ReservedSlider6(); 184 virtual void _ReservedSlider7(); 185 virtual void _ReservedSlider8(); 186 virtual void _ReservedSlider9(); 187 virtual void _ReservedSlider10(); 188 virtual void _ReservedSlider11(); 189 virtual void _ReservedSlider12(); 190 191 BSlider& operator=(const BSlider& other); 192 193 private: 194 BMessage* fModificationMessage; 195 int32 fSnoozeAmount; 196 197 rgb_color fBarColor; 198 rgb_color fFillColor; 199 bool fUseFillColor; 200 201 char* fMinLimitLabel; 202 char* fMaxLimitLabel; 203 const char* fUpdateText; 204 205 int32 fMinValue; 206 int32 fMaxValue; 207 int32 fKeyIncrementValue; 208 209 int32 fHashMarkCount; 210 hash_mark_location fHashMarks; 211 212 BBitmap* fOffScreenBits; 213 BView* fOffScreenView; 214 215 thumb_style fStyle; 216 217 BPoint fLocation; 218 BPoint fInitialLocation; 219 220 orientation fOrientation; 221 float fBarThickness; 222 223 BSize fMinSize; 224 225 float fMaxUpdateTextWidth; 226 227 uint32 _reserved[4]; 228 }; 229 230 #endif // _SLIDER_H 231