1 class RichText : public RichTxt, public DeepCopyOption<RichText> {
2 	mutable Mutex mutex; // To cover all those laze evaluation scenarios
3 	RichStyles    style;
4 	String        footer_hack; // ugly hack
5 	bool          nolinks = false; // another ugly hack
6 
7 	void       Init();
8 
9 	void       PaintHeaderFooter(PageDraw& pw, const Rect& page, PageY py, const PaintInfo& pi,
10 	                             int from_page, int to_page) const;
11 
12 	struct StyleChangeOp;
13 	struct SetStylesOp;
14 	struct RemoveStyleOp;
15 	struct MergeStylesOp;
16 	friend struct MergeStylesOp;
17 	struct OverrideStylesOp;
18 
19 public:
20 	void                  Clear();
21 
GetStyleCount()22 	int                   GetStyleCount() const                { return style.GetCount(); }
GetStyleId(int i)23 	Uuid                  GetStyleId(int i) const              { return style.GetKey(i); }
24 	Uuid                  GetStyleId(const String& name) const;
GetStyle(int i)25 	const RichStyle&      GetStyle(int i) const                { return style[i]; }
GetStyle(const Uuid & id)26 	const RichStyle&      GetStyle(const Uuid& id) const       { return UPP::GetStyle(style, id); }
27 	void                  SetStyle(const Uuid& id, const RichStyle& _style);
HasStyle(const Uuid & id)28 	bool                  HasStyle(const Uuid& id)             { return style.Find(id) >= 0; }
29 	void                  RemoveStyle(const Uuid& id);
30 
GetStyles()31 	const RichStyles&     GetStyles() const                    { return style; }
32 	void                  SetStyles(const RichStyles& styles);
33 	void                  OverrideStyles(const RichStyles& masterstyles,
34 	                                     bool matchname = true, bool addmissing = true);
35 	void                  MergeStyles(const RichText& text);
36 
Get(int i)37 	RichPara              Get(int i) const                     { return RichTxt::Get(i, style); }
Cat(const RichPara & p)38 	void                  Cat(const RichPara& p)               { RichTxt::Cat(p, style); }
39 	void                  CatPick(RichText&& p);
40 	using                 RichTxt::CatPick;
41 
42 	RichContext           Context(const Rect& page, PageY py, RichText *header, RichText *footer) const;
Context(const Rect & page,PageY py)43 	RichContext           Context(const Rect& page, PageY py) const { return Context(page, py, ~header, ~footer); }
44 //	RichContext           Context(const Rect& page) const { return Context(page, PageY(0, 0)); }
45 
46 	RichPos               GetRichPos(int pos, int maxlevel = INT_MAX) const;
47 	int                   operator[](int pos) const            { return GetRichPos(pos).chr; }
48 
49 	void                  ApplyZoom(Zoom z);
50 
51 	PageY                 GetHeight(PageY py, const Rect& page) const;
52 	PageY                 GetHeight(const Rect& page) const;
53 	void                  Paint(PageDraw& w, PageY py, const Rect& page, const PaintInfo& pi) const;
54 	void                  Paint(PageDraw& w, const Rect& page, const PaintInfo& pi) const;
55 	RichCaret             GetCaret(int pos, const Rect& page) const;
56 	int                   GetPos(int x, PageY y, const Rect& page) const;
57 	RichHotPos            GetHotPos(int x, PageY y, int tolerance, const Rect& page) const;
58 	int                   GetVertMove(int pos, int gx, const Rect& page, int dir) const;
59 	int                   GetWidth() const;
60 
61 	int                   GetHeight(int cx) const;
62 	int                   GetHeight(Zoom zoom, int cx) const;
63 	void                  Paint(Draw& w, int x, int y, int cx, const PaintInfo& pi) const;
64 	void                  Paint(Zoom zoom, Draw& w, int x, int y, int cx) const;
65 	void                  Paint(Draw& w, int x, int y, int cx) const;
66 
67 	Vector<RichValPos>    GetValPos(const Rect& page, int type) const;
68 
69 	int                   AdjustCursor(int anchor, int cursor) const;
70 
71 	void                  Remove(int pos, int count);
72 	void                  Insert(int pos, const RichText& p);
73 	RichText              Copy(int pos, int count) const;
74 
75 	FormatInfo            GetFormatInfo(int pos, int count) const;
76 	void                  ApplyFormatInfo(int pos, const FormatInfo& fi, int count);
77 	void                  ReplaceStyle(int pos, const Uuid& id);
78 
79 	void                  ReStyle(int pos, const Uuid& id);
80 
81 	Formating             SaveFormat(int pos, int count) const;
82 	void                  RestoreFormat(int pos, const Formating& info);
83 
84 
85 	RichTable::Format     GetTableFormat(int table) const;
86 	void                  SetTableFormat(int table, const RichTable::Format& fmt);
87 	int                   SetTable(int pos, const RichTable& table);
88 	void                  DestroyTable(int table);
89 	RichTable             CopyTable(int table) const;
90 	void                  ReplaceTable(int table, const RichTable& tab);
91 	void                  RemoveParaSpecial(int table, bool before);
92 	bool                  CanRemoveParaSpecial(int table, bool before);
93 	void                  InsertParaSpecial(int table, bool before, const RichPara::Format& fmt);
94 	bool                  ShouldInsertParaSpecial(int table, bool before);
95 	RichTable             CopyTable(int table, const Rect& sel) const;
96 	void                  ClearTable(int table, const Rect& sel);
97 	void                  PasteTable(int table, Point pos, const RichTable& tab);
98 	void                  InsertTableRow(int table, int row);
99 	void                  RemoveTableRow(int table, int row);
100 	void                  InsertTableColumn(int table, int column);
101 	void                  RemoveTableColumn(int table, int column);
102 	Point                 GetMasterCell(int table, int row, int column);
GetMasterCell(int table,Point p)103 	Point                 GetMasterCell(int table, Point p)                 { return GetMasterCell(table, p.y, p.x); }
104 	void                  SplitCell(int table, Point cell, Size sz);
105 	void                  JoinCell(int table, const Rect& sel);
106 	RichCell::Format      GetCellFormat(int table, const Rect& sel) const;
107 	void                  SetCellFormat(int table, const Rect& sel, const RichCell::Format& fmt,
108 	                                    bool setkeep, bool setround);
109 	FormatInfo            GetTableFormatInfo(int table, const Rect& sel) const;
110 	void                  ApplyTableFormatInfo(int table, const Rect& sel, const RichText::FormatInfo& fi);
AdjustTableSel(int table,Rect & sel)111 	void                  AdjustTableSel(int table, Rect& sel) const        { return GetConstTable(table).AdjustSel(sel); }
112 
Iterate(Iterator & r)113 	bool                  Iterate(Iterator& r) const                        { return RichTxt::Iterate(r, 0, style); }
Iterate(UpdateIterator & r)114 	bool                  Iterate(UpdateIterator& r)                        { return RichTxt::Iterate(r, 0, style); }
115 
EvaluateFields(VectorMap<String,Value> & vars)116 	bool                  EvaluateFields(VectorMap<String, Value>& vars)    { return RichTxt::EvaluateFields(style, vars); }
117 
InvalidateAll()118 	void                  InvalidateAll()                                   { r_type = ALL; }
119 	void                  Validate();
120 	bool                  GetInvalid(PageY& top, PageY& bottom, const Rect& page,
121 	                                 int sell, int selh, int osell, int oselh) const;
122 
123 	struct ClipboardType {
124 		ClipboardType();
125 		virtual ~ClipboardType();
126 
127 		virtual int      Level();
128 		virtual RichText ReadClipboard(const RichPara::Format& f) = 0;
129 		virtual void     WriteClipboard(const RichText& text) = 0;
130 	};
131 
132 	static void           Register(ClipboardType& type);
133 
134 	//Ugly hacks
SetFooter(const String & s)135 	void                  SetFooter(const String& s)                          { footer_hack = s; }
GetFooter()136 	String                GetFooter() const                                   { return footer_hack; }
137 	void                  PrintNoLinks(bool b = true)                         { nolinks = b; }
IsPrintNoLinks()138 	bool                  IsPrintNoLinks() const                              { return nolinks; }
139 
RichText()140 	RichText()            { Init(); }
141 	RichText(const RichText& x, int);
142 	RichText(RichText&& x);
143 	RichText(RichTxt&& x, RichStyles&& st);
144 
145 	RichText& operator=(RichText&& x);
146 };
147