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 AttachedToWindow(); 37 void SetValue(float value); 38 float Value() const; 39 void SetProportion(float); 40 float Proportion() const; 41 virtual void ValueChanged(float newValue); 42 43 void SetRange(float min, float max); 44 void GetRange(float* _min, float* _max) const; 45 void SetSteps(float smallStep, float largeStep); 46 void GetSteps(float* _smallStep, 47 float* _largeStep) const; 48 void SetTarget(BView *target); 49 void SetTarget(const char* targetName); 50 BView* Target() const; 51 void SetOrientation(orientation orientation); 52 orientation Orientation() const; 53 54 // TODO: Make this a virtual method, it should be one, 55 // but it's not important right now. This is supposed 56 // to be used in case the BScrollBar should draw part of 57 // the focus indication of the target view for aesthetical 58 // reasons. BScrollView will forward this method. 59 status_t SetBorderHighlighted(bool state); 60 61 virtual void MessageReceived(BMessage* message); 62 virtual void MouseDown(BPoint pt); 63 virtual void MouseUp(BPoint pt); 64 virtual void MouseMoved(BPoint pt, uint32 code, 65 const BMessage* dragMessage); 66 virtual void DetachedFromWindow(); 67 virtual void Draw(BRect updateRect); 68 virtual void FrameMoved(BPoint new_position); 69 virtual void FrameResized(float newWidth, float newHeight); 70 71 virtual BHandler* ResolveSpecifier(BMessage* message, 72 int32 index, BMessage* specifier, 73 int32 form, const char* property); 74 75 virtual void ResizeToPreferred(); 76 virtual void GetPreferredSize(float* _width, 77 float* _height); 78 virtual void MakeFocus(bool state = true); 79 virtual void AllAttached(); 80 virtual void AllDetached(); 81 virtual status_t GetSupportedSuites(BMessage* data); 82 83 virtual BSize MinSize(); 84 virtual BSize MaxSize(); 85 virtual BSize PreferredSize(); 86 87 virtual status_t Perform(perform_code d, void* arg); 88 89 #if DISABLES_ON_WINDOW_DEACTIVATION 90 virtual void WindowActivated(bool active); 91 #endif 92 93 private: 94 class Private; 95 friend class Private; 96 97 friend status_t control_scrollbar(scroll_bar_info* info, 98 BScrollBar *bar); 99 // for use within the preflet 100 101 virtual void _ReservedScrollBar1(); 102 virtual void _ReservedScrollBar2(); 103 virtual void _ReservedScrollBar3(); 104 virtual void _ReservedScrollBar4(); 105 106 // disabled 107 BScrollBar& operator=(const BScrollBar& other); 108 109 bool _DoubleArrows() const; 110 void _UpdateThumbFrame(); 111 float _ValueFor(BPoint where) const; 112 int32 _ButtonFor(BPoint where) const; 113 BRect _ButtonRectFor(int32 button) const; 114 void _UpdateTargetValue(BPoint where); 115 void _UpdateArrowButtons(); 116 void _DrawDisabledBackground(BRect area, 117 const rgb_color& light, 118 const rgb_color& dark, 119 const rgb_color& fill); 120 void _DrawArrowButton(int32 direction, 121 bool doubleArrows, BRect frame, 122 const BRect& updateRect, 123 bool enabled, bool down); 124 125 BSize _MinSize() const; 126 127 private: 128 float fMin; 129 float fMax; 130 float fSmallStep; 131 float fLargeStep; 132 float fValue; 133 float fProportion; 134 BView* fTarget; 135 orientation fOrientation; 136 char* fTargetName; 137 138 Private* fPrivateData; 139 140 uint32 _reserved[3]; 141 }; 142 143 #endif // _SCROLL_BAR_H 144