1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2002, OpenBeOS 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 // 22 // File Name: Slider.h 23 // Author: Marc Flerackers (mflerackers@androme.be) 24 // Description: BSlider creates and displays a sliding thumb control. 25 //------------------------------------------------------------------------------ 26 27 #ifndef _SLIDER_H 28 #define _SLIDER_H 29 30 // Standard Includes ----------------------------------------------------------- 31 32 // System Includes ------------------------------------------------------------- 33 #include <BeBuild.h> 34 #include <Control.h> 35 36 // Project Includes ------------------------------------------------------------ 37 38 // Local Includes -------------------------------------------------------------- 39 40 // Local Defines --------------------------------------------------------------- 41 enum hash_mark_location { 42 B_HASH_MARKS_NONE = 0, 43 B_HASH_MARKS_TOP = 1, 44 B_HASH_MARKS_LEFT = 1, 45 B_HASH_MARKS_BOTTOM = 2, 46 B_HASH_MARKS_RIGHT = 2, 47 B_HASH_MARKS_BOTH = 3 48 }; 49 50 enum thumb_style { 51 B_BLOCK_THUMB, 52 B_TRIANGLE_THUMB 53 }; 54 55 // Globals --------------------------------------------------------------------- 56 57 58 // BSlider class --------------------------------------------------------------- 59 class BSlider : public BControl { 60 public: 61 BSlider(BRect frame, 62 const char *name, 63 const char *label, 64 BMessage *message, 65 int32 minValue, 66 int32 maxValue, 67 thumb_style thumbType = B_BLOCK_THUMB, 68 uint32 resizingMode = B_FOLLOW_LEFT | 69 B_FOLLOW_TOP, 70 uint32 flags = B_NAVIGABLE | B_WILL_DRAW | 71 B_FRAME_EVENTS); 72 BSlider(BRect frame, 73 const char *name, 74 const char *label, 75 BMessage *message, 76 int32 minValue, 77 int32 maxValue, 78 orientation posture /*= B_HORIZONTAL*/, 79 thumb_style thumbType = B_BLOCK_THUMB, 80 uint32 resizingMode = B_FOLLOW_LEFT | 81 B_FOLLOW_TOP, 82 uint32 flags = B_NAVIGABLE | B_WILL_DRAW | 83 B_FRAME_EVENTS); 84 virtual ~BSlider(); 85 86 BSlider(BMessage *data); 87 static BArchivable *Instantiate(BMessage *data); 88 virtual status_t Archive(BMessage *data, bool deep = true) const; 89 virtual status_t Perform(perform_code d, void *arg); 90 91 virtual void WindowActivated(bool state); 92 virtual void AttachedToWindow(); 93 virtual void AllAttached(); 94 virtual void AllDetached(); 95 virtual void DetachedFromWindow(); 96 97 virtual void MessageReceived(BMessage *msg); 98 virtual void FrameMoved(BPoint new_position); 99 virtual void FrameResized(float w,float h); 100 virtual void KeyDown(const char * bytes, int32 n); 101 virtual void MouseDown(BPoint); 102 virtual void MouseUp(BPoint pt); 103 virtual void MouseMoved(BPoint pt, uint32 c, const BMessage *m); 104 virtual void Pulse(); 105 106 virtual void SetLabel(const char *label); 107 virtual void SetLimitLabels(const char *minLabel, 108 const char *maxLabel); 109 const char* MinLimitLabel() const; 110 const char* MaxLimitLabel() const; 111 virtual void SetValue(int32); 112 virtual int32 ValueForPoint(BPoint) const; 113 virtual void SetPosition(float); 114 float Position() const; 115 virtual void SetEnabled(bool on); 116 void GetLimits(int32 * minimum, int32 * maximum); 117 118 virtual void Draw(BRect); 119 virtual void DrawSlider(); 120 virtual void DrawBar(); 121 virtual void DrawHashMarks(); 122 virtual void DrawThumb(); 123 virtual void DrawFocusMark(); 124 virtual void DrawText(); 125 virtual char* UpdateText() const; 126 127 virtual BRect BarFrame() const; 128 virtual BRect HashMarksFrame() const; 129 virtual BRect ThumbFrame() const; 130 131 virtual void SetFlags(uint32 flags); 132 virtual void SetResizingMode(uint32 mode); 133 134 virtual void GetPreferredSize( float *width, float *height); 135 virtual void ResizeToPreferred(); 136 137 virtual status_t Invoke(BMessage *msg=NULL); 138 virtual BHandler *ResolveSpecifier(BMessage *msg, 139 int32 index, 140 BMessage *specifier, 141 int32 form, 142 const char *property); 143 virtual status_t GetSupportedSuites(BMessage *data); 144 145 virtual void SetModificationMessage(BMessage *message); 146 BMessage *ModificationMessage() const; 147 148 virtual void SetSnoozeAmount(int32); 149 int32 SnoozeAmount() const; 150 151 virtual void SetKeyIncrementValue(int32 value); 152 int32 KeyIncrementValue() const; 153 154 virtual void SetHashMarkCount(int32 count); 155 int32 HashMarkCount() const; 156 157 virtual void SetHashMarks(hash_mark_location where); 158 hash_mark_location HashMarks() const; 159 160 virtual void SetStyle(thumb_style s); 161 thumb_style Style() const; 162 163 virtual void SetBarColor(rgb_color); 164 rgb_color BarColor() const; 165 virtual void UseFillColor(bool, const rgb_color* c=NULL); 166 bool FillColor(rgb_color*) const; 167 168 BView* OffscreenView() const; 169 170 orientation Orientation() const; 171 virtual void SetOrientation(orientation); 172 173 float BarThickness() const; 174 virtual void SetBarThickness(float thickness); 175 176 virtual void SetFont(const BFont *font, uint32 properties = B_FONT_ALL); 177 178 #ifdef BEOS_R5_COMPATIBLE 179 virtual void _ReservedSlider4(); 180 #else 181 virtual void SetLimits(int32 minimum, int32 maximum); // Was _ReservedSlider4() 182 #endif 183 /*----- Private or reserved -----------------------------------------*/ 184 private: 185 void _DrawBlockThumb(); 186 void _DrawTriangleThumb(); 187 188 BPoint _Location() const; 189 void _SetLocation(BPoint p); 190 191 float _MinPosition() const; 192 float _MaxPosition() const; 193 194 //virtual void _ReservedSlider1(); 195 //virtual void _ReservedSlider2(); 196 //virtual void _ReservedSlider3(); 197 //virtual void _ReservedSlider4(); 198 virtual void _ReservedSlider5(); 199 virtual void _ReservedSlider6(); 200 virtual void _ReservedSlider7(); 201 virtual void _ReservedSlider8(); 202 virtual void _ReservedSlider9(); 203 virtual void _ReservedSlider10(); 204 virtual void _ReservedSlider11(); 205 virtual void _ReservedSlider12(); 206 207 BSlider &operator=(const BSlider &); 208 209 void _InitObject(); 210 211 BMessage* fModificationMessage; 212 int32 fSnoozeAmount; 213 214 rgb_color fBarColor; 215 rgb_color fFillColor; 216 bool fUseFillColor; 217 218 char* fMinLimitStr; 219 char* fMaxLimitStr; 220 221 int32 fMinValue; 222 int32 fMaxValue; 223 int32 fKeyIncrementValue; 224 225 int32 fHashMarkCount; 226 hash_mark_location fHashMarks; 227 228 BBitmap* fOffScreenBits; 229 BView* fOffScreenView; 230 231 thumb_style fStyle; 232 233 BPoint fLocation; 234 BPoint fInitialLocation; 235 236 orientation fOrientation; 237 float fBarThickness; 238 239 uint32 _reserved[8]; 240 }; 241 //------------------------------------------------------------------------------ 242 243 #endif // _SLIDER_H 244