repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / haikudepot / textview / TextEditor.h
blobb26ac3e283adff6e88c089bb04a0fb3af618d64e
1 /*
2 * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5 #ifndef TEXT_EDITOR_H
6 #define TEXT_EDITOR_H
9 #include <Point.h>
10 #include <Referenceable.h>
12 #include "CharacterStyle.h"
13 #include "TextDocument.h"
14 #include "TextDocumentLayout.h"
15 #include "TextSelection.h"
18 class KeyEvent {
19 public:
20 const char* bytes;
21 int32 length;
22 int32 key;
23 int32 modifiers;
27 class TextEditor : public BReferenceable {
28 public:
29 TextEditor();
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
39 { return fDocument; }
41 void SetLayout(
42 const TextDocumentLayoutRef& ref);
43 TextDocumentLayoutRef Layout() const
44 { return fLayout; }
46 void SetEditingEnabled(bool enabled);
47 inline bool IsEditingEnabled() const
48 { return fEditingEnabled; }
50 void SetCaret(BPoint location, bool extendSelection);
51 void SelectAll();
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(); }
79 private:
80 void _MoveToLine(int32 lineIndex, bool select);
81 void _SetCaretOffset(int32 offset,
82 bool updateAnchor,
83 bool lockSelectionAnchor,
84 bool updateSelectionStyle);
85 void _SetSelection(int32 caret, int32 anchor,
86 bool updateAnchor,
87 bool updateSelectionStyle);
89 void _UpdateStyleAtCaret();
91 private:
92 TextDocumentRef fDocument;
93 TextDocumentLayoutRef fLayout;
94 TextSelection fSelection;
95 float fCaretAnchorX;
96 ::CharacterStyle fStyleAtCaret;
97 bool fEditingEnabled;
101 typedef BReference<TextEditor> TextEditorRef;
104 #endif // TEXT_EDITOR_H