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