1 #include "RichEdit.h"
2
3 namespace Upp {
4
Apply(RichText & txt)5 void RichEdit::UndoTableFormat::Apply(RichText& txt)
6 {
7 txt.SetTableFormat(table, format);
8 }
9
GetRedo(const RichText & txt)10 One<RichEdit::UndoRec> RichEdit::UndoTableFormat::GetRedo(const RichText& txt)
11 {
12 return MakeOne<UndoTableFormat>(txt, table);
13 }
14
UndoTableFormat(const RichText & txt,int table)15 RichEdit::UndoTableFormat::UndoTableFormat(const RichText& txt, int table)
16 : table(table)
17 {
18 format = txt.GetTableFormat(table);
19 }
20
21 // -----------------------
22
23
Apply(RichText & txt)24 void RichEdit::UndoCreateTable::Apply(RichText& txt)
25 {
26 txt.DestroyTable(table);
27 }
28
GetRedo(const RichText & txt)29 One<RichEdit::UndoRec> RichEdit::UndoCreateTable::GetRedo(const RichText& txt)
30 {
31 return MakeOne<UndoDestroyTable>(txt, table);
32 }
33
34 // -----------------------
35
Apply(RichText & txt)36 void RichEdit::UndoDestroyTable::Apply(RichText& txt)
37 {
38 txt.SetTable(pos, table);
39 }
40
GetRedo(const RichText & txt)41 One<RichEdit::UndoRec> RichEdit::UndoDestroyTable::GetRedo(const RichText& txt)
42 {
43 return MakeOne<UndoCreateTable>(txt.GetRichPos(pos).table + 1);
44 }
45
UndoDestroyTable(const RichText & txt,int tab)46 RichEdit::UndoDestroyTable::UndoDestroyTable(const RichText& txt, int tab)
47 {
48 pos = txt.GetCellPos(tab, 0, 0).pos;
49 table = txt.CopyTable(tab);
50 }
51
52 // -----------------------
53
Apply(RichText & txt)54 void RichEdit::UndoInsertParaSpecial::Apply(RichText& txt)
55 {
56 txt.RemoveParaSpecial(table, before);
57 RichCellPos p = txt.GetCellPos(table, 0, 0);
58 }
59
GetRedo(const RichText & txt)60 One<RichEdit::UndoRec> RichEdit::UndoInsertParaSpecial::GetRedo(const RichText& txt)
61 {
62 return MakeOne<UndoRemoveParaSpecial>(txt, table, before);
63 }
64
65 // -----------------------
66
Apply(RichText & txt)67 void RichEdit::UndoRemoveParaSpecial::Apply(RichText& txt)
68 {
69 txt.InsertParaSpecial(table, before, format);
70 }
71
GetRedo(const RichText & txt)72 One<RichEdit::UndoRec> RichEdit::UndoRemoveParaSpecial::GetRedo(const RichText& txt)
73 {
74 return MakeOne<UndoInsertParaSpecial>(table, before);
75 }
76
UndoRemoveParaSpecial(const RichText & txt,int table,bool before)77 RichEdit::UndoRemoveParaSpecial::UndoRemoveParaSpecial(const RichText& txt, int table, bool before)
78 : table(table), before(before)
79 {
80 RichCellPos p = txt.GetCellPos(table, 0, 0);
81 format = txt.GetRichPos(before ? p.pos - 1 : p.pos + p.tablen + 1).format;
82 }
83
84 // -----------------------
85
Apply(RichText & txt)86 void RichEdit::UndoTable::Apply(RichText& txt)
87 {
88 txt.ReplaceTable(table, copy);
89 }
90
GetRedo(const RichText & txt)91 One<RichEdit::UndoRec> RichEdit::UndoTable::GetRedo(const RichText& txt)
92 {
93 return MakeOne<UndoTable>(txt, table);
94 }
95
UndoTable(const RichText & txt,int tab)96 RichEdit::UndoTable::UndoTable(const RichText& txt, int tab)
97 {
98 table = tab;
99 copy = txt.CopyTable(tab);
100 }
101
102 }
103