1 /* 2 * Copyright 2004-2009, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT license. 4 */ 5 #ifndef _SCROLL_VIEW_H 6 #define _SCROLL_VIEW_H 7 8 9 #include <ScrollBar.h> 10 11 12 /*! The BScrollView is a convenience class to add a scrolling 13 mechanism to the target view. 14 */ 15 class BScrollView : public BView { 16 public: 17 BScrollView(const char* name, BView* target, 18 uint32 resizingMode 19 = B_FOLLOW_LEFT | B_FOLLOW_TOP, 20 uint32 flags = 0, bool horizontal = false, 21 bool vertical = false, 22 border_style border = B_FANCY_BORDER); 23 BScrollView(const char* name, BView* target, 24 uint32 flags, bool horizontal, 25 bool vertical, border_style border 26 = B_FANCY_BORDER); 27 BScrollView(BMessage* archive); 28 virtual ~BScrollView(); 29 30 static BArchivable* Instantiate(BMessage* archive); 31 virtual status_t Archive(BMessage* archive, 32 bool deep = true) const; 33 34 virtual void AttachedToWindow(); 35 virtual void DetachedFromWindow(); 36 virtual void AllAttached(); 37 virtual void AllDetached(); 38 39 virtual void Draw(BRect updateRect); 40 41 virtual void WindowActivated(bool active); 42 virtual void MakeFocus(bool state = true); 43 44 virtual void GetPreferredSize(float* _width, 45 float* _height); 46 virtual BSize MinSize(); 47 virtual BSize MaxSize(); 48 virtual BSize PreferredSize(); 49 virtual void ResizeToPreferred(); 50 51 virtual void FrameMoved(BPoint position); 52 virtual void FrameResized(float width, float height); 53 54 virtual void MessageReceived(BMessage* message); 55 56 virtual void MouseDown(BPoint point); 57 virtual void MouseUp(BPoint point); 58 virtual void MouseMoved(BPoint point, uint32 code, 59 const BMessage* dragMessage); 60 61 // BScrollView 62 BScrollBar* ScrollBar(orientation posture) const; 63 64 virtual void SetBorder(border_style border); 65 border_style Border() const; 66 67 virtual status_t SetBorderHighlighted(bool state); 68 bool IsBorderHighlighted() const; 69 70 void SetTarget(BView* target); 71 BView* Target() const; 72 73 // Scripting 74 virtual BHandler* ResolveSpecifier(BMessage* message, 75 int32 index, BMessage* specifier, 76 int32 form, const char* property); 77 virtual status_t GetSupportedSuites(BMessage* data); 78 79 virtual status_t Perform(perform_code d, void* arg); 80 81 protected: 82 virtual void LayoutInvalidated(bool descendants = false); 83 virtual void DoLayout(); 84 85 private: 86 // FBC padding and forbidden methods 87 virtual void _ReservedScrollView1(); 88 virtual void _ReservedScrollView2(); 89 virtual void _ReservedScrollView3(); 90 virtual void _ReservedScrollView4(); 91 92 BScrollView& operator=(const BScrollView& other); 93 94 private: 95 friend class BView; 96 97 void _Init(bool horizontal, bool vertical); 98 float _BorderSize() const; 99 BRect _InnerFrame() const; 100 BSize _ComputeSize(BSize targetSize) const; 101 BRect _ComputeFrame(BRect targetRect) const; 102 void _AlignScrollBars(bool horizontal, 103 bool vertical, BRect targetFrame); 104 105 static BRect _ComputeFrame(BRect frame, bool horizontal, 106 bool vertical, border_style border); 107 static BRect _ComputeFrame(BView* target, bool horizontal, 108 bool vertical, border_style border); 109 static float _BorderSize(border_style border); 110 static int32 _ModifyFlags(int32 flags, border_style border); 111 112 private: 113 BView* fTarget; 114 BScrollBar* fHorizontalScrollBar; 115 BScrollBar* fVerticalScrollBar; 116 border_style fBorder; 117 uint16 fPreviousWidth; 118 uint16 fPreviousHeight; 119 bool fHighlighted; 120 121 uint32 _reserved[3]; 122 }; 123 124 #endif // _SCROLL_VIEW_H 125