xref: /haiku/src/apps/mail/KUndoBuffer.h (revision 93a78ecaa45114d68952d08c4778f073515102f2)
1 #include <List.h>
2 
3 enum undo_type{
4 	K_INSERTED,	// 文字挿入時 (At the time of character insertion)
5 	K_DELETED,	// 削除時 (When deleting)
6 	K_REPLACED	// 置換、つまり削除→挿入の連続動作時 (Substitution, in other words deletion -> at the time of continuous action of insertion)
7 };
8 
9 class KUndoItem
10 {
11 public:
12 	KUndoItem(const char *text,
13 			int32 length,
14 			int32 offset,
15 			undo_type history,
16 			int32 cursor_pos);
17 	~KUndoItem();
18 	void Merge(const char *text, int32 length);
19 	status_t InitCheck();
20 
21 	int32 Offset;			// 開始位置 (Start position)
22 	int32 Length;			// 文字長 (Letter length)
23 	char *RedoText;		// 復元すべきテキスト (The text which it should reconstruct)
24 	undo_type History;		// 操作区分 (Operation division)
25 	int32 CursorPos;		// カーソル位置 (Cursor position)
26 
27 private:
28 	status_t Status;
29 };
30 
31 class KUndoBuffer:public BList
32 {
33 public:
34 	KUndoBuffer();
35 	~KUndoBuffer();
36 
37 	bool AddItem(KUndoItem *item, int32 index);
38 	bool AddItem(KUndoItem *item);
39 	void MakeEmpty(void);
40 	KUndoItem *RemoveItem(int32 index);
41 	KUndoItem *ItemAt(int32 index) const;
42 
43 
44 	status_t AddUndo(const char *redo_text,
45 					int32 length,
46 					int32 offset,
47 					undo_type history,
48 					int32 cursor_pos);
49 	status_t MakeNewUndoItem();
50 	status_t Undo(char **text,
51 				int32 *length,
52 				int32 *offset,
53 				undo_type *history,
54 				int32 *cursor_pos);
55 	status_t Redo(char **text,
56 				int32 *length,
57 				int32 *offset,
58 				undo_type *history,
59 				int32 *cursor_pos,
60 				bool *replaced);
61 
62 	void PrintToStream();
63 
64 	void On();
65 	void Off();
66 
67 private:
68 	int32 FIndex;
69 	bool FNewItem;
70 	bool FNoTouch;
71 
72 	status_t NewUndo(const char *text,
73 					int32 length,
74 					int32 offset,
75 					undo_type history,
76 					int32 cursor_pos);
77 };
78