xref: /haiku/src/apps/terminal/TermScrollView.cpp (revision 03187b607b2b5eec7ee059f1ead09bdba14991fb)
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 bottom of the scroll bar with
46 		// the resize knob for aesthetical reasons.
47 		frame.bottom -= B_H_SCROLL_BAR_HEIGHT - 1;
48 
49 		TermScrollBar* scrollBar = new TermScrollBar(frame, "_VSB_", target, 0,
50 			1000, B_VERTICAL);
51 		AddChild(scrollBar);
52 		fVerticalScrollBar = scrollBar;
53 	}
54 }
55 
56 
57 TermScrollView::~TermScrollView()
58 {
59 }
60