xref: /haiku/src/apps/haikudepot/textview/TextDocumentView.h (revision a5a3b2d9a3d95cbae71eaf371708c73a1780ac0d)
1 /*
2  * Copyright 2013-2015, Stephan Aßmus <superstippi@gmx.de>.
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #ifndef TEXT_DOCUMENT_VIEW_H
6 #define TEXT_DOCUMENT_VIEW_H
7 
8 #include <String.h>
9 #include <View.h>
10 
11 #include "TextDocument.h"
12 #include "TextDocumentLayout.h"
13 #include "TextEditor.h"
14 
15 
16 class BClipboard;
17 class BMessageRunner;
18 
19 
20 class TextDocumentView : public BView {
21 public:
22 								TextDocumentView(const char* name = NULL);
23 	virtual						~TextDocumentView();
24 
25 	// BView implementation
26 	virtual	void				MessageReceived(BMessage* message);
27 
28 	virtual void				Draw(BRect updateRect);
29 
30 	virtual	void				AttachedToWindow();
31 	virtual void				FrameResized(float width, float height);
32 	virtual	void				WindowActivated(bool active);
33 	virtual	void				MakeFocus(bool focus = true);
34 
35 	virtual	void				MouseDown(BPoint where);
36 	virtual	void				MouseUp(BPoint where);
37 	virtual	void				MouseMoved(BPoint where, uint32 transit,
38 									const BMessage* dragMessage);
39 
40 	virtual	void				KeyDown(const char* bytes, int32 numBytes);
41 	virtual	void				KeyUp(const char* bytes, int32 numBytes);
42 
43 	virtual	BSize				MinSize();
44 	virtual	BSize				MaxSize();
45 	virtual	BSize				PreferredSize();
46 
47 	virtual	bool				HasHeightForWidth();
48 	virtual	void				GetHeightForWidth(float width, float* min,
49 									float* max, float* preferred);
50 
51 	// TextDocumentView interface
52 			void				SetTextDocument(
53 									const TextDocumentRef& document);
54 
55 			void				SetEditingEnabled(bool enabled);
56 			void				SetTextEditor(
57 									const TextEditorRef& editor);
58 
59 			void				SetInsets(float inset);
60 			void				SetInsets(float horizontal, float vertical);
61 			void				SetInsets(float left, float top, float right,
62 									float bottom);
63 
64 			void				SetSelectionEnabled(bool enabled);
65 			void				SetCaret(BPoint where, bool extendSelection);
66 
67 			void				SelectAll();
68 			bool				HasSelection() const;
69 			void				GetSelection(int32& start, int32& end) const;
70 
71 			void				Copy(BClipboard* clipboard);
72 
73 private:
74 			float				_TextLayoutWidth(float viewWidth) const;
75 
76 			void				_UpdateScrollBars();
77 
78 			void				_ShowCaret(bool show);
79 			void				_BlinkCaret();
80 			void				_DrawCaret(int32 textOffset);
81 			void				_DrawSelection();
82 			void				_GetSelectionShape(BShape& shape,
83 									int32 start, int32 end);
84 
85 private:
86 			TextDocumentRef		fTextDocument;
87 			TextDocumentLayout	fTextDocumentLayout;
88 			TextEditorRef		fTextEditor;
89 
90 			float				fInsetLeft;
91 			float				fInsetTop;
92 			float				fInsetRight;
93 			float				fInsetBottom;
94 
95 			BRect				fCaretBounds;
96 			BMessageRunner*		fCaretBlinker;
97 			int32				fCaretBlinkToken;
98 			bool				fSelectionEnabled;
99 			bool				fShowCaret;
100 			bool				fMouseDown;
101 };
102 
103 #endif // TEXT_DOCUMENT_VIEW_H
104