summaryrefslogtreecommitdiff
path: root/fpdfsdk/include/fxedit/fxet_edit.h
blob: 8aa44a4bed6b6d5981c0cef7cef2559c31dc1e6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
 
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef _FXET_EDIT_H_
#define _FXET_EDIT_H_

#include "../../../core/include/fpdfdoc/fpdf_vt.h"
#include "fx_edit.h"

class CFX_Edit_Page;
struct CFX_Edit_LineRect;
class CFX_Edit_LineRectArray;
class CFX_Edit_RectArray;
class CFX_Edit_Refresh;
class CFX_Edit_Select;
class CFX_Edit;
class CFX_Edit_Iterator;
class CFX_Edit_Refresh;
class CFX_Edit_UndoItem;
class CFX_Edit_Undo;
class CFX_Edit_Provider;

#define FX_EDIT_IsFloatZero(f)						(f < 0.0001 && f > -0.0001)
#define FX_EDIT_IsFloatEqual(fa,fb)					FX_EDIT_IsFloatZero(fa - fb)
#define FX_EDIT_IsFloatBigger(fa,fb)				(fa > fb && !FX_EDIT_IsFloatEqual(fa,fb))
#define FX_EDIT_IsFloatSmaller(fa,fb)				(fa < fb && !FX_EDIT_IsFloatEqual(fa,fb))

template<class T> T FX_EDIT_MIN (const T & i, const T & j) { return ((i < j) ? i : j); }
template<class T> T FX_EDIT_MAX (const T & i, const T & j) { return ((i > j) ? i : j); }

#define	FX_EDIT_PI									3.14159265358979f
#define FX_EDIT_ITALIC_ANGEL						10 * FX_EDIT_PI / 180.0f


/* ------------------------- CFX_Edit_Refresh ---------------------------- */

enum REFRESH_PLAN_E
{
	RP_ANALYSE,
	RP_NOANALYSE,
	RP_OPTIONAL
};

enum EDIT_PROPS_E
{
	EP_LINELEADING,
	EP_LINEINDENT,
	EP_ALIGNMENT,
	EP_FONTINDEX,
	EP_FONTSIZE,
	EP_WORDCOLOR,
	EP_SCRIPTTYPE,
	EP_UNDERLINE,
	EP_CROSSOUT,
	EP_CHARSPACE,
	EP_HORZSCALE,
	EP_BOLD,
	EP_ITALIC
};

struct CFX_Edit_LineRect
{
	CFX_Edit_LineRect(const CPVT_WordRange & wrLine,const CPDF_Rect & rcLine) :
		m_wrLine(wrLine), m_rcLine(rcLine)
	{
	}

	FX_BOOL operator != (const CFX_Edit_LineRect & linerect) const
	{
		return FXSYS_memcmp(this, &linerect, sizeof(CFX_Edit_LineRect)) != 0;
	}

	FX_BOOL IsSameHeight(const CFX_Edit_LineRect & linerect) const
	{
		return FX_EDIT_IsFloatZero((m_rcLine.top - m_rcLine.bottom) - (linerect.m_rcLine.top -linerect.m_rcLine.bottom));
	}

	FX_BOOL IsSameTop(const CFX_Edit_LineRect & linerect) const
	{
		return FX_EDIT_IsFloatZero(m_rcLine.top - linerect.m_rcLine.top);
	}

	FX_BOOL IsSameLeft(const CFX_Edit_LineRect & linerect) const
	{
		return FX_EDIT_IsFloatZero(m_rcLine.left - linerect.m_rcLine.left);
	}

	FX_BOOL IsSameRight(const CFX_Edit_LineRect & linerect) const
	{
		return FX_EDIT_IsFloatZero(m_rcLine.right - linerect.m_rcLine.right);
	}

	CPVT_WordRange							m_wrLine;
	CPDF_Rect								m_rcLine;
};

class CFX_Edit_LineRectArray
{
public:
	CFX_Edit_LineRectArray()
	{
	}

	virtual ~CFX_Edit_LineRectArray()
	{
		Empty();
	}

	void Empty()
	{
		for (FX_INT32 i = 0, sz = m_LineRects.GetSize(); i < sz; i++)
			delete m_LineRects.GetAt(i);

		m_LineRects.RemoveAll();
	}

	void RemoveAll()
	{
		m_LineRects.RemoveAll();
	}

	void operator = (CFX_Edit_LineRectArray & rects)
	{
		Empty();
		for (FX_INT32 i = 0, sz = rects.GetSize(); i < sz; i++)
			m_LineRects.Add(rects.GetAt(i));

		rects.RemoveAll();
	}

	void Add(const CPVT_WordRange & wrLine,const CPDF_Rect & rcLine)
	{
		if (CFX_Edit_LineRect * pRect = new CFX_Edit_LineRect(wrLine,rcLine))
			m_LineRects.Add(pRect);
	}

	FX_INT32 GetSize() const
	{
		return m_LineRects.GetSize();
	}

	CFX_Edit_LineRect * GetAt(FX_INT32 nIndex) const
	{
		if (nIndex < 0 || nIndex >= m_LineRects.GetSize())
			return NULL;

		return m_LineRects.GetAt(nIndex);
	}

	CFX_ArrayTemplate<CFX_Edit_LineRect*>		m_LineRects;
};

class CFX_Edit_RectArray
{
public:
	CFX_Edit_RectArray()
	{
	}

	virtual ~CFX_Edit_RectArray()
	{
		this->Empty();
	}

	void Empty()
	{
		for (FX_INT32 i = 0, sz = m_Rects.GetSize(); i < sz; i++)
			delete m_Rects.GetAt(i);

		this->m_Rects.RemoveAll();
	}

	void Add(const CPDF_Rect & rect)
	{
		//check for overlaped area
		for (FX_INT32 i = 0, sz = m_Rects.GetSize(); i < sz; i++)
			if (CPDF_Rect * pRect = m_Rects.GetAt(i))
				if (pRect->Contains(rect))return;

		if (CPDF_Rect * pNewRect = new CPDF_Rect(rect))
			m_Rects.Add(pNewRect);
	}

	FX_INT32 GetSize() const
	{
		return m_Rects.GetSize();
	}

	CPDF_Rect * GetAt(FX_INT32 nIndex) const
	{
		if (nIndex < 0 || nIndex >= m_Rects.GetSize())
			return NULL;

		return m_Rects.GetAt(nIndex);
	}

	CFX_ArrayTemplate<CPDF_Rect*>			m_Rects;
};

class CFX_Edit_Refresh
{
public:
	CFX_Edit_Refresh();
	virtual ~CFX_Edit_Refresh();

	void									BeginRefresh();
	void									Push(const CPVT_WordRange & linerange,const CPDF_Rect & rect);
	void									NoAnalyse();
	void									Analyse(FX_INT32 nAlignment);
	void									AddRefresh(const CPDF_Rect & rect);
	const CFX_Edit_RectArray *				GetRefreshRects() const;
	void									EndRefresh();

private:
	CFX_Edit_LineRectArray					m_NewLineRects;
	CFX_Edit_LineRectArray					m_OldLineRects;
	CFX_Edit_RectArray						m_RefreshRects;
};


/* ------------------------- CFX_Edit_Select ---------------------------- */

class CFX_Edit_Select
{
public:
	CFX_Edit_Select()
	{
	}

	CFX_Edit_Select(const CPVT_WordPlace & begin,const CPVT_WordPlace & end)
	{
		Set(begin,end);
	}

	CFX_Edit_Select(const CPVT_WordRange & range)
	{
		Set(range.BeginPos,range.EndPos);
	}

	CPVT_WordRange ConvertToWordRange() const
	{
		return CPVT_WordRange(this->BeginPos,this->EndPos);
	}

	void Default()
	{
		BeginPos.Default();
		EndPos.Default();
	}

	void Set(const CPVT_WordPlace & begin,const CPVT_WordPlace & end)
	{
		this->BeginPos = begin;
		this->EndPos = end;
	}

	void SetBeginPos(const CPVT_WordPlace & begin)
	{
		this->BeginPos = begin;
	}

	void SetEndPos(const CPVT_WordPlace & end)
	{
		this->EndPos = end;
	}

	FX_BOOL IsExist() const
	{
		return this->BeginPos != this->EndPos;
	}

	FX_BOOL operator != (const CPVT_WordRange & wr) const
	{
		return wr.BeginPos != this->BeginPos || wr.EndPos != this->EndPos;
	}

	CPVT_WordPlace BeginPos,EndPos;
};

/* ------------------------- CFX_Edit_Undo ---------------------------- */

class CFX_Edit_Undo
{
public:
	CFX_Edit_Undo(FX_INT32 nBufsize = 10000);
	virtual ~CFX_Edit_Undo();

	void									Undo();
	void									Redo();

	void									AddItem(IFX_Edit_UndoItem* pItem);

	FX_BOOL									CanUndo() const;
	FX_BOOL									CanRedo() const;
	FX_BOOL									IsModified() const;
	FX_BOOL									IsWorking() const;

	void									Reset();

	IFX_Edit_UndoItem*						GetItem(FX_INT32 nIndex);
	FX_INT32								GetItemCount(){return m_UndoItemStack.GetSize();}
	FX_INT32								GetCurUndoPos(){return m_nCurUndoPos;}

private:
	void									SetBufSize(FX_INT32 nSize){m_nBufSize = nSize;}
	FX_INT32								GetBufSize(){return m_nBufSize;}

	void									RemoveHeads();
	void									RemoveTails();

private:
	CFX_ArrayTemplate<IFX_Edit_UndoItem*>	m_UndoItemStack;
	
	FX_INT32								m_nCurUndoPos;
	FX_INT32								m_nBufSize;
	FX_BOOL									m_bModified; 
	FX_BOOL									m_bVirgin;
	FX_BOOL									m_bWorking;
};

class CFX_Edit_UndoItem : public IFX_Edit_UndoItem
{
public:
	CFX_Edit_UndoItem() : m_bFirst(TRUE), m_bLast(TRUE) {}
	virtual ~CFX_Edit_UndoItem(){}

	virtual CFX_WideString					GetUndoTitle() {return L"";}
	virtual void							Release(){delete this;}

public:
	void									SetFirst(FX_BOOL bFirst){m_bFirst = bFirst;}
	FX_BOOL									IsFirst(){return m_bFirst;}
	void									SetLast(FX_BOOL bLast){m_bLast = bLast;}
	FX_BOOL									IsLast(){return m_bLast;}

private:
	FX_BOOL									m_bFirst;
	FX_BOOL									m_bLast;
};

class CFX_Edit_GroupUndoItem : public IFX_Edit_UndoItem
{
public:
	CFX_Edit_GroupUndoItem(const CFX_WideString& sTitle);
	virtual ~CFX_Edit_GroupUndoItem();

	void									AddUndoItem(CFX_Edit_UndoItem* pUndoItem);
	void									UpdateItems();

public:
	virtual void							Undo();
	virtual void							Redo();
	virtual CFX_WideString					GetUndoTitle();
	virtual void							Release();

private:
	CFX_WideString							m_sTitle;
	CFX_ArrayTemplate<CFX_Edit_UndoItem*>	m_Items;
};

/* ------------------------- CFX_Edit_UndoItem derived classes ---------------------------- */

class CFXEU_InsertWord : public CFX_Edit_UndoItem
{
public:
	CFXEU_InsertWord(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
		FX_WORD word, FX_INT32 charset, const CPVT_WordProps * pWordProps);
	virtual ~CFXEU_InsertWord();

	void						Redo();
	void						Undo();

private:
	CFX_Edit*					m_pEdit;

	CPVT_WordPlace				m_wpOld;
	CPVT_WordPlace				m_wpNew;
	FX_WORD						m_Word;
	FX_INT32					m_nCharset;
	CPVT_WordProps				m_WordProps;
};

class CFXEU_InsertReturn : public CFX_Edit_UndoItem
{
public:
	CFXEU_InsertReturn(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
							 const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps);
	virtual ~CFXEU_InsertReturn();

	void						Redo();
	void						Undo();

private:
	CFX_Edit *					m_pEdit;

	CPVT_WordPlace				m_wpOld;
	CPVT_WordPlace				m_wpNew;
	CPVT_SecProps				m_SecProps;
	CPVT_WordProps				m_WordProps;
};

class CFXEU_Backspace : public CFX_Edit_UndoItem
{
public:
	CFXEU_Backspace(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
						FX_WORD word, FX_INT32 charset,
						const CPVT_SecProps & SecProps, const CPVT_WordProps & WordProps);
	virtual ~CFXEU_Backspace();

	void						Redo();
	void						Undo();

private:
	CFX_Edit *					m_pEdit;

	CPVT_WordPlace				m_wpOld;
	CPVT_WordPlace				m_wpNew;
	FX_WORD						m_Word;
	FX_INT32					m_nCharset;
	CPVT_SecProps				m_SecProps;
	CPVT_WordProps				m_WordProps;
};

class CFXEU_Delete : public CFX_Edit_UndoItem
{
public:
	CFXEU_Delete(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
						FX_WORD word, FX_INT32 charset,
						const CPVT_SecProps & SecProps, const CPVT_WordProps & WordProps, FX_BOOL bSecEnd);
	virtual ~CFXEU_Delete();

	void						Redo();
	void						Undo();

private:
	CFX_Edit *					m_pEdit;

	CPVT_WordPlace				m_wpOld;
	CPVT_WordPlace				m_wpNew;
	FX_WORD						m_Word;
	FX_INT32					m_nCharset;
	CPVT_SecProps				m_SecProps;
	CPVT_WordProps				m_WordProps;
	FX_BOOL						m_bSecEnd;
};

class CFXEU_Clear : public CFX_Edit_UndoItem
{
public:
	CFXEU_Clear(CFX_Edit * pEdit, const CPVT_WordRange & wrSel, const CFX_WideString & swText);
	virtual ~CFXEU_Clear();

	void						Redo();
	void						Undo();

private:
	CFX_Edit*					m_pEdit;

	CPVT_WordRange				m_wrSel;
	CFX_WideString				m_swText;
};

class CFXEU_ClearRich : public CFX_Edit_UndoItem
{
public:
	CFXEU_ClearRich(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
						const CPVT_WordRange & wrSel,
					   FX_WORD word, FX_INT32 charset,
					   const CPVT_SecProps & SecProps, const CPVT_WordProps & WordProps);
	virtual ~CFXEU_ClearRich();

	void						Redo();
	void						Undo();

private:
	CFX_Edit *					m_pEdit;

	CPVT_WordPlace				m_wpOld;
	CPVT_WordPlace				m_wpNew;
	CPVT_WordRange				m_wrSel;
	FX_WORD						m_Word;
	FX_INT32					m_nCharset;
	CPVT_SecProps				m_SecProps;
	CPVT_WordProps				m_WordProps;
};

class CFXEU_InsertText : public CFX_Edit_UndoItem
{
public:
	CFXEU_InsertText(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
						   const CFX_WideString & swText, FX_INT32 charset,
						   const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps);
	virtual ~CFXEU_InsertText();

	void						Redo();
	void						Undo();

private:
	CFX_Edit *					m_pEdit;

	CPVT_WordPlace				m_wpOld;
	CPVT_WordPlace				m_wpNew;
	CFX_WideString				m_swText;
	FX_INT32					m_nCharset;
	CPVT_SecProps				m_SecProps;
	CPVT_WordProps				m_WordProps;
};

class CFXEU_SetSecProps : public CFX_Edit_UndoItem
{
public:
	CFXEU_SetSecProps(CFX_Edit * pEdit, const CPVT_WordPlace & place, EDIT_PROPS_E ep, 
		const CPVT_SecProps & oldsecprops, const CPVT_WordProps & oldwordprops, 
		const CPVT_SecProps & newsecprops, const CPVT_WordProps & newwordprops, const CPVT_WordRange & range);
	virtual ~CFXEU_SetSecProps();

	void						Redo();
	void						Undo();

private:
	CFX_Edit *					m_pEdit;
	CPVT_WordPlace				m_wpPlace;
	CPVT_WordRange				m_wrPlace;
	EDIT_PROPS_E				m_eProps;

	CPVT_SecProps				m_OldSecProps;
	CPVT_SecProps				m_NewSecProps;
	CPVT_WordProps				m_OldWordProps;
	CPVT_WordProps				m_NewWordProps;	
};

class CFXEU_SetWordProps : public CFX_Edit_UndoItem
{
public:
	CFXEU_SetWordProps(CFX_Edit * pEdit, const CPVT_WordPlace & place, EDIT_PROPS_E ep, 
		const CPVT_WordProps & oldprops, const CPVT_WordProps & newprops, const CPVT_WordRange & range);
	virtual ~CFXEU_SetWordProps();

	void						Redo();
	void						Undo();

private:
	CFX_Edit *					m_pEdit;
	CPVT_WordPlace				m_wpPlace;
	CPVT_WordRange				m_wrPlace;
	EDIT_PROPS_E				m_eProps;
	
	CPVT_WordProps				m_OldWordProps;
	CPVT_WordProps				m_NewWordProps;	
};

/* ------------------------- CFX_Edit ---------------------------- */

class CFX_Edit : public IFX_Edit
{
	friend class CFX_Edit_Iterator;
	friend class CFXEU_InsertWord;
	friend class CFXEU_InsertReturn;
	friend class CFXEU_Backspace;
	friend class CFXEU_Delete;
	friend class CFXEU_Clear;
	friend class CFXEU_ClearRich;
	friend class CFXEU_SetSecProps;
	friend class CFXEU_SetWordProps;	
	friend class CFXEU_InsertText;

public:
	CFX_Edit(IPDF_VariableText * pVT);
	virtual ~CFX_Edit();

	void									SetFontMap(IFX_Edit_FontMap * pFontMap);	
	void									SetVTProvider(IPDF_VariableText_Provider* pProvider);
	void									SetNotify(IFX_Edit_Notify * pNotify);
	void									SetOprNotify(IFX_Edit_OprNotify* pOprNotify);
	IFX_Edit_Iterator*						GetIterator();
	IPDF_VariableText *						GetVariableText();
	IFX_Edit_FontMap*						GetFontMap();

	void									Initialize();
	void									SetPlateRect(const CPDF_Rect & rect, FX_BOOL bPaint = TRUE);
	void									SetScrollPos(const CPDF_Point & point);

	void									SetAlignmentH(FX_INT32 nFormat = 0, FX_BOOL bPaint = TRUE);
	void									SetAlignmentV(FX_INT32 nFormat = 0, FX_BOOL bPaint = TRUE);
	void									SetPasswordChar(FX_WORD wSubWord = '*', FX_BOOL bPaint = TRUE);
	void									SetLimitChar(FX_INT32 nLimitChar = 0, FX_BOOL bPaint = TRUE);
	void									SetCharArray(FX_INT32 nCharArray = 0, FX_BOOL bPaint = TRUE);
	void									SetCharSpace(FX_FLOAT fCharSpace = 0.0f, FX_BOOL bPaint = TRUE);
	void									SetHorzScale(FX_INT32 nHorzScale = 100, FX_BOOL bPaint = TRUE);
	void									SetLineLeading(FX_FLOAT fLineLeading, FX_BOOL bPaint = TRUE);
	void									SetMultiLine(FX_BOOL bMultiLine = TRUE, FX_BOOL bPaint = TRUE);
	void									SetAutoReturn(FX_BOOL bAuto = TRUE, FX_BOOL bPaint = TRUE);
	void									SetAutoFontSize(FX_BOOL bAuto = TRUE, FX_BOOL bPaint = TRUE);	
	void									SetAutoScroll(FX_BOOL bAuto = TRUE, FX_BOOL bPaint = TRUE);	
	void									SetFontSize(FX_FLOAT fFontSize, FX_BOOL bPaint = TRUE);
	void									SetTextOverflow(FX_BOOL bAllowed = FALSE, FX_BOOL bPaint = TRUE);

	FX_BOOL									IsRichText() const;
	void									SetRichText(FX_BOOL bRichText = TRUE, FX_BOOL bPaint = TRUE);
	FX_BOOL									SetRichFontSize(FX_FLOAT fFontSize);	
	FX_BOOL									SetRichFontIndex(FX_INT32 nFontIndex);
	FX_BOOL									SetRichTextColor(FX_COLORREF dwColor);
	FX_BOOL									SetRichTextScript(FX_INT32 nScriptType);
	FX_BOOL									SetRichTextBold(FX_BOOL bBold = TRUE);	
	FX_BOOL									SetRichTextItalic(FX_BOOL bItalic = TRUE);
	FX_BOOL									SetRichTextUnderline(FX_BOOL bUnderline = TRUE);
	FX_BOOL									SetRichTextCrossout(FX_BOOL bCrossout = TRUE);
	FX_BOOL									SetRichTextCharSpace(FX_FLOAT fCharSpace);
	FX_BOOL									SetRichTextHorzScale(FX_INT32 nHorzScale = 100);
	FX_BOOL									SetRichTextLineLeading(FX_FLOAT fLineLeading);
	FX_BOOL									SetRichTextLineIndent(FX_FLOAT fLineIndent);
	FX_BOOL									SetRichTextAlignment(FX_INT32 nAlignment);

	void									OnMouseDown(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl);
	void									OnMouseMove(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl);
	void									OnVK_UP(FX_BOOL bShift,FX_BOOL bCtrl);
	void									OnVK_DOWN(FX_BOOL bShift,FX_BOOL bCtrl);
	void									OnVK_LEFT(FX_BOOL bShift,FX_BOOL bCtrl);
	void									OnVK_RIGHT(FX_BOOL bShift,FX_BOOL bCtrl);
	void									OnVK_HOME(FX_BOOL bShift,FX_BOOL bCtrl);
	void									OnVK_END(FX_BOOL bShift,FX_BOOL bCtrl);

	void									SetText(FX_LPCWSTR text,FX_INT32 charset = DEFAULT_CHARSET,
													const CPVT_SecProps * pSecProps = NULL,const CPVT_WordProps * pWordProps = NULL);	
	FX_BOOL									InsertWord(FX_WORD word, FX_INT32 charset = DEFAULT_CHARSET, const CPVT_WordProps * pWordProps = NULL);
	FX_BOOL									InsertReturn(const CPVT_SecProps * pSecProps = NULL,const CPVT_WordProps * pWordProps = NULL);
	FX_BOOL									Backspace();
	FX_BOOL									Delete();		
	FX_BOOL									Clear();
	FX_BOOL									Empty();
	FX_BOOL									InsertText(FX_LPCWSTR text, FX_INT32 charset = DEFAULT_CHARSET,
													const CPVT_SecProps * pSecProps = NULL,const CPVT_WordProps * pWordProps = NULL);
	FX_BOOL									Redo();
	FX_BOOL									Undo();	
	CPVT_WordPlace							DoInsertText(const CPVT_WordPlace& place, FX_LPCWSTR text, FX_INT32 charset, 
												const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps);
	FX_INT32								GetCharSetFromUnicode(FX_WORD word, FX_INT32 nOldCharset);

	FX_INT32								WordPlaceToWordIndex(const CPVT_WordPlace & place) const;
	CPVT_WordPlace							WordIndexToWordPlace(FX_INT32 index) const;	

	CPVT_WordPlace							GetLineBeginPlace(const CPVT_WordPlace & place) const;
	CPVT_WordPlace							GetLineEndPlace(const CPVT_WordPlace & place) const;
	CPVT_WordPlace							GetSectionBeginPlace(const CPVT_WordPlace & place) const;
	CPVT_WordPlace							GetSectionEndPlace(const CPVT_WordPlace & place) const;
	CPVT_WordPlace							SearchWordPlace(const CPDF_Point& point) const;

	FX_INT32								GetCaret() const;
	CPVT_WordPlace							GetCaretWordPlace() const;
	CFX_WideString							GetSelText() const;
	CFX_WideString							GetText() const;
	FX_FLOAT								GetFontSize() const;
	FX_WORD									GetPasswordChar() const;
	CPDF_Point								GetScrollPos() const;
	FX_INT32								GetCharArray() const;
	CPDF_Rect								GetPlateRect() const;
	CPDF_Rect								GetContentRect() const;
	CFX_WideString							GetRangeText(const CPVT_WordRange & range) const;
	FX_INT32								GetHorzScale() const;
	FX_FLOAT								GetCharSpace() const;
	FX_INT32								GetTotalWords() const;
	FX_INT32								GetTotalLines() const;

	void									SetSel(FX_INT32 nStartChar,FX_INT32 nEndChar);
	void									GetSel(FX_INT32 & nStartChar, FX_INT32 & nEndChar) const;

private:
	void									SelectAll();
	void									SelectNone();
	void									SetSel(const CPVT_WordPlace & begin,const CPVT_WordPlace & end);
	FX_BOOL									IsSelected() const;

	void									RearrangeAll();
	void									RearrangePart(const CPVT_WordRange & range);
	void									Paint();
	void									ScrollToCaret();
	void									SetScrollInfo();
	void									SetScrollPosX(FX_FLOAT fx);
	void									SetScrollPosY(FX_FLOAT fy);
	void									SetScrollLimit();
	void									SetContentChanged();
	void									EnableNotify(FX_BOOL bNotify);

	void									SetText(FX_LPCWSTR text,FX_INT32 charset,
													const CPVT_SecProps * pSecProps,const CPVT_WordProps * pWordProps,FX_BOOL bAddUndo, FX_BOOL bPaint);	
	FX_BOOL									InsertWord(FX_WORD word, FX_INT32 charset, const CPVT_WordProps * pWordProps,FX_BOOL bAddUndo, FX_BOOL bPaint);
	FX_BOOL									InsertReturn(const CPVT_SecProps * pSecProps,const CPVT_WordProps * pWordProps,FX_BOOL bAddUndo, FX_BOOL bPaint);
	FX_BOOL									Backspace(FX_BOOL bAddUndo, FX_BOOL bPaint);
	FX_BOOL									Delete(FX_BOOL bAddUndo, FX_BOOL bPaint);		
	FX_BOOL									Clear(FX_BOOL bAddUndo, FX_BOOL bPaint);
	FX_BOOL									InsertText(FX_LPCWSTR text, FX_INT32 charset,
												const CPVT_SecProps * pSecProps,const CPVT_WordProps * pWordProps,FX_BOOL bAddUndo, FX_BOOL bPaint);
	FX_BOOL									SetRichTextProps(EDIT_PROPS_E eProps,
												const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps);
	FX_BOOL									SetSecProps(EDIT_PROPS_E eProps, const CPVT_WordPlace & place, 
												const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps, const CPVT_WordRange & wr, FX_BOOL bAddUndo);
	FX_BOOL									SetWordProps(EDIT_PROPS_E eProps, const CPVT_WordPlace & place, 
												const CPVT_WordProps * pWordProps, const CPVT_WordRange & wr, FX_BOOL bAddUndo);
	void									PaintSetProps(EDIT_PROPS_E eProps, const CPVT_WordRange & wr);
	void									PaintInsertText(const CPVT_WordPlace & wpOld, const CPVT_WordPlace & wpNew);

	inline CPDF_Point						VTToEdit(const CPDF_Point & point) const;
	inline CPDF_Point						EditToVT(const CPDF_Point & point) const;
	inline CPDF_Rect						VTToEdit(const CPDF_Rect & rect) const;
	inline CPDF_Rect						EditToVT(const CPDF_Rect & rect) const;

	void									EnableRefresh(FX_BOOL bRefresh);
	void									Refresh(REFRESH_PLAN_E ePlan,const CPVT_WordRange * pRange1 = NULL,const CPVT_WordRange * pRange2 = NULL);
	void									RefreshPushLineRects(const CPVT_WordRange & wr);
	void									RefreshPushRandomRects(const CPVT_WordRange & wr);
	void									RefreshWordRange(const CPVT_WordRange& wr);

	void									SetCaret(FX_INT32 nPos);
	void									SetCaret(const CPVT_WordPlace & place);
	void									SetCaretInfo();
	void									SetCaretOrigin();
	void									SetCaretChange();

	CPVT_WordRange							GetWholeWordRange() const;
	CPVT_WordRange							GetVisibleWordRange() const;
	CPVT_WordRange							GetLatinWordsRange(const CPVT_WordPlace & place) const;
	CPVT_WordRange							CombineWordRange(const CPVT_WordRange & wr1, const CPVT_WordRange & wr2);
	CPVT_WordRange							GetSelectWordRange() const;

	void									EnableUndo(FX_BOOL bUndo);
	void									EnableOprNotify(FX_BOOL bNotify);

	FX_BOOL									IsTextFull() const;
	FX_BOOL									IsTextOverflow() const;
	FX_BOOL									CanUndo() const;
	FX_BOOL									CanRedo() const;
	FX_BOOL									IsModified() const;

	void									BeginGroupUndo(const CFX_WideString& sTitle);
	void									EndGroupUndo();
	void									AddEditUndoItem(CFX_Edit_UndoItem* pEditUndoItem);
	void									AddUndoItem(IFX_Edit_UndoItem* pUndoItem);

	void									SetPageInfo(const CPVT_WordPlace& place);
	CPVT_WordPlace							SearchPageEndPlace(const CPVT_WordPlace& wpPageBegin, const CPDF_Point& point) const;
	FX_FLOAT								GetLineTop(const CPVT_WordPlace& place) const;
	FX_FLOAT								GetLineBottom(const CPVT_WordPlace& place) const;

private:	
	IPDF_VariableText*						m_pVT;
	IFX_Edit_Notify*						m_pNotify;
	IFX_Edit_OprNotify*						m_pOprNotify;
	CFX_Edit_Provider*						m_pVTProvide;

	CPVT_WordPlace							m_wpCaret;
	CPVT_WordPlace							m_wpOldCaret;
	CFX_Edit_Select							m_SelState;

	CPDF_Point								m_ptScrollPos;
	CPDF_Point								m_ptRefreshScrollPos;
	FX_BOOL									m_bEnableScroll;	
	IFX_Edit_Iterator *						m_pIterator;	
	CFX_Edit_Refresh						m_Refresh;
	CPDF_Point								m_ptCaret;
	CFX_Edit_Undo							m_Undo;
	FX_INT32								m_nAlignment;
	FX_BOOL									m_bNotifyFlag;
	FX_BOOL									m_bEnableOverflow;
	FX_BOOL									m_bEnableRefresh;
	CPDF_Rect								m_rcOldContent;
	FX_BOOL									m_bEnableUndo;
	FX_BOOL									m_bNotify;
	FX_BOOL									m_bOprNotify;
	CFX_Edit_GroupUndoItem*					m_pGroupUndoItem;
};

/* ------------------------- CFX_Edit_Iterator ---------------------------- */

class CFX_Edit_Iterator : public IFX_Edit_Iterator
{
public:
	CFX_Edit_Iterator(CFX_Edit * pEdit,IPDF_VariableText_Iterator * pVTIterator);
	virtual ~CFX_Edit_Iterator();

	FX_BOOL									NextWord();
	FX_BOOL									NextLine();
	FX_BOOL									NextSection();
	FX_BOOL									PrevWord();
	FX_BOOL									PrevLine();
	FX_BOOL									PrevSection();

	FX_BOOL									GetWord(CPVT_Word & word) const;
	FX_BOOL									GetLine(CPVT_Line & line) const;
	FX_BOOL									GetSection(CPVT_Section & section) const;
	void									SetAt(FX_INT32 nWordIndex);
	void									SetAt(const CPVT_WordPlace & place);
	const CPVT_WordPlace &					GetAt() const;
	IFX_Edit*								GetEdit() const;

private:
	CFX_Edit *								m_pEdit;
	IPDF_VariableText_Iterator*				m_pVTIterator;
};

class CFX_Edit_Provider : public IPDF_VariableText_Provider
{
public:
	CFX_Edit_Provider(IFX_Edit_FontMap* pFontMap);
	virtual ~CFX_Edit_Provider();

	IFX_Edit_FontMap*			GetFontMap();

	FX_INT32					GetCharWidth(FX_INT32 nFontIndex, FX_WORD word, FX_INT32 nWordStyle);
	FX_INT32					GetTypeAscent(FX_INT32 nFontIndex);
	FX_INT32					GetTypeDescent(FX_INT32 nFontIndex);
	FX_INT32					GetWordFontIndex(FX_WORD word, FX_INT32 charset, FX_INT32 nFontIndex);
	FX_INT32					GetDefaultFontIndex();
	FX_BOOL						IsLatinWord(FX_WORD word);

private:
	IFX_Edit_FontMap*			m_pFontMap;
};

#endif //_FXET_EDIT_H_