1#ifndef _K_UNDOBUFFER_H
2#define _K_UNDOBUFFER_H
3
4
5#include <List.h>
6
7
8enum undo_type{
9	K_INSERTED,
10	K_DELETED,
11	K_REPLACED
12};
13
14
15class KUndoItem
16{
17public:
18							KUndoItem(const char* text, int32 length,
19								int32 offset, undo_type history,
20								int32 cursor_pos);
21							~KUndoItem();
22
23			void			Merge(const char* text, int32 length);
24			status_t		InitCheck();
25
26			int32			Offset;
27			int32			Length;
28			char*			RedoText;
29			undo_type		History;
30			int32			CursorPos;
31
32private:
33			status_t		fStatus;
34};
35
36
37class KUndoBuffer : public BList
38{
39public:
40							KUndoBuffer();
41							~KUndoBuffer();
42
43			bool			AddItem(KUndoItem* item, int32 index);
44			bool			AddItem(KUndoItem* item);
45			void			MakeEmpty(void);
46			KUndoItem*		RemoveItem(int32 index);
47			KUndoItem*		ItemAt(int32 index) const;
48
49			status_t		AddUndo(const char* redo_text, int32 length,
50								int32 offset, undo_type history,
51								int32 cursor_pos);
52
53			status_t		MakeNewUndoItem();
54
55			status_t		Undo(char** text, int32* length, int32* offset,
56								undo_type* history, int32* cursor_pos);
57
58			status_t		Redo(char** text, int32* length, int32* offset,
59								undo_type* history, int32* cursor_pos,
60								bool* replaced);
61
62			void			PrintToStream();
63			void			On();
64			void			Off();
65
66private:
67			int32			fIndex;
68			bool			fNewItem;
69			bool			fNoTouch;
70
71			status_t		NewUndo(const char* text, int32 length,
72								int32 offset, undo_type history,
73								int32 cursor_pos);
74};
75
76
77#endif	// _K_UNDOBUFFER_H
78
79