2 * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
10 #include <Referenceable.h>
12 #include "CharacterStyle.h"
13 #include "TextDocument.h"
14 #include "TextDocumentLayout.h"
15 #include "TextSelection.h"
27 class TextEditor
: public BReferenceable
{
30 TextEditor(const TextEditor
& other
);
31 virtual ~TextEditor();
33 TextEditor
& operator=(const TextEditor
& other
);
34 bool operator==(const TextEditor
& other
) const;
35 bool operator!=(const TextEditor
& other
) const;
37 void SetDocument(const TextDocumentRef
& ref
);
38 TextDocumentRef
Document() const
42 const TextDocumentLayoutRef
& ref
);
43 TextDocumentLayoutRef
Layout() const
46 void SetEditingEnabled(bool enabled
);
47 inline bool IsEditingEnabled() const
48 { return fEditingEnabled
; }
50 void SetCaret(BPoint location
, bool extendSelection
);
52 void SetSelection(TextSelection selection
);
53 inline TextSelection
Selection() const
54 { return fSelection
; }
56 void SetCharacterStyle(::CharacterStyle style
);
57 ::CharacterStyle
CharacterStyle() const
58 { return fStyleAtCaret
; }
60 virtual void KeyDown(KeyEvent event
);
62 virtual status_t
Insert(int32 offset
, const BString
& string
);
63 virtual status_t
Remove(int32 offset
, int32 length
);
64 virtual status_t
Replace(int32 offset
, int32 length
,
65 const BString
& string
);
67 void LineUp(bool select
);
68 void LineDown(bool select
);
69 void LineStart(bool select
);
70 void LineEnd(bool select
);
72 bool HasSelection() const;
73 int32
SelectionStart() const;
74 int32
SelectionEnd() const;
75 int32
SelectionLength() const;
76 inline int32
CaretOffset() const
77 { return fSelection
.Caret(); }
80 void _MoveToLine(int32 lineIndex
, bool select
);
81 void _SetCaretOffset(int32 offset
,
83 bool lockSelectionAnchor
,
84 bool updateSelectionStyle
);
85 void _SetSelection(int32 caret
, int32 anchor
,
87 bool updateSelectionStyle
);
89 void _UpdateStyleAtCaret();
92 TextDocumentRef fDocument
;
93 TextDocumentLayoutRef fLayout
;
94 TextSelection fSelection
;
96 ::CharacterStyle fStyleAtCaret
;
101 typedef BReference
<TextEditor
> TextEditorRef
;
104 #endif // TEXT_EDITOR_H