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