1// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#ifndef _FXET_EDIT_H_
8#define _FXET_EDIT_H_
9
10#include "fx_edit.h"
11
12class CFX_Edit_Page;
13struct CFX_Edit_LineRect;
14class CFX_Edit_LineRectArray;
15class CFX_Edit_RectArray;
16class CFX_Edit_Refresh;
17class CFX_Edit_Select;
18class CFX_Edit;
19class CFX_Edit_Iterator;
20class CFX_Edit_Refresh;
21class CFX_Edit_UndoItem;
22class CFX_Edit_Undo;
23class CFX_Edit_Provider;
24
25#define FX_EDIT_IsFloatZero(f)						(f < 0.0001 && f > -0.0001)
26#define FX_EDIT_IsFloatEqual(fa,fb)					FX_EDIT_IsFloatZero(fa - fb)
27#define FX_EDIT_IsFloatBigger(fa,fb)				(fa > fb && !FX_EDIT_IsFloatEqual(fa,fb))
28#define FX_EDIT_IsFloatSmaller(fa,fb)				(fa < fb && !FX_EDIT_IsFloatEqual(fa,fb))
29
30template<class T> T FX_EDIT_MIN (const T & i, const T & j) { return ((i < j) ? i : j); }
31template<class T> T FX_EDIT_MAX (const T & i, const T & j) { return ((i > j) ? i : j); }
32
33#define	FX_EDIT_PI									3.14159265358979f
34#define FX_EDIT_ITALIC_ANGEL						10 * FX_EDIT_PI / 180.0f
35
36
37/* ------------------------- CFX_Edit_Refresh ---------------------------- */
38
39enum REFRESH_PLAN_E
40{
41	RP_ANALYSE,
42	RP_NOANALYSE,
43	RP_OPTIONAL
44};
45
46enum EDIT_PROPS_E
47{
48	EP_LINELEADING,
49	EP_LINEINDENT,
50	EP_ALIGNMENT,
51	EP_FONTINDEX,
52	EP_FONTSIZE,
53	EP_WORDCOLOR,
54	EP_SCRIPTTYPE,
55	EP_UNDERLINE,
56	EP_CROSSOUT,
57	EP_CHARSPACE,
58	EP_HORZSCALE,
59	EP_BOLD,
60	EP_ITALIC
61};
62
63struct CFX_Edit_LineRect
64{
65	CFX_Edit_LineRect(const CPVT_WordRange & wrLine,const CPDF_Rect & rcLine) :
66		m_wrLine(wrLine), m_rcLine(rcLine)
67	{
68	}
69
70	FX_BOOL operator != (const CFX_Edit_LineRect & linerect) const
71	{
72		return FXSYS_memcmp(this, &linerect, sizeof(CFX_Edit_LineRect)) != 0;
73	}
74
75	FX_BOOL IsSameHeight(const CFX_Edit_LineRect & linerect) const
76	{
77		return FX_EDIT_IsFloatZero((m_rcLine.top - m_rcLine.bottom) - (linerect.m_rcLine.top -linerect.m_rcLine.bottom));
78	}
79
80	FX_BOOL IsSameTop(const CFX_Edit_LineRect & linerect) const
81	{
82		return FX_EDIT_IsFloatZero(m_rcLine.top - linerect.m_rcLine.top);
83	}
84
85	FX_BOOL IsSameLeft(const CFX_Edit_LineRect & linerect) const
86	{
87		return FX_EDIT_IsFloatZero(m_rcLine.left - linerect.m_rcLine.left);
88	}
89
90	FX_BOOL IsSameRight(const CFX_Edit_LineRect & linerect) const
91	{
92		return FX_EDIT_IsFloatZero(m_rcLine.right - linerect.m_rcLine.right);
93	}
94
95	CPVT_WordRange							m_wrLine;
96	CPDF_Rect								m_rcLine;
97};
98
99class CFX_Edit_LineRectArray
100{
101public:
102	CFX_Edit_LineRectArray()
103	{
104	}
105
106	virtual ~CFX_Edit_LineRectArray()
107	{
108		Empty();
109	}
110
111	void Empty()
112	{
113		for (FX_INT32 i = 0, sz = m_LineRects.GetSize(); i < sz; i++)
114			delete m_LineRects.GetAt(i);
115
116		m_LineRects.RemoveAll();
117	}
118
119	void RemoveAll()
120	{
121		m_LineRects.RemoveAll();
122	}
123
124	void operator = (CFX_Edit_LineRectArray & rects)
125	{
126		Empty();
127		for (FX_INT32 i = 0, sz = rects.GetSize(); i < sz; i++)
128			m_LineRects.Add(rects.GetAt(i));
129
130		rects.RemoveAll();
131	}
132
133	void Add(const CPVT_WordRange & wrLine,const CPDF_Rect & rcLine)
134	{
135		if (CFX_Edit_LineRect * pRect = new CFX_Edit_LineRect(wrLine,rcLine))
136			m_LineRects.Add(pRect);
137	}
138
139	FX_INT32 GetSize() const
140	{
141		return m_LineRects.GetSize();
142	}
143
144	CFX_Edit_LineRect * GetAt(FX_INT32 nIndex) const
145	{
146		if (nIndex < 0 || nIndex >= m_LineRects.GetSize())
147			return NULL;
148
149		return m_LineRects.GetAt(nIndex);
150	}
151
152	CFX_ArrayTemplate<CFX_Edit_LineRect*>		m_LineRects;
153};
154
155class CFX_Edit_RectArray
156{
157public:
158	CFX_Edit_RectArray()
159	{
160	}
161
162	virtual ~CFX_Edit_RectArray()
163	{
164		this->Empty();
165	}
166
167	void Empty()
168	{
169		for (FX_INT32 i = 0, sz = m_Rects.GetSize(); i < sz; i++)
170			delete m_Rects.GetAt(i);
171
172		this->m_Rects.RemoveAll();
173	}
174
175	void Add(const CPDF_Rect & rect)
176	{
177		//check for overlaped area
178		for (FX_INT32 i = 0, sz = m_Rects.GetSize(); i < sz; i++)
179			if (CPDF_Rect * pRect = m_Rects.GetAt(i))
180				if (pRect->Contains(rect))return;
181
182		if (CPDF_Rect * pNewRect = new CPDF_Rect(rect))
183			m_Rects.Add(pNewRect);
184	}
185
186	FX_INT32 GetSize() const
187	{
188		return m_Rects.GetSize();
189	}
190
191	CPDF_Rect * GetAt(FX_INT32 nIndex) const
192	{
193		if (nIndex < 0 || nIndex >= m_Rects.GetSize())
194			return NULL;
195
196		return m_Rects.GetAt(nIndex);
197	}
198
199	CFX_ArrayTemplate<CPDF_Rect*>			m_Rects;
200};
201
202class CFX_Edit_Refresh
203{
204public:
205	CFX_Edit_Refresh();
206	virtual ~CFX_Edit_Refresh();
207
208	void									BeginRefresh();
209	void									Push(const CPVT_WordRange & linerange,const CPDF_Rect & rect);
210	void									NoAnalyse();
211	void									Analyse(FX_INT32 nAlignment);
212	void									AddRefresh(const CPDF_Rect & rect);
213	const CFX_Edit_RectArray *				GetRefreshRects() const;
214	void									EndRefresh();
215
216private:
217	CFX_Edit_LineRectArray					m_NewLineRects;
218	CFX_Edit_LineRectArray					m_OldLineRects;
219	CFX_Edit_RectArray						m_RefreshRects;
220};
221
222
223/* ------------------------- CFX_Edit_Select ---------------------------- */
224
225class CFX_Edit_Select
226{
227public:
228	CFX_Edit_Select()
229	{
230	}
231
232	CFX_Edit_Select(const CPVT_WordPlace & begin,const CPVT_WordPlace & end)
233	{
234		Set(begin,end);
235	}
236
237	CFX_Edit_Select(const CPVT_WordRange & range)
238	{
239		Set(range.BeginPos,range.EndPos);
240	}
241
242	CPVT_WordRange ConvertToWordRange() const
243	{
244		return CPVT_WordRange(this->BeginPos,this->EndPos);
245	}
246
247	void Default()
248	{
249		BeginPos.Default();
250		EndPos.Default();
251	}
252
253	void Set(const CPVT_WordPlace & begin,const CPVT_WordPlace & end)
254	{
255		this->BeginPos = begin;
256		this->EndPos = end;
257	}
258
259	void SetBeginPos(const CPVT_WordPlace & begin)
260	{
261		this->BeginPos = begin;
262	}
263
264	void SetEndPos(const CPVT_WordPlace & end)
265	{
266		this->EndPos = end;
267	}
268
269	FX_BOOL IsExist() const
270	{
271		return this->BeginPos != this->EndPos;
272	}
273
274	FX_BOOL operator != (const CPVT_WordRange & wr) const
275	{
276		return wr.BeginPos != this->BeginPos || wr.EndPos != this->EndPos;
277	}
278
279	CPVT_WordPlace BeginPos,EndPos;
280};
281
282/* ------------------------- CFX_Edit_Undo ---------------------------- */
283
284class CFX_Edit_Undo
285{
286public:
287	CFX_Edit_Undo(FX_INT32 nBufsize = 10000);
288	virtual ~CFX_Edit_Undo();
289
290	void									Undo();
291	void									Redo();
292
293	void									AddItem(IFX_Edit_UndoItem* pItem);
294
295	FX_BOOL									CanUndo() const;
296	FX_BOOL									CanRedo() const;
297	FX_BOOL									IsModified() const;
298	FX_BOOL									IsWorking() const;
299
300	void									Reset();
301
302	IFX_Edit_UndoItem*						GetItem(FX_INT32 nIndex);
303	FX_INT32								GetItemCount(){return m_UndoItemStack.GetSize();}
304	FX_INT32								GetCurUndoPos(){return m_nCurUndoPos;}
305
306private:
307	void									SetBufSize(FX_INT32 nSize){m_nBufSize = nSize;}
308	FX_INT32								GetBufSize(){return m_nBufSize;}
309
310	void									RemoveHeads();
311	void									RemoveTails();
312
313private:
314	CFX_ArrayTemplate<IFX_Edit_UndoItem*>	m_UndoItemStack;
315
316	FX_INT32								m_nCurUndoPos;
317	FX_INT32								m_nBufSize;
318	FX_BOOL									m_bModified;
319	FX_BOOL									m_bVirgin;
320	FX_BOOL									m_bWorking;
321};
322
323class CFX_Edit_UndoItem : public IFX_Edit_UndoItem
324{
325public:
326	CFX_Edit_UndoItem() : m_bFirst(TRUE), m_bLast(TRUE) {}
327	virtual ~CFX_Edit_UndoItem(){}
328
329	virtual CFX_WideString					GetUndoTitle() {return L"";}
330	virtual void							Release(){delete this;}
331
332public:
333	void									SetFirst(FX_BOOL bFirst){m_bFirst = bFirst;}
334	FX_BOOL									IsFirst(){return m_bFirst;}
335	void									SetLast(FX_BOOL bLast){m_bLast = bLast;}
336	FX_BOOL									IsLast(){return m_bLast;}
337
338private:
339	FX_BOOL									m_bFirst;
340	FX_BOOL									m_bLast;
341};
342
343class CFX_Edit_GroupUndoItem : public IFX_Edit_UndoItem
344{
345public:
346	CFX_Edit_GroupUndoItem(const CFX_WideString& sTitle);
347	virtual ~CFX_Edit_GroupUndoItem();
348
349	void									AddUndoItem(CFX_Edit_UndoItem* pUndoItem);
350	void									UpdateItems();
351
352public:
353	virtual void							Undo();
354	virtual void							Redo();
355	virtual CFX_WideString					GetUndoTitle();
356	virtual void							Release();
357
358private:
359	CFX_WideString							m_sTitle;
360	CFX_ArrayTemplate<CFX_Edit_UndoItem*>	m_Items;
361};
362
363/* ------------------------- CFX_Edit_UndoItem derived classes ---------------------------- */
364
365class CFXEU_InsertWord : public CFX_Edit_UndoItem
366{
367public:
368	CFXEU_InsertWord(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
369		FX_WORD word, FX_INT32 charset, const CPVT_WordProps * pWordProps);
370	virtual ~CFXEU_InsertWord();
371
372	void						Redo();
373	void						Undo();
374
375private:
376	CFX_Edit*					m_pEdit;
377
378	CPVT_WordPlace				m_wpOld;
379	CPVT_WordPlace				m_wpNew;
380	FX_WORD						m_Word;
381	FX_INT32					m_nCharset;
382	CPVT_WordProps				m_WordProps;
383};
384
385class CFXEU_InsertReturn : public CFX_Edit_UndoItem
386{
387public:
388	CFXEU_InsertReturn(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
389							 const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps);
390	virtual ~CFXEU_InsertReturn();
391
392	void						Redo();
393	void						Undo();
394
395private:
396	CFX_Edit *					m_pEdit;
397
398	CPVT_WordPlace				m_wpOld;
399	CPVT_WordPlace				m_wpNew;
400	CPVT_SecProps				m_SecProps;
401	CPVT_WordProps				m_WordProps;
402};
403
404class CFXEU_Backspace : public CFX_Edit_UndoItem
405{
406public:
407	CFXEU_Backspace(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
408						FX_WORD word, FX_INT32 charset,
409						const CPVT_SecProps & SecProps, const CPVT_WordProps & WordProps);
410	virtual ~CFXEU_Backspace();
411
412	void						Redo();
413	void						Undo();
414
415private:
416	CFX_Edit *					m_pEdit;
417
418	CPVT_WordPlace				m_wpOld;
419	CPVT_WordPlace				m_wpNew;
420	FX_WORD						m_Word;
421	FX_INT32					m_nCharset;
422	CPVT_SecProps				m_SecProps;
423	CPVT_WordProps				m_WordProps;
424};
425
426class CFXEU_Delete : public CFX_Edit_UndoItem
427{
428public:
429	CFXEU_Delete(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
430						FX_WORD word, FX_INT32 charset,
431						const CPVT_SecProps & SecProps, const CPVT_WordProps & WordProps, FX_BOOL bSecEnd);
432	virtual ~CFXEU_Delete();
433
434	void						Redo();
435	void						Undo();
436
437private:
438	CFX_Edit *					m_pEdit;
439
440	CPVT_WordPlace				m_wpOld;
441	CPVT_WordPlace				m_wpNew;
442	FX_WORD						m_Word;
443	FX_INT32					m_nCharset;
444	CPVT_SecProps				m_SecProps;
445	CPVT_WordProps				m_WordProps;
446	FX_BOOL						m_bSecEnd;
447};
448
449class CFXEU_Clear : public CFX_Edit_UndoItem
450{
451public:
452	CFXEU_Clear(CFX_Edit * pEdit, const CPVT_WordRange & wrSel, const CFX_WideString & swText);
453	virtual ~CFXEU_Clear();
454
455	void						Redo();
456	void						Undo();
457
458private:
459	CFX_Edit*					m_pEdit;
460
461	CPVT_WordRange				m_wrSel;
462	CFX_WideString				m_swText;
463};
464
465class CFXEU_ClearRich : public CFX_Edit_UndoItem
466{
467public:
468	CFXEU_ClearRich(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
469						const CPVT_WordRange & wrSel,
470					   FX_WORD word, FX_INT32 charset,
471					   const CPVT_SecProps & SecProps, const CPVT_WordProps & WordProps);
472	virtual ~CFXEU_ClearRich();
473
474	void						Redo();
475	void						Undo();
476
477private:
478	CFX_Edit *					m_pEdit;
479
480	CPVT_WordPlace				m_wpOld;
481	CPVT_WordPlace				m_wpNew;
482	CPVT_WordRange				m_wrSel;
483	FX_WORD						m_Word;
484	FX_INT32					m_nCharset;
485	CPVT_SecProps				m_SecProps;
486	CPVT_WordProps				m_WordProps;
487};
488
489class CFXEU_InsertText : public CFX_Edit_UndoItem
490{
491public:
492	CFXEU_InsertText(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
493						   const CFX_WideString & swText, FX_INT32 charset,
494						   const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps);
495	virtual ~CFXEU_InsertText();
496
497	void						Redo();
498	void						Undo();
499
500private:
501	CFX_Edit *					m_pEdit;
502
503	CPVT_WordPlace				m_wpOld;
504	CPVT_WordPlace				m_wpNew;
505	CFX_WideString				m_swText;
506	FX_INT32					m_nCharset;
507	CPVT_SecProps				m_SecProps;
508	CPVT_WordProps				m_WordProps;
509};
510
511class CFXEU_SetSecProps : public CFX_Edit_UndoItem
512{
513public:
514	CFXEU_SetSecProps(CFX_Edit * pEdit, const CPVT_WordPlace & place, EDIT_PROPS_E ep,
515		const CPVT_SecProps & oldsecprops, const CPVT_WordProps & oldwordprops,
516		const CPVT_SecProps & newsecprops, const CPVT_WordProps & newwordprops, const CPVT_WordRange & range);
517	virtual ~CFXEU_SetSecProps();
518
519	void						Redo();
520	void						Undo();
521
522private:
523	CFX_Edit *					m_pEdit;
524	CPVT_WordPlace				m_wpPlace;
525	CPVT_WordRange				m_wrPlace;
526	EDIT_PROPS_E				m_eProps;
527
528	CPVT_SecProps				m_OldSecProps;
529	CPVT_SecProps				m_NewSecProps;
530	CPVT_WordProps				m_OldWordProps;
531	CPVT_WordProps				m_NewWordProps;
532};
533
534class CFXEU_SetWordProps : public CFX_Edit_UndoItem
535{
536public:
537	CFXEU_SetWordProps(CFX_Edit * pEdit, const CPVT_WordPlace & place, EDIT_PROPS_E ep,
538		const CPVT_WordProps & oldprops, const CPVT_WordProps & newprops, const CPVT_WordRange & range);
539	virtual ~CFXEU_SetWordProps();
540
541	void						Redo();
542	void						Undo();
543
544private:
545	CFX_Edit *					m_pEdit;
546	CPVT_WordPlace				m_wpPlace;
547	CPVT_WordRange				m_wrPlace;
548	EDIT_PROPS_E				m_eProps;
549
550	CPVT_WordProps				m_OldWordProps;
551	CPVT_WordProps				m_NewWordProps;
552};
553
554/* ------------------------- CFX_Edit ---------------------------- */
555
556class CFX_Edit : public IFX_Edit
557{
558	friend class CFX_Edit_Iterator;
559	friend class CFXEU_InsertWord;
560	friend class CFXEU_InsertReturn;
561	friend class CFXEU_Backspace;
562	friend class CFXEU_Delete;
563	friend class CFXEU_Clear;
564	friend class CFXEU_ClearRich;
565	friend class CFXEU_SetSecProps;
566	friend class CFXEU_SetWordProps;
567	friend class CFXEU_InsertText;
568
569public:
570	CFX_Edit(IPDF_VariableText * pVT);
571	virtual ~CFX_Edit();
572
573	void									SetFontMap(IFX_Edit_FontMap * pFontMap);
574	void									SetVTProvider(IPDF_VariableText_Provider* pProvider);
575	void									SetNotify(IFX_Edit_Notify * pNotify);
576	void									SetOprNotify(IFX_Edit_OprNotify* pOprNotify);
577	IFX_Edit_Iterator*						GetIterator();
578	IPDF_VariableText *						GetVariableText();
579	IFX_Edit_FontMap*						GetFontMap();
580
581	void									Initialize();
582	void									SetPlateRect(const CPDF_Rect & rect, FX_BOOL bPaint = TRUE);
583	void									SetScrollPos(const CPDF_Point & point);
584
585	void									SetAlignmentH(FX_INT32 nFormat = 0, FX_BOOL bPaint = TRUE);
586	void									SetAlignmentV(FX_INT32 nFormat = 0, FX_BOOL bPaint = TRUE);
587	void									SetPasswordChar(FX_WORD wSubWord = '*', FX_BOOL bPaint = TRUE);
588	void									SetLimitChar(FX_INT32 nLimitChar = 0, FX_BOOL bPaint = TRUE);
589	void									SetCharArray(FX_INT32 nCharArray = 0, FX_BOOL bPaint = TRUE);
590	void									SetCharSpace(FX_FLOAT fCharSpace = 0.0f, FX_BOOL bPaint = TRUE);
591	void									SetHorzScale(FX_INT32 nHorzScale = 100, FX_BOOL bPaint = TRUE);
592	void									SetLineLeading(FX_FLOAT fLineLeading, FX_BOOL bPaint = TRUE);
593	void									SetMultiLine(FX_BOOL bMultiLine = TRUE, FX_BOOL bPaint = TRUE);
594	void									SetAutoReturn(FX_BOOL bAuto = TRUE, FX_BOOL bPaint = TRUE);
595	void									SetAutoFontSize(FX_BOOL bAuto = TRUE, FX_BOOL bPaint = TRUE);
596	void									SetAutoScroll(FX_BOOL bAuto = TRUE, FX_BOOL bPaint = TRUE);
597	void									SetFontSize(FX_FLOAT fFontSize, FX_BOOL bPaint = TRUE);
598	void									SetTextOverflow(FX_BOOL bAllowed = FALSE, FX_BOOL bPaint = TRUE);
599
600	FX_BOOL									IsRichText() const;
601	void									SetRichText(FX_BOOL bRichText = TRUE, FX_BOOL bPaint = TRUE);
602	FX_BOOL									SetRichFontSize(FX_FLOAT fFontSize);
603	FX_BOOL									SetRichFontIndex(FX_INT32 nFontIndex);
604	FX_BOOL									SetRichTextColor(FX_COLORREF dwColor);
605	FX_BOOL									SetRichTextScript(FX_INT32 nScriptType);
606	FX_BOOL									SetRichTextBold(FX_BOOL bBold = TRUE);
607	FX_BOOL									SetRichTextItalic(FX_BOOL bItalic = TRUE);
608	FX_BOOL									SetRichTextUnderline(FX_BOOL bUnderline = TRUE);
609	FX_BOOL									SetRichTextCrossout(FX_BOOL bCrossout = TRUE);
610	FX_BOOL									SetRichTextCharSpace(FX_FLOAT fCharSpace);
611	FX_BOOL									SetRichTextHorzScale(FX_INT32 nHorzScale = 100);
612	FX_BOOL									SetRichTextLineLeading(FX_FLOAT fLineLeading);
613	FX_BOOL									SetRichTextLineIndent(FX_FLOAT fLineIndent);
614	FX_BOOL									SetRichTextAlignment(FX_INT32 nAlignment);
615
616	void									OnMouseDown(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl);
617	void									OnMouseMove(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl);
618	void									OnVK_UP(FX_BOOL bShift,FX_BOOL bCtrl);
619	void									OnVK_DOWN(FX_BOOL bShift,FX_BOOL bCtrl);
620	void									OnVK_LEFT(FX_BOOL bShift,FX_BOOL bCtrl);
621	void									OnVK_RIGHT(FX_BOOL bShift,FX_BOOL bCtrl);
622	void									OnVK_HOME(FX_BOOL bShift,FX_BOOL bCtrl);
623	void									OnVK_END(FX_BOOL bShift,FX_BOOL bCtrl);
624
625	void									SetText(FX_LPCWSTR text,FX_INT32 charset = DEFAULT_CHARSET,
626													const CPVT_SecProps * pSecProps = NULL,const CPVT_WordProps * pWordProps = NULL);
627	FX_BOOL									InsertWord(FX_WORD word, FX_INT32 charset = DEFAULT_CHARSET, const CPVT_WordProps * pWordProps = NULL);
628	FX_BOOL									InsertReturn(const CPVT_SecProps * pSecProps = NULL,const CPVT_WordProps * pWordProps = NULL);
629	FX_BOOL									Backspace();
630	FX_BOOL									Delete();
631	FX_BOOL									Clear();
632	FX_BOOL									Empty();
633	FX_BOOL									InsertText(FX_LPCWSTR text, FX_INT32 charset = DEFAULT_CHARSET,
634													const CPVT_SecProps * pSecProps = NULL,const CPVT_WordProps * pWordProps = NULL);
635	FX_BOOL									Redo();
636	FX_BOOL									Undo();
637	CPVT_WordPlace							DoInsertText(const CPVT_WordPlace& place, FX_LPCWSTR text, FX_INT32 charset,
638												const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps);
639	FX_INT32								GetCharSetFromUnicode(FX_WORD word, FX_INT32 nOldCharset);
640
641	FX_INT32								WordPlaceToWordIndex(const CPVT_WordPlace & place) const;
642	CPVT_WordPlace							WordIndexToWordPlace(FX_INT32 index) const;
643
644	CPVT_WordPlace							GetLineBeginPlace(const CPVT_WordPlace & place) const;
645	CPVT_WordPlace							GetLineEndPlace(const CPVT_WordPlace & place) const;
646	CPVT_WordPlace							GetSectionBeginPlace(const CPVT_WordPlace & place) const;
647	CPVT_WordPlace							GetSectionEndPlace(const CPVT_WordPlace & place) const;
648	CPVT_WordPlace							SearchWordPlace(const CPDF_Point& point) const;
649
650	FX_INT32								GetCaret() const;
651	CPVT_WordPlace							GetCaretWordPlace() const;
652	CFX_WideString							GetSelText() const;
653	CFX_WideString							GetText() const;
654	FX_FLOAT								GetFontSize() const;
655	FX_WORD									GetPasswordChar() const;
656	CPDF_Point								GetScrollPos() const;
657	FX_INT32								GetCharArray() const;
658	CPDF_Rect								GetPlateRect() const;
659	CPDF_Rect								GetContentRect() const;
660	CFX_WideString							GetRangeText(const CPVT_WordRange & range) const;
661	FX_INT32								GetHorzScale() const;
662	FX_FLOAT								GetCharSpace() const;
663	FX_INT32								GetTotalWords() const;
664	FX_INT32								GetTotalLines() const;
665
666	void									SetSel(FX_INT32 nStartChar,FX_INT32 nEndChar);
667	void									GetSel(FX_INT32 & nStartChar, FX_INT32 & nEndChar) const;
668
669private:
670	void									SelectAll();
671	void									SelectNone();
672	void									SetSel(const CPVT_WordPlace & begin,const CPVT_WordPlace & end);
673	FX_BOOL									IsSelected() const;
674
675	void									RearrangeAll();
676	void									RearrangePart(const CPVT_WordRange & range);
677	void									Paint();
678	void									ScrollToCaret();
679	void									SetScrollInfo();
680	void									SetScrollPosX(FX_FLOAT fx);
681	void									SetScrollPosY(FX_FLOAT fy);
682	void									SetScrollLimit();
683	void									SetContentChanged();
684	void									EnableNotify(FX_BOOL bNotify);
685
686	void									SetText(FX_LPCWSTR text,FX_INT32 charset,
687													const CPVT_SecProps * pSecProps,const CPVT_WordProps * pWordProps,FX_BOOL bAddUndo, FX_BOOL bPaint);
688	FX_BOOL									InsertWord(FX_WORD word, FX_INT32 charset, const CPVT_WordProps * pWordProps,FX_BOOL bAddUndo, FX_BOOL bPaint);
689	FX_BOOL									InsertReturn(const CPVT_SecProps * pSecProps,const CPVT_WordProps * pWordProps,FX_BOOL bAddUndo, FX_BOOL bPaint);
690	FX_BOOL									Backspace(FX_BOOL bAddUndo, FX_BOOL bPaint);
691	FX_BOOL									Delete(FX_BOOL bAddUndo, FX_BOOL bPaint);
692	FX_BOOL									Clear(FX_BOOL bAddUndo, FX_BOOL bPaint);
693	FX_BOOL									InsertText(FX_LPCWSTR text, FX_INT32 charset,
694												const CPVT_SecProps * pSecProps,const CPVT_WordProps * pWordProps,FX_BOOL bAddUndo, FX_BOOL bPaint);
695	FX_BOOL									SetRichTextProps(EDIT_PROPS_E eProps,
696												const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps);
697	FX_BOOL									SetSecProps(EDIT_PROPS_E eProps, const CPVT_WordPlace & place,
698												const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps, const CPVT_WordRange & wr, FX_BOOL bAddUndo);
699	FX_BOOL									SetWordProps(EDIT_PROPS_E eProps, const CPVT_WordPlace & place,
700												const CPVT_WordProps * pWordProps, const CPVT_WordRange & wr, FX_BOOL bAddUndo);
701	void									PaintSetProps(EDIT_PROPS_E eProps, const CPVT_WordRange & wr);
702	void									PaintInsertText(const CPVT_WordPlace & wpOld, const CPVT_WordPlace & wpNew);
703
704	inline CPDF_Point						VTToEdit(const CPDF_Point & point) const;
705	inline CPDF_Point						EditToVT(const CPDF_Point & point) const;
706	inline CPDF_Rect						VTToEdit(const CPDF_Rect & rect) const;
707	inline CPDF_Rect						EditToVT(const CPDF_Rect & rect) const;
708
709	void									EnableRefresh(FX_BOOL bRefresh);
710	void									Refresh(REFRESH_PLAN_E ePlan,const CPVT_WordRange * pRange1 = NULL,const CPVT_WordRange * pRange2 = NULL);
711	void									RefreshPushLineRects(const CPVT_WordRange & wr);
712	void									RefreshPushRandomRects(const CPVT_WordRange & wr);
713	void									RefreshWordRange(const CPVT_WordRange& wr);
714
715	void									SetCaret(FX_INT32 nPos);
716	void									SetCaret(const CPVT_WordPlace & place);
717	void									SetCaretInfo();
718	void									SetCaretOrigin();
719	void									SetCaretChange();
720
721	CPVT_WordRange							GetWholeWordRange() const;
722	CPVT_WordRange							GetVisibleWordRange() const;
723	CPVT_WordRange							GetLatinWordsRange(const CPVT_WordPlace & place) const;
724	CPVT_WordRange							CombineWordRange(const CPVT_WordRange & wr1, const CPVT_WordRange & wr2);
725	CPVT_WordRange							GetSelectWordRange() const;
726
727	void									EnableUndo(FX_BOOL bUndo);
728	void									EnableOprNotify(FX_BOOL bNotify);
729
730	FX_BOOL									IsTextFull() const;
731	FX_BOOL									IsTextOverflow() const;
732	FX_BOOL									CanUndo() const;
733	FX_BOOL									CanRedo() const;
734	FX_BOOL									IsModified() const;
735
736	void									BeginGroupUndo(const CFX_WideString& sTitle);
737	void									EndGroupUndo();
738	void									AddEditUndoItem(CFX_Edit_UndoItem* pEditUndoItem);
739	void									AddUndoItem(IFX_Edit_UndoItem* pUndoItem);
740
741	void									SetPageInfo(const CPVT_WordPlace& place);
742	CPVT_WordPlace							SearchPageEndPlace(const CPVT_WordPlace& wpPageBegin, const CPDF_Point& point) const;
743	FX_FLOAT								GetLineTop(const CPVT_WordPlace& place) const;
744	FX_FLOAT								GetLineBottom(const CPVT_WordPlace& place) const;
745
746private:
747	IPDF_VariableText*						m_pVT;
748	IFX_Edit_Notify*						m_pNotify;
749	IFX_Edit_OprNotify*						m_pOprNotify;
750	CFX_Edit_Provider*						m_pVTProvide;
751
752	CPVT_WordPlace							m_wpCaret;
753	CPVT_WordPlace							m_wpOldCaret;
754	CFX_Edit_Select							m_SelState;
755
756	CPDF_Point								m_ptScrollPos;
757	CPDF_Point								m_ptRefreshScrollPos;
758	FX_BOOL									m_bEnableScroll;
759	IFX_Edit_Iterator *						m_pIterator;
760	CFX_Edit_Refresh						m_Refresh;
761	CPDF_Point								m_ptCaret;
762	CFX_Edit_Undo							m_Undo;
763	FX_INT32								m_nAlignment;
764	FX_BOOL									m_bNotifyFlag;
765	FX_BOOL									m_bTextFullFlag;
766	FX_BOOL									m_bEnableOverflow;
767	FX_BOOL									m_bEnableRefresh;
768	CPDF_Rect								m_rcOldContent;
769	FX_BOOL									m_bEnableUndo;
770	FX_BOOL									m_bNotify;
771	FX_BOOL									m_bOprNotify;
772	CFX_Edit_GroupUndoItem*					m_pGroupUndoItem;
773};
774
775/* ------------------------- CFX_Edit_Iterator ---------------------------- */
776
777class CFX_Edit_Iterator : public IFX_Edit_Iterator
778{
779public:
780	CFX_Edit_Iterator(CFX_Edit * pEdit,IPDF_VariableText_Iterator * pVTIterator);
781	virtual ~CFX_Edit_Iterator();
782
783	FX_BOOL									NextWord();
784	FX_BOOL									NextLine();
785	FX_BOOL									NextSection();
786	FX_BOOL									PrevWord();
787	FX_BOOL									PrevLine();
788	FX_BOOL									PrevSection();
789
790	FX_BOOL									GetWord(CPVT_Word & word) const;
791	FX_BOOL									GetLine(CPVT_Line & line) const;
792	FX_BOOL									GetSection(CPVT_Section & section) const;
793	void									SetAt(FX_INT32 nWordIndex);
794	void									SetAt(const CPVT_WordPlace & place);
795	const CPVT_WordPlace &					GetAt() const;
796	IFX_Edit*								GetEdit() const;
797
798private:
799	CFX_Edit *								m_pEdit;
800	IPDF_VariableText_Iterator*				m_pVTIterator;
801};
802
803class CFX_Edit_Provider : public IPDF_VariableText_Provider
804{
805public:
806	CFX_Edit_Provider(IFX_Edit_FontMap* pFontMap);
807	virtual ~CFX_Edit_Provider();
808
809	IFX_Edit_FontMap*			GetFontMap();
810
811	FX_INT32					GetCharWidth(FX_INT32 nFontIndex, FX_WORD word, FX_INT32 nWordStyle);
812	FX_INT32					GetTypeAscent(FX_INT32 nFontIndex);
813	FX_INT32					GetTypeDescent(FX_INT32 nFontIndex);
814	FX_INT32					GetWordFontIndex(FX_WORD word, FX_INT32 charset, FX_INT32 nFontIndex);
815	FX_INT32					GetDefaultFontIndex();
816	FX_BOOL						IsLatinWord(FX_WORD word);
817
818private:
819	IFX_Edit_FontMap*			m_pFontMap;
820};
821
822#endif //_FXET_EDIT_H_
823
824