1 #include "RichEdit.h"
2 
3 namespace Upp {
4 
Apply(RichText & txt)5 void RichEdit::UndoInsert::Apply(RichText& txt)
6 {
7 	txt.Remove(pos, length);
8 }
9 
GetRedo(const RichText & txt)10 One<RichEdit::UndoRec> RichEdit::UndoInsert::GetRedo(const RichText& txt)
11 {
12 	return MakeOne<UndoRemove>(txt, pos, length);
13 }
14 
UndoInsert(int pos,int length,bool typing)15 RichEdit::UndoInsert::UndoInsert(int pos, int length, bool typing)
16 : pos(pos), length(length), typing(typing) {}
17 
18 // -----------------------
19 
Apply(RichText & txt)20 void RichEdit::UndoRemove::Apply(RichText& txt)
21 {
22 	txt.Insert(pos, text);
23 }
24 
GetRedo(const RichText & txt)25 One<RichEdit::UndoRec> RichEdit::UndoRemove::GetRedo(const RichText& txt)
26 {
27 	return MakeOne<UndoInsert>(pos, text.GetLength());
28 }
29 
UndoRemove(const RichText & txt,int pos,int length)30 RichEdit::UndoRemove::UndoRemove(const RichText& txt, int pos, int length)
31 : pos(pos)
32 {
33 	text = txt.Copy(pos, length);
34 }
35 
36 // -----------------------
37 
Apply(RichText & txt)38 void RichEdit::UndoFormat::Apply(RichText& txt)
39 {
40 	txt.RestoreFormat(pos, format);
41 }
42 
GetRedo(const RichText & txt)43 One<RichEdit::UndoRec> RichEdit::UndoFormat::GetRedo(const RichText& txt)
44 {
45 	return MakeOne<UndoFormat>(txt, pos, length);
46 }
47 
UndoFormat(const RichText & txt,int pos,int length)48 RichEdit::UndoFormat::UndoFormat(const RichText& txt, int pos, int length)
49 : pos(pos), length(length)
50 {
51 	format = txt.SaveFormat(pos, length);
52 }
53 
54 // -----------------------
55 
Apply(RichText & txt)56 void RichEdit::UndoStyle::Apply(RichText& txt)
57 {
58 	txt.SetStyle(id, style);
59 }
60 
GetRedo(const RichText & txt)61 One<RichEdit::UndoRec> RichEdit::UndoStyle::GetRedo(const RichText& txt)
62 {
63 	return MakeOne<UndoStyle>(txt, id);
64 }
65 
UndoStyle(const RichText & txt,const Uuid & id)66 RichEdit::UndoStyle::UndoStyle(const RichText& txt, const Uuid& id)
67 : id(id)
68 {
69 	style = txt.GetStyle(id);
70 }
71 
72 // -----------------------
73 
Apply(RichText & txt)74 void RichEdit::UndoStyles::Apply(RichText& txt)
75 {
76 	txt.SetStyles(styles);
77 }
78 
GetRedo(const RichText & txt)79 One<RichEdit::UndoRec> RichEdit::UndoStyles::GetRedo(const RichText& txt)
80 {
81 	return MakeOne<UndoStyles>(txt);
82 }
83 
UndoStyles(const RichText & txt)84 RichEdit::UndoStyles::UndoStyles(const RichText& txt)
85 {
86 	styles <<= txt.GetStyles();
87 }
88 
89 }
90