1 /* 2 * Copyright 2003-2008, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stefano Ceccherini (burton666@libero.it) 7 */ 8 9 #ifndef __UNDOBUFFER_H 10 #define __UNDOBUFFER_H 11 12 #include <TextView.h> 13 14 15 class BClipboard; 16 17 18 // UndoBuffer 19 class BTextView::UndoBuffer { 20 public: 21 UndoBuffer(BTextView* view, undo_state state); 22 virtual ~UndoBuffer(); 23 24 void Undo(BClipboard* clipboard); 25 undo_state State(bool* _isRedo) const; 26 27 protected: 28 virtual void UndoSelf(BClipboard* clipboard); 29 virtual void RedoSelf(BClipboard* clipboard); 30 31 BTextView* fTextView; 32 int32 fStart; 33 int32 fEnd; 34 35 char* fTextData; 36 int32 fTextLength; 37 text_run_array* fRunArray; 38 int32 fRunArrayLength; 39 40 bool fRedo; 41 42 private: 43 undo_state fState; 44 }; 45 46 47 // CutUndoBuffer 48 class BTextView::CutUndoBuffer : public BTextView::UndoBuffer { 49 public: 50 CutUndoBuffer(BTextView* textView); 51 virtual ~CutUndoBuffer(); 52 53 protected: 54 virtual void RedoSelf(BClipboard* clipboard); 55 }; 56 57 58 // PasteUndoBuffer 59 class BTextView::PasteUndoBuffer : public BTextView::UndoBuffer { 60 public: 61 PasteUndoBuffer(BTextView* textView, 62 const char* text, int32 textLength, 63 text_run_array* runArray, 64 int32 runArrayLen); 65 virtual ~PasteUndoBuffer(); 66 67 protected: 68 virtual void UndoSelf(BClipboard* clipboard); 69 virtual void RedoSelf(BClipboard* clipboard); 70 71 private: 72 char* fPasteText; 73 int32 fPasteTextLength; 74 text_run_array* fPasteRunArray; 75 }; 76 77 78 // ClearUndoBuffer 79 class BTextView::ClearUndoBuffer : public BTextView::UndoBuffer { 80 public: 81 ClearUndoBuffer(BTextView* textView); 82 virtual ~ClearUndoBuffer(); 83 84 protected: 85 virtual void RedoSelf(BClipboard* clipboard); 86 }; 87 88 89 // DropUndoBuffer 90 class BTextView::DropUndoBuffer : public BTextView::UndoBuffer { 91 public: 92 DropUndoBuffer(BTextView* textView, 93 char const* text, int32 textLength, 94 text_run_array* runArray, 95 int32 runArrayLength, int32 location, 96 bool internalDrop); 97 virtual ~DropUndoBuffer(); 98 99 protected: 100 virtual void UndoSelf(BClipboard* clipboard); 101 virtual void RedoSelf(BClipboard* clipboard); 102 103 private: 104 char* fDropText; 105 int32 fDropTextLength; 106 text_run_array* fDropRunArray; 107 108 int32 fDropLocation; 109 bool fInternalDrop; 110 }; 111 112 113 // TypingUndoBuffer 114 class BTextView::TypingUndoBuffer : public BTextView::UndoBuffer { 115 public: 116 TypingUndoBuffer(BTextView* textView); 117 virtual ~TypingUndoBuffer(); 118 119 void InputCharacter(int32 length); 120 void BackwardErase(); 121 void ForwardErase(); 122 123 protected: 124 virtual void RedoSelf(BClipboard* clipboard); 125 virtual void UndoSelf(BClipboard* clipboard); 126 127 private: 128 void _Reset(); 129 130 char* fTypedText; 131 int32 fTypedStart; 132 int32 fTypedEnd; 133 int32 fUndone; 134 }; 135 136 #endif //__UNDOBUFFER_H 137