xref: /haiku/src/apps/terminal/TermScrollView.cpp (revision 746cac055adc6ac3308c7bc2d29040fb95689cc9)
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 
15 class TermScrollBar : public BScrollBar {
16 public:
17 	TermScrollBar(BRect frame, const char *name, BView *target,
18 			float min, float max, orientation direction)
19 		:
20 		BScrollBar(frame, name, target, min, max, direction)
21 	{
22 	}
23 
24 	virtual void ValueChanged(float newValue)
25 	{
26 		if (BView* target = Target())
27 			target->ScrollTo(0, newValue);
28 	}
29 };
30 
31 
32 TermScrollView::TermScrollView(const char* name, BView* child, BView* target,
33 		uint32 resizingMode)
34 	:
35 	BScrollView(name, child, resizingMode, 0, false, true, B_NO_BORDER)
36 {
37 	// replace the vertical scroll bar with our own
38 	if (fVerticalScrollBar != NULL) {
39 		BRect frame(fVerticalScrollBar->Frame());
40 		RemoveChild(fVerticalScrollBar);
41 
42 		// Overlap one pixel at the top and the bottom of the scroll bar with
43 		// the menu respectively resize knob for aesthetical reasons.
44 		frame.top -= 1;
45 		frame.bottom -= B_H_SCROLL_BAR_HEIGHT - 1;
46 
47 		TermScrollBar* scrollBar = new TermScrollBar(frame, "_VSB_", target, 0,
48 			1000, B_VERTICAL);
49 		AddChild(scrollBar);
50 		fVerticalScrollBar = scrollBar;
51 	}
52 }
53 
54 
55 TermScrollView::~TermScrollView()
56 {
57 }
58