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 SetCaret(BPoint where, bool extendSelection); 65 66 bool HasSelection() const; 67 void GetSelection(int32& start, int32& end) const; 68 69 void Copy(BClipboard* clipboard); 70 71 private: 72 float _TextLayoutWidth(float viewWidth) const; 73 74 void _UpdateScrollBars(); 75 76 void _DrawCaret(int32 textOffset); 77 void _DrawSelection(); 78 void _GetSelectionShape(BShape& shape, 79 int32 start, int32 end); 80 81 private: 82 TextDocumentRef fTextDocument; 83 TextDocumentLayout fTextDocumentLayout; 84 TextEditorRef fTextEditor; 85 86 float fInsetLeft; 87 float fInsetTop; 88 float fInsetRight; 89 float fInsetBottom; 90 91 BRect fCaretBounds; 92 bool fShowCaret; 93 bool fMouseDown; 94 }; 95 96 #endif // TEXT_DOCUMENT_VIEW_H 97