1 /* 2 * Copyright 2001-2008, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _SCROLL_BAR_H 6 #define _SCROLL_BAR_H 7 8 9 #include <View.h> 10 11 12 #define B_V_SCROLL_BAR_WIDTH 14.0f 13 #define B_H_SCROLL_BAR_HEIGHT 14.0f 14 15 // TODO: shouldn't these be moved into the implementation? 16 #define SCROLL_BAR_MAXIMUM_KNOB_SIZE 50 17 #define SCROLL_BAR_MINIMUM_KNOB_SIZE 9 18 19 #define DISABLES_ON_WINDOW_DEACTIVATION 1 20 21 22 class BScrollBar : public BView { 23 public: 24 BScrollBar(BRect frame, const char* name, 25 BView* target, float min, float max, 26 orientation direction); 27 BScrollBar(const char* name, BView* target, 28 float min, float max, 29 orientation orientation); 30 BScrollBar(BMessage* archive); 31 virtual ~BScrollBar(); 32 static BArchivable* Instantiate(BMessage* archive); 33 virtual status_t Archive(BMessage* archive, 34 bool deep = true) const; 35 36 virtual void AllAttached(); 37 virtual void AllDetached(); 38 39 virtual void AttachedToWindow(); 40 virtual void DetachedFromWindow(); 41 42 virtual void Draw(BRect updateRect); 43 virtual void FrameMoved(BPoint new_position); 44 virtual void FrameResized(float newWidth, float newHeight); 45 46 virtual void MessageReceived(BMessage* message); 47 48 virtual void MouseDown(BPoint where); 49 virtual void MouseUp(BPoint where); 50 virtual void MouseMoved(BPoint where, uint32 code, 51 const BMessage* dragMessage); 52 53 #if DISABLES_ON_WINDOW_DEACTIVATION 54 virtual void WindowActivated(bool active); 55 #endif 56 57 void SetValue(float value); 58 float Value() const; 59 60 void SetProportion(float); 61 float Proportion() const; 62 63 virtual void ValueChanged(float newValue); 64 65 void SetRange(float min, float max); 66 void GetRange(float* _min, float* _max) const; 67 void SetSteps(float smallStep, float largeStep); 68 void GetSteps(float* _smallStep, 69 float* _largeStep) const; 70 71 void SetTarget(BView *target); 72 void SetTarget(const char* targetName); 73 BView* Target() const; 74 75 void SetOrientation(orientation direction); 76 orientation Orientation() const; 77 78 // TODO: Make this a virtual method, it should be one, 79 // but it's not important right now. This is supposed 80 // to be used in case the BScrollBar should draw part of 81 // the focus indication of the target view for aesthetical 82 // reasons. BScrollView will forward this method. 83 status_t SetBorderHighlighted(bool highlight); 84 85 virtual void GetPreferredSize(float* _width, 86 float* _height); 87 virtual void ResizeToPreferred(); 88 virtual void MakeFocus(bool focus = true); 89 90 virtual BSize MinSize(); 91 virtual BSize MaxSize(); 92 virtual BSize PreferredSize(); 93 94 virtual status_t GetSupportedSuites(BMessage* message); 95 virtual BHandler* ResolveSpecifier(BMessage* message, 96 int32 index, BMessage* specifier, 97 int32 what, const char* property); 98 99 virtual status_t Perform(perform_code d, void* arg); 100 101 private: 102 class Private; 103 friend class Private; 104 105 friend status_t control_scrollbar(scroll_bar_info* info, 106 BScrollBar *bar); 107 // for use within the preflet 108 109 virtual void _ReservedScrollBar1(); 110 virtual void _ReservedScrollBar2(); 111 virtual void _ReservedScrollBar3(); 112 virtual void _ReservedScrollBar4(); 113 114 // disabled 115 BScrollBar& operator=(const BScrollBar& other); 116 117 bool _DoubleArrows() const; 118 void _UpdateThumbFrame(); 119 float _ValueFor(BPoint where) const; 120 int32 _ButtonFor(BPoint where) const; 121 BRect _ButtonRectFor(int32 button) const; 122 void _UpdateTargetValue(BPoint where); 123 void _UpdateArrowButtons(); 124 void _DrawDisabledBackground(BRect area, 125 const rgb_color& light, 126 const rgb_color& dark, 127 const rgb_color& fill); 128 void _DrawArrowButton(int32 direction, 129 bool doubleArrows, BRect frame, 130 const BRect& updateRect, 131 bool enabled, bool down); 132 133 BSize _MinSize() const; 134 135 private: 136 float fMin; 137 float fMax; 138 float fSmallStep; 139 float fLargeStep; 140 float fValue; 141 float fProportion; 142 BView* fTarget; 143 orientation fOrientation; 144 145 Private* fPrivateData; 146 147 uint32 _reserved[4]; 148 }; 149 150 #endif // _SCROLL_BAR_H 151