xref: /haiku/src/apps/terminal/TermScrollView.cpp (revision 2600324b57fa31cdea1627d584d314f2a579c4a8)
1 /*
2  * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 // NOTE: Nasty hack to get access to BScrollView's private parts.
7 #include <ScrollBar.h>
8 #define private	protected
9 #include <ScrollView.h>
10 #undef private
11 
12 #include "TermScrollView.h"
13 
14 #ifndef __HAIKU__
15 #define fVerticalScrollBar fVSB
16 #endif
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 		uint32 resizingMode)
37 	:
38 	BScrollView(name, child, resizingMode, 0, false, true, B_NO_BORDER)
39 {
40 	// replace the vertical scroll bar with our own
41 	if (fVerticalScrollBar != NULL) {
42 		BRect frame(fVerticalScrollBar->Frame());
43 		RemoveChild(fVerticalScrollBar);
44 
45 		// Overlap one pixel at the top and the bottom of the scroll bar with
46 		// the menu respectively resize knob for aesthetical reasons.
47 		frame.top -= 1;
48 		frame.bottom -= B_H_SCROLL_BAR_HEIGHT - 1;
49 
50 		TermScrollBar* scrollBar = new TermScrollBar(frame, "_VSB_", target, 0,
51 			1000, B_VERTICAL);
52 		AddChild(scrollBar);
53 		fVerticalScrollBar = scrollBar;
54 	}
55 }
56 
57 
58 TermScrollView::~TermScrollView()
59 {
60 }
61