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
15class BClipboard;
16
17
18// UndoBuffer
19class BTextView::UndoBuffer {
20public:
21								UndoBuffer(BTextView* view, undo_state state);
22	virtual						~UndoBuffer();
23
24			void				Undo(BClipboard* clipboard);
25			undo_state			State(bool* _isRedo) const;
26
27protected:
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
42private:
43			undo_state			fState;
44};
45
46
47// CutUndoBuffer
48class BTextView::CutUndoBuffer : public BTextView::UndoBuffer {
49public:
50								CutUndoBuffer(BTextView* textView);
51	virtual						~CutUndoBuffer();
52
53protected:
54	virtual	void				RedoSelf(BClipboard* clipboard);
55};
56
57
58// PasteUndoBuffer
59class BTextView::PasteUndoBuffer : public BTextView::UndoBuffer {
60public:
61								PasteUndoBuffer(BTextView* textView,
62									const char* text, int32 textLength,
63									text_run_array* runArray,
64									int32 runArrayLen);
65	virtual						~PasteUndoBuffer();
66
67protected:
68	virtual	void				UndoSelf(BClipboard* clipboard);
69	virtual	void				RedoSelf(BClipboard* clipboard);
70
71private:
72			char*				fPasteText;
73			int32				fPasteTextLength;
74			text_run_array*		fPasteRunArray;
75};
76
77
78// ClearUndoBuffer
79class BTextView::ClearUndoBuffer : public BTextView::UndoBuffer {
80public:
81								ClearUndoBuffer(BTextView* textView);
82	virtual						~ClearUndoBuffer();
83
84protected:
85	virtual	void				RedoSelf(BClipboard* clipboard);
86};
87
88
89// DropUndoBuffer
90class BTextView::DropUndoBuffer : public BTextView::UndoBuffer {
91public:
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
99protected:
100	virtual	void				UndoSelf(BClipboard* clipboard);
101	virtual	void				RedoSelf(BClipboard* clipboard);
102
103private:
104			char*				fDropText;
105			int32				fDropTextLength;
106			text_run_array*		fDropRunArray;
107
108			int32				fDropLocation;
109			bool				fInternalDrop;
110};
111
112
113// TypingUndoBuffer
114class BTextView::TypingUndoBuffer : public BTextView::UndoBuffer {
115public:
116								TypingUndoBuffer(BTextView* textView);
117	virtual						~TypingUndoBuffer();
118
119			void				InputCharacter(int32 length);
120			void				BackwardErase();
121			void				ForwardErase();
122
123protected:
124	virtual	void				RedoSelf(BClipboard* clipboard);
125	virtual	void				UndoSelf(BClipboard* clipboard);
126
127private:
128			void				_Reset();
129
130			char*				fTypedText;
131			int32				fTypedStart;
132			int32				fTypedEnd;
133			int32				fUndone;
134};
135
136#endif //__UNDOBUFFER_H
137