xref: /haiku/src/kits/interface/textview_support/UndoBuffer.h (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
1 /*
2  * Copyright 2003-2007, 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 class _BUndoBuffer_ {
18 public:
19 	_BUndoBuffer_(BTextView *, undo_state);
20 	virtual ~_BUndoBuffer_();
21 
22 	void Undo(BClipboard *);
23 	undo_state State(bool *);
24 
25 protected:
26 	virtual void UndoSelf(BClipboard *);
27 	virtual void RedoSelf(BClipboard *);
28 
29 	BTextView *fTextView;
30 	int32 fStart;
31 	int32 fEnd;
32 
33 	char *fTextData;
34 	int32 fTextLength;
35 	text_run_array *fRunArray;
36 	int32 fRunArrayLength;
37 
38 	bool fRedo;
39 
40 private:
41 	undo_state fState;
42 };
43 
44 
45 //  ******** _BCutUndoBuffer_ *******
46 class _BCutUndoBuffer_ : public _BUndoBuffer_ {
47 public:
48 	_BCutUndoBuffer_(BTextView *textView);
49 	~_BCutUndoBuffer_();
50 
51 protected:
52 	virtual void RedoSelf(BClipboard *);
53 };
54 
55 
56 //  ******** _BPasteUndoBuffer_ *******
57 class _BPasteUndoBuffer_ : public _BUndoBuffer_ {
58 public:
59 	_BPasteUndoBuffer_(BTextView *, const char *, int32, text_run_array *, int32);
60 	~_BPasteUndoBuffer_();
61 
62 protected:
63 	virtual void UndoSelf(BClipboard *);
64 	virtual void RedoSelf(BClipboard *);
65 
66 private:
67 	char *fPasteText;
68 	int32 fPasteTextLength;
69 	text_run_array *fPasteRunArray;
70 };
71 
72 
73 //  ******** _BClearUndoBuffer_ *******
74 class _BClearUndoBuffer_ : public _BUndoBuffer_ {
75 public:
76 	_BClearUndoBuffer_(BTextView *textView);
77 	~_BClearUndoBuffer_();
78 
79 protected:
80 	virtual void RedoSelf(BClipboard *);
81 };
82 
83 
84 //  ******** _BDropUndoBuffer_ ********
85 class _BDropUndoBuffer_ : public _BUndoBuffer_ {
86 public:
87 	_BDropUndoBuffer_(BTextView *, char const *, int32, text_run_array *, int32, int32, bool);
88 	~_BDropUndoBuffer_();
89 
90 protected:
91 	virtual void UndoSelf(BClipboard *);
92 	virtual void RedoSelf(BClipboard *);
93 
94 private:
95 	char *fDropText;
96 	int32 fDropTextLength;
97 	text_run_array *fDropRunArray;
98 
99 	int32 fDropLocation;
100 	bool fInternalDrop;
101 };
102 
103 
104 //  ******** _BTypingUndoBuffer_ ********
105 class _BTypingUndoBuffer_ : public _BUndoBuffer_ {
106 public:
107 	_BTypingUndoBuffer_(BTextView *);
108 	~_BTypingUndoBuffer_();
109 
110 	void InputCharacter(int32);
111 	void BackwardErase();
112 	void ForwardErase();
113 
114 protected:
115 	virtual void RedoSelf(BClipboard *);
116 	virtual void UndoSelf(BClipboard *);
117 
118 private:
119 	void Reset();
120 
121 	char *fTypedText;
122 	int32 fTypedStart;
123 	int32 fTypedEnd;
124 	int32 fUndone;
125 };
126 
127 #endif //__UNDOBUFFER_H
128