xref: /haiku/src/apps/icon-o-matic/generic/gui/scrollview/ScrollableView.cpp (revision 21258e2674226d6aa732321b6f8494841895af5f)
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 "ScrollableView.h"
10 
11 #include <View.h>
12 
13 // constructor
14 ScrollableView::ScrollableView()
15 	: Scrollable()
16 {
17 }
18 
19 // destructor
20 ScrollableView::~ScrollableView()
21 {
22 }
23 
24 // ScrollOffsetChanged
25 void
26 ScrollableView::ScrollOffsetChanged(BPoint oldOffset, BPoint newOffset)
27 {
28 	if (BView* view = dynamic_cast<BView*>(this)) {
29 		// We keep it simple: The part of the data rect we shall show now
30 		// has existed before as well (even if partially or completely
31 		// obscured), so we let CopyBits() do the messy details.
32 		BRect bounds(view->Bounds());
33 		view->CopyBits(bounds.OffsetByCopy(newOffset - oldOffset), bounds);
34 		// move our children
35 		for (int32 i = 0; BView* child = view->ChildAt(i); i++)
36 			child->MoveTo(child->Frame().LeftTop() + oldOffset - newOffset);
37 	}
38 }
39 
40