2 * Copyright 2013-2015, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
5 #ifndef TEXT_DOCUMENT_VIEW_H
6 #define TEXT_DOCUMENT_VIEW_H
11 #include "TextDocument.h"
12 #include "TextDocumentLayout.h"
13 #include "TextEditor.h"
20 class TextDocumentView
: public BView
{
22 TextDocumentView(const char* name
= NULL
);
23 virtual ~TextDocumentView();
25 // BView implementation
26 virtual void MessageReceived(BMessage
* message
);
28 virtual void Draw(BRect updateRect
);
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);
35 virtual void MouseDown(BPoint where
);
36 virtual void MouseUp(BPoint where
);
37 virtual void MouseMoved(BPoint where
, uint32 transit
,
38 const BMessage
* dragMessage
);
40 virtual void KeyDown(const char* bytes
, int32 numBytes
);
41 virtual void KeyUp(const char* bytes
, int32 numBytes
);
43 virtual BSize
MinSize();
44 virtual BSize
MaxSize();
45 virtual BSize
PreferredSize();
47 virtual bool HasHeightForWidth();
48 virtual void GetHeightForWidth(float width
, float* min
,
49 float* max
, float* preferred
);
51 // TextDocumentView interface
53 const TextDocumentRef
& document
);
55 void SetEditingEnabled(bool enabled
);
57 const TextEditorRef
& editor
);
59 void SetInsets(float inset
);
60 void SetInsets(float horizontal
, float vertical
);
61 void SetInsets(float left
, float top
, float right
,
64 void SetSelectionEnabled(bool enabled
);
65 void SetCaret(BPoint where
, bool extendSelection
);
68 bool HasSelection() const;
69 void GetSelection(int32
& start
, int32
& end
) const;
71 void Copy(BClipboard
* clipboard
);
74 float _TextLayoutWidth(float viewWidth
) const;
76 void _UpdateScrollBars();
78 void _ShowCaret(bool show
);
80 void _DrawCaret(int32 textOffset
);
81 void _DrawSelection();
82 void _GetSelectionShape(BShape
& shape
,
83 int32 start
, int32 end
);
86 TextDocumentRef fTextDocument
;
87 TextDocumentLayout fTextDocumentLayout
;
88 TextEditorRef fTextEditor
;
96 BMessageRunner
* fCaretBlinker
;
97 int32 fCaretBlinkToken
;
98 bool fSelectionEnabled
;
103 #endif // TEXT_DOCUMENT_VIEW_H