xref: /haiku/src/apps/terminal/TermScrollView.cpp (revision 1c09002cbee8e797a0f8bbfc5678dfadd39ee1a7)
1 /*
2  * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 // NOTE: Nasty hack to get access to BScrollView's private parts.
8 #include <ScrollBar.h>
9 #define private	protected
10 #include <ScrollView.h>
11 #undef private
12 
13 #include "TermScrollView.h"
14 
15 #include <Message.h>
16 
17 
18 class TermScrollBar : public BScrollBar {
19 public:
20 	TermScrollBar(BRect frame, const char *name, BView *target,
21 			float min, float max, orientation direction)
22 		:
23 		BScrollBar(frame, name, target, min, max, direction)
24 	{
25 	}
26 
27 	virtual void ValueChanged(float newValue)
28 	{
29 		if (BView* target = Target())
30 			target->ScrollTo(0, newValue);
31 	}
32 };
33 
34 
35 TermScrollView::TermScrollView(const char* name, BView* child, BView* target,
36 		bool overlapTop, uint32 resizingMode)
37 	:
38 	BScrollView(name, child, resizingMode, 0, false, true, B_NO_BORDER)
39 {
40 	child->TargetedByScrollView(NULL);
41 
42 	// replace the vertical scroll bar with our own
43 	if (fVerticalScrollBar != NULL) {
44 		BRect frame(fVerticalScrollBar->Frame());
45 		RemoveChild(fVerticalScrollBar);
46 		delete fVerticalScrollBar;
47 
48 		// Overlap one pixel at the top (if required) with the menu for
49 		// aesthetical reasons.
50 		if (overlapTop)
51 			frame.top--;
52 
53 		TermScrollBar* scrollBar = new TermScrollBar(frame, "_VSB_", target, 0,
54 			1000, B_VERTICAL);
55 		AddChild(scrollBar);
56 		fVerticalScrollBar = scrollBar;
57 	}
58 
59 	target->TargetedByScrollView(this);
60 }
61 
62 
63 TermScrollView::~TermScrollView()
64 {
65 }
66