xref: /haiku/src/apps/haikudepot/textview/TextDocumentView.h (revision 46d4471af7fad4e52cfbd09174598cf5318aceed)
1 /*
2  * Copyright 2013-2014, 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 
18 
19 class TextDocumentView : public BView {
20 public:
21 								TextDocumentView(const char* name = NULL);
22 	virtual						~TextDocumentView();
23 
24 	// BView implementation
25 	virtual	void				MessageReceived(BMessage* message);
26 
27 	virtual void				Draw(BRect updateRect);
28 	virtual	void				Pulse();
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				_DrawCaret(int32 textOffset);
79 			void				_DrawSelection();
80 			void				_GetSelectionShape(BShape& shape,
81 									int32 start, int32 end);
82 
83 private:
84 			TextDocumentRef		fTextDocument;
85 			TextDocumentLayout	fTextDocumentLayout;
86 			TextEditorRef		fTextEditor;
87 
88 			float				fInsetLeft;
89 			float				fInsetTop;
90 			float				fInsetRight;
91 			float				fInsetBottom;
92 
93 			BRect				fCaretBounds;
94 			bool				fSelectionEnabled;
95 			bool				fShowCaret;
96 			bool				fMouseDown;
97 };
98 
99 #endif // TEXT_DOCUMENT_VIEW_H
100