xref: /haiku/src/apps/serialconnect/TermView.h (revision 495060760727dd782c9f8a90db71e5d727f19748)
1 /*
2  * Copyright 2012-2019, Adrien Destugues, pulkomandy@pulkomandy.tk
3  * Distributed under the terms of the MIT licence.
4  */
5 
6 
7 #include <String.h>
8 #include <View.h>
9 
10 extern "C" {
11 	#include <vterm.h>
12 }
13 
14 
15 class TermView: public BView
16 {
17 	public:
18 							TermView();
19 							TermView(BRect bounds);
20 							~TermView();
21 
22 				void		AttachedToWindow();
23 				void		Draw(BRect updateRect);
24 				void		FrameResized(float width, float height);
25 				void		GetPreferredSize(float* width, float* height);
26 				void		KeyDown(const char* bytes, int32 numBytes);
27 				void		MessageReceived(BMessage* message);
28 				void		SetLineTerminator(BString bytes);
29 
30 				void		PushBytes(const char* bytes, const size_t length);
31 				void		Clear();
32 
33 	private:
34 				void		_Init();
35 
36 				VTermRect	_PixelsToGlyphs(BRect pixels) const;
37 				BRect		_GlyphsToPixels(const VTermRect& glyphs) const;
38 				BRect		_GlyphsToPixels(const int width, const int height)
39 								const;
40 				void		_GetCell(VTermPos pos, VTermScreenCell& cell);
41 
42 				void		_Damage(VTermRect rect);
43 				void		_MoveCursor(VTermPos pos, VTermPos oldPos,
44 								int visible);
45 				void		_PushLine(int cols, const VTermScreenCell* cells);
46 				int			_PopLine(int cols, VTermScreenCell* cells);
47 				void		_UpdateScrollbar();
48 
49 		static	int			_Damage(VTermRect rect, void* user);
50 		static	int			_MoveCursor(VTermPos pos, VTermPos oldPos,
51 								int visible, void* user);
52 		static	int			_PushLine(int cols, const VTermScreenCell* cells,
53 								void* user);
54 		static	int			_PopLine(int cols, VTermScreenCell* cells,
55 								void* user);
56 
57 	private:
58 		VTerm* fTerm;
59 		VTermScreen* fTermScreen;
60 		BList fScrollBuffer;
61 		int fFontWidth;
62 		int fFontHeight;
63 
64 		BString fLineTerminator;
65 
66 		static const VTermScreenCallbacks sScreenCallbacks;
67 
68 		static const int kDefaultWidth = 80;
69 		static const int kDefaultHeight = 25;
70 		static const int kBorderSpacing = 3;
71 		static const int kScrollBackSize = 10000;
72 };
73