xref: /haiku/src/apps/serialconnect/TermView.h (revision 3a6bc1cf655f552194bae298fadfdde896dad690)
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		MouseDown(BPoint where);
28 				void		MessageReceived(BMessage* message);
29 				void		SetLineTerminator(BString bytes);
30 
31 				void		PushBytes(const char* bytes, const size_t length);
32 				void		Clear();
33 				void		PasteFromClipboard();
34 
35 	private:
36 				void		_Init();
37 
38 				VTermRect	_PixelsToGlyphs(BRect pixels) const;
39 				BRect		_GlyphsToPixels(const VTermRect& glyphs) const;
40 				BRect		_GlyphsToPixels(const int width, const int height)
41 								const;
42 				void		_GetCell(VTermPos pos, VTermScreenCell& cell);
43 
44 				void		_Damage(VTermRect rect);
45 				void		_MoveCursor(VTermPos pos, VTermPos oldPos,
46 								int visible);
47 				void		_PushLine(int cols, const VTermScreenCell* cells);
48 				int			_PopLine(int cols, VTermScreenCell* cells);
49 				void		_UpdateScrollbar();
50 
51 		static	int			_Damage(VTermRect rect, void* user);
52 		static	int			_MoveCursor(VTermPos pos, VTermPos oldPos,
53 								int visible, void* user);
54 		static	int			_PushLine(int cols, const VTermScreenCell* cells,
55 								void* user);
56 		static	int			_PopLine(int cols, VTermScreenCell* cells,
57 								void* user);
58 
59 	private:
60 		VTerm* fTerm;
61 		VTermScreen* fTermScreen;
62 		BList fScrollBuffer;
63 		int fFontWidth;
64 		int fFontHeight;
65 
66 		BString fLineTerminator;
67 
68 		static const VTermScreenCallbacks sScreenCallbacks;
69 
70 		static const int kDefaultWidth = 80;
71 		static const int kDefaultHeight = 25;
72 		static const int kBorderSpacing = 3;
73 		static const int kScrollBackSize = 10000;
74 };
75