1 /* 2 * Copyright 2001-2009, Ingo Weinhold <ingo_weinhold@gmx.de> 3 * All rights reserved. Distributed under the terms of the MIT license. 4 */ 5 #ifndef SCROLLABLE_H 6 #define SCROLLABLE_H 7 8 #include <Point.h> 9 #include <Rect.h> 10 11 class Scroller; 12 13 class Scrollable { 14 public: 15 Scrollable(); 16 virtual ~Scrollable(); 17 18 void SetScrollSource(Scroller* source); 19 Scroller* ScrollSource() const; 20 21 void SetDataRect(BRect dataRect, 22 bool validateScrollOffset = true); 23 BRect DataRect() const; 24 25 virtual void SetScrollOffset(BPoint offset); 26 BPoint ScrollOffset() const; 27 28 void SetDataRectAndScrollOffset(BRect dataRect, 29 BPoint offset); 30 31 BPoint ValidScrollOffsetFor(BPoint offset) const; 32 BPoint ValidScrollOffsetFor(BPoint offset, 33 const BRect& dataRect) const; 34 35 void SetVisibleSize(float width, float height); 36 BRect VisibleBounds() const; 37 BRect VisibleRect() const; 38 39 protected: 40 virtual void DataRectChanged(BRect oldDataRect, 41 BRect newDataRect); 42 virtual void ScrollOffsetChanged(BPoint oldOffset, 43 BPoint newOffset); 44 virtual void VisibleSizeChanged(float oldWidth, 45 float oldHeight, 46 float newWidth, 47 float newHeight); 48 virtual void ScrollSourceChanged(Scroller* oldSource, 49 Scroller* newSource); 50 51 private: 52 BRect fDataRect; 53 BPoint fScrollOffset; 54 float fVisibleWidth; 55 float fVisibleHeight; 56 Scroller* fScrollSource; 57 }; 58 59 60 #endif // SCROLLABLE_H 61 62