1/* 2 * Copyright 2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold <bonefish@cs.tu-berlin.de> 7 */ 8 9#include "Scroller.h" 10 11#include <stdio.h> 12 13#include <Point.h> 14#include <Rect.h> 15 16#include "Scrollable.h" 17 18// constructor 19Scroller::Scroller() 20 : fScrollTarget(NULL), 21 fScrollingEnabled(true) 22{ 23} 24 25// destructor 26Scroller::~Scroller() 27{ 28} 29 30// SetScrollTarget 31// 32// Sets a new scroll target. Notifies the old and the new target 33// of the change if necessary . 34void 35Scroller::SetScrollTarget(Scrollable* target) 36{ 37 Scrollable* oldTarget = fScrollTarget; 38 if (oldTarget != target) { 39 fScrollTarget = NULL; 40 // Notify the old target, if it doesn't know about the change. 41 if (oldTarget && oldTarget->ScrollSource() == this) 42 oldTarget->SetScrollSource(NULL); 43 fScrollTarget = target; 44 // Notify the new target, if it doesn't know about the change. 45 if (target && target->ScrollSource() != this) 46 target->SetScrollSource(this); 47 // Notify ourselves. 48 ScrollTargetChanged(oldTarget, target); 49 } 50} 51 52// ScrollTarget 53// 54// Returns the current scroll target. May be NULL, if we don't have any. 55Scrollable* 56Scroller::ScrollTarget() const 57{ 58 return fScrollTarget; 59} 60 61// SetDataRect 62// 63// Sets the data rect of the scroll target, if we have one. 64void 65Scroller::SetDataRect(BRect dataRect) 66{ 67 if (fScrollTarget) 68 fScrollTarget->SetDataRect(dataRect); 69} 70 71// DataRect 72// 73// Returns the data rect of the scroll target or a undefined value, if 74// we have none. 75BRect 76Scroller::DataRect() const 77{ 78 if (fScrollTarget) 79 return fScrollTarget->DataRect(); 80 return BRect(); 81} 82 83// SetScrollOffset 84// 85// Sets the scroll offset of the scroll target, if we have one. 86void 87Scroller::SetScrollOffset(BPoint offset) 88{ 89 if (fScrollTarget) 90 fScrollTarget->SetScrollOffset(offset); 91} 92 93// ScrollOffset 94// 95// Returns the scroll offset of the scroll target or a undefined value, if 96// we have none. 97BPoint 98Scroller::ScrollOffset() const 99{ 100 if (fScrollTarget) 101 return fScrollTarget->ScrollOffset(); 102 return BPoint(0.0, 0.0); 103} 104 105// SetVisibleSize 106// 107// Sets the visible size of the scroll target, if we have one. 108void 109Scroller::SetVisibleSize(float width, float height) 110{ 111 if (fScrollTarget) 112 fScrollTarget->SetVisibleSize(width, height); 113} 114 115// VisibleBounds 116// 117// Returns the visible bounds of the scroll target or a undefined value, if 118// we have none. 119BRect 120Scroller::VisibleBounds() const 121{ 122 if (fScrollTarget) 123 return fScrollTarget->VisibleBounds(); 124 return BRect(); 125} 126 127// VisibleRect 128// 129// Returns the visible rect of the scroll target or a undefined value, if 130// we have none. 131BRect 132Scroller::VisibleRect() const 133{ 134 if (fScrollTarget) 135 return fScrollTarget->VisibleRect(); 136 return BRect(); 137} 138 139// SetScrollingEnabled 140void 141Scroller::SetScrollingEnabled(bool enabled) 142{ 143 fScrollingEnabled = enabled; 144} 145 146// IsScrolling 147bool 148Scroller::IsScrolling() const 149{ 150 return false; 151} 152 153// hooks 154 155// DataRectChanged 156// 157// Hook function. Implemented by derived classes to get notified when 158// the data rect of the sroll target has changed. 159void 160Scroller::DataRectChanged(BRect /*oldDataRect*/, BRect /*newDataRect*/) 161{ 162} 163 164// ScrollOffsetChanged 165// 166// Hook function. Implemented by derived classes to get notified when 167// the scroll offset of the sroll target has changed. 168void 169Scroller::ScrollOffsetChanged(BPoint /*oldOffset*/, BPoint /*newOffset*/) 170{ 171} 172 173// VisiblSizeChanged 174// 175// Hook function. Implemented by derived classes to get notified when 176// the visible size of the sroll target has changed. 177void 178Scroller::VisibleSizeChanged(float /*oldWidth*/, float /*oldHeight*/, 179 float /*newWidth*/, float /*newHeight*/) 180{ 181} 182 183// ScrollTargetChanged 184// 185// Hook function. Implemented by derived classes to get notified when 186// the sroll target has changed. /target/ may be NULL. 187void 188Scroller::ScrollTargetChanged(Scrollable* /*oldTarget*/, 189 Scrollable* /*newTarget*/) 190{ 191} 192 193