vfs: check userland buffers before reading them.
[haiku.git] / src / apps / haikudepot / textview / TextDocumentView.h
blobc5b8c705a49b882e2b1393192462d2a81fd18b74
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
8 #include <String.h>
9 #include <View.h>
11 #include "TextDocument.h"
12 #include "TextDocumentLayout.h"
13 #include "TextEditor.h"
16 class BClipboard;
17 class BMessageRunner;
20 class TextDocumentView : public BView {
21 public:
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
52 void SetTextDocument(
53 const TextDocumentRef& document);
55 void SetEditingEnabled(bool enabled);
56 void SetTextEditor(
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,
62 float bottom);
64 void SetSelectionEnabled(bool enabled);
65 void SetCaret(BPoint where, bool extendSelection);
67 void SelectAll();
68 bool HasSelection() const;
69 void GetSelection(int32& start, int32& end) const;
71 void Copy(BClipboard* clipboard);
73 private:
74 float _TextLayoutWidth(float viewWidth) const;
76 void _UpdateScrollBars();
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);
85 private:
86 TextDocumentRef fTextDocument;
87 TextDocumentLayout fTextDocumentLayout;
88 TextEditorRef fTextEditor;
90 float fInsetLeft;
91 float fInsetTop;
92 float fInsetRight;
93 float fInsetBottom;
95 BRect fCaretBounds;
96 BMessageRunner* fCaretBlinker;
97 int32 fCaretBlinkToken;
98 bool fSelectionEnabled;
99 bool fShowCaret;
100 bool fMouseDown;
103 #endif // TEXT_DOCUMENT_VIEW_H