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 FPDFSDK_INCLUDE_FXEDIT_FXET_EDIT_H_
8 #define FPDFSDK_INCLUDE_FXEDIT_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
FX_EDIT_MIN(const T & i,const T & j)31 template<class T> T FX_EDIT_MIN (const T & i, const T & j) { return ((i < j) ? i : j); }
FX_EDIT_MAX(const T & i,const T & 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 {
CFX_Edit_LineRectCFX_Edit_LineRect66 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
IsSameHeightCFX_Edit_LineRect76 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
IsSameTopCFX_Edit_LineRect81 FX_BOOL IsSameTop(const CFX_Edit_LineRect & linerect) const
82 {
83 return FX_EDIT_IsFloatZero(m_rcLine.top - linerect.m_rcLine.top);
84 }
85
IsSameLeftCFX_Edit_LineRect86 FX_BOOL IsSameLeft(const CFX_Edit_LineRect & linerect) const
87 {
88 return FX_EDIT_IsFloatZero(m_rcLine.left - linerect.m_rcLine.left);
89 }
90
IsSameRightCFX_Edit_LineRect91 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:
CFX_Edit_LineRectArray()103 CFX_Edit_LineRectArray()
104 {
105 }
106
~CFX_Edit_LineRectArray()107 virtual ~CFX_Edit_LineRectArray()
108 {
109 Empty();
110 }
111
Empty()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
RemoveAll()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
Add(const CPVT_WordRange & wrLine,const CPDF_Rect & rcLine)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
GetSize()140 FX_INT32 GetSize() const
141 {
142 return m_LineRects.GetSize();
143 }
144
GetAt(FX_INT32 nIndex)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:
CFX_Edit_RectArray()159 CFX_Edit_RectArray()
160 {
161 }
162
~CFX_Edit_RectArray()163 virtual ~CFX_Edit_RectArray()
164 {
165 this->Empty();
166 }
167
Empty()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
Add(const CPDF_Rect & rect)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
GetSize()187 FX_INT32 GetSize() const
188 {
189 return m_Rects.GetSize();
190 }
191
GetAt(FX_INT32 nIndex)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:
CFX_Edit_Select()229 CFX_Edit_Select()
230 {
231 }
232
CFX_Edit_Select(const CPVT_WordPlace & begin,const CPVT_WordPlace & end)233 CFX_Edit_Select(const CPVT_WordPlace & begin,const CPVT_WordPlace & end)
234 {
235 Set(begin,end);
236 }
237
CFX_Edit_Select(const CPVT_WordRange & range)238 CFX_Edit_Select(const CPVT_WordRange & range)
239 {
240 Set(range.BeginPos,range.EndPos);
241 }
242
ConvertToWordRange()243 CPVT_WordRange ConvertToWordRange() const
244 {
245 return CPVT_WordRange(this->BeginPos,this->EndPos);
246 }
247
Default()248 void Default()
249 {
250 BeginPos.Default();
251 EndPos.Default();
252 }
253
Set(const CPVT_WordPlace & begin,const CPVT_WordPlace & end)254 void Set(const CPVT_WordPlace & begin,const CPVT_WordPlace & end)
255 {
256 this->BeginPos = begin;
257 this->EndPos = end;
258 }
259
SetBeginPos(const CPVT_WordPlace & begin)260 void SetBeginPos(const CPVT_WordPlace & begin)
261 {
262 this->BeginPos = begin;
263 }
264
SetEndPos(const CPVT_WordPlace & end)265 void SetEndPos(const CPVT_WordPlace & end)
266 {
267 this->EndPos = end;
268 }
269
IsExist()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);
GetItemCount()304 FX_INT32 GetItemCount(){return m_UndoItemStack.GetSize();}
GetCurUndoPos()305 FX_INT32 GetCurUndoPos(){return m_nCurUndoPos;}
306
307 private:
SetBufSize(FX_INT32 nSize)308 void SetBufSize(FX_INT32 nSize){m_nBufSize = nSize;}
GetBufSize()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:
CFX_Edit_UndoItem()327 CFX_Edit_UndoItem() : m_bFirst(TRUE), m_bLast(TRUE) {}
328
GetUndoTitle()329 CFX_WideString GetUndoTitle() override { return L""; }
330
SetFirst(FX_BOOL bFirst)331 void SetFirst(FX_BOOL bFirst){m_bFirst = bFirst;}
IsFirst()332 FX_BOOL IsFirst(){return m_bFirst;}
SetLast(FX_BOOL bLast)333 void SetLast(FX_BOOL bLast){m_bLast = bLast;}
IsLast()334 FX_BOOL IsLast(){return m_bLast;}
335
336 private:
337 FX_BOOL m_bFirst;
338 FX_BOOL m_bLast;
339 };
340
341 class CFX_Edit_GroupUndoItem : public IFX_Edit_UndoItem
342 {
343 public:
344 CFX_Edit_GroupUndoItem(const CFX_WideString& sTitle);
345 ~CFX_Edit_GroupUndoItem() override;
346
347 void Undo() override;
348 void Redo() override;
349 CFX_WideString GetUndoTitle() override;
350
351 void AddUndoItem(CFX_Edit_UndoItem* pUndoItem);
352 void UpdateItems();
353
354 private:
355 CFX_WideString m_sTitle;
356 CFX_ArrayTemplate<CFX_Edit_UndoItem*> m_Items;
357 };
358
359 /* ------------------------- CFX_Edit_UndoItem derived classes ---------------------------- */
360
361 class CFXEU_InsertWord : public CFX_Edit_UndoItem
362 {
363 public:
364 CFXEU_InsertWord(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
365 FX_WORD word, FX_INT32 charset, const CPVT_WordProps * pWordProps);
366 virtual ~CFXEU_InsertWord();
367
368 void Redo();
369 void Undo();
370
371 private:
372 CFX_Edit* m_pEdit;
373
374 CPVT_WordPlace m_wpOld;
375 CPVT_WordPlace m_wpNew;
376 FX_WORD m_Word;
377 FX_INT32 m_nCharset;
378 CPVT_WordProps m_WordProps;
379 };
380
381 class CFXEU_InsertReturn : public CFX_Edit_UndoItem
382 {
383 public:
384 CFXEU_InsertReturn(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
385 const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps);
386 virtual ~CFXEU_InsertReturn();
387
388 void Redo();
389 void Undo();
390
391 private:
392 CFX_Edit * m_pEdit;
393
394 CPVT_WordPlace m_wpOld;
395 CPVT_WordPlace m_wpNew;
396 CPVT_SecProps m_SecProps;
397 CPVT_WordProps m_WordProps;
398 };
399
400 class CFXEU_Backspace : public CFX_Edit_UndoItem
401 {
402 public:
403 CFXEU_Backspace(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
404 FX_WORD word, FX_INT32 charset,
405 const CPVT_SecProps & SecProps, const CPVT_WordProps & WordProps);
406 virtual ~CFXEU_Backspace();
407
408 void Redo();
409 void Undo();
410
411 private:
412 CFX_Edit * m_pEdit;
413
414 CPVT_WordPlace m_wpOld;
415 CPVT_WordPlace m_wpNew;
416 FX_WORD m_Word;
417 FX_INT32 m_nCharset;
418 CPVT_SecProps m_SecProps;
419 CPVT_WordProps m_WordProps;
420 };
421
422 class CFXEU_Delete : public CFX_Edit_UndoItem
423 {
424 public:
425 CFXEU_Delete(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
426 FX_WORD word, FX_INT32 charset,
427 const CPVT_SecProps & SecProps, const CPVT_WordProps & WordProps, FX_BOOL bSecEnd);
428 virtual ~CFXEU_Delete();
429
430 void Redo();
431 void Undo();
432
433 private:
434 CFX_Edit * m_pEdit;
435
436 CPVT_WordPlace m_wpOld;
437 CPVT_WordPlace m_wpNew;
438 FX_WORD m_Word;
439 FX_INT32 m_nCharset;
440 CPVT_SecProps m_SecProps;
441 CPVT_WordProps m_WordProps;
442 FX_BOOL m_bSecEnd;
443 };
444
445 class CFXEU_Clear : public CFX_Edit_UndoItem
446 {
447 public:
448 CFXEU_Clear(CFX_Edit * pEdit, const CPVT_WordRange & wrSel, const CFX_WideString & swText);
449 virtual ~CFXEU_Clear();
450
451 void Redo();
452 void Undo();
453
454 private:
455 CFX_Edit* m_pEdit;
456
457 CPVT_WordRange m_wrSel;
458 CFX_WideString m_swText;
459 };
460
461 class CFXEU_ClearRich : public CFX_Edit_UndoItem
462 {
463 public:
464 CFXEU_ClearRich(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
465 const CPVT_WordRange & wrSel,
466 FX_WORD word, FX_INT32 charset,
467 const CPVT_SecProps & SecProps, const CPVT_WordProps & WordProps);
468 virtual ~CFXEU_ClearRich();
469
470 void Redo();
471 void Undo();
472
473 private:
474 CFX_Edit * m_pEdit;
475
476 CPVT_WordPlace m_wpOld;
477 CPVT_WordPlace m_wpNew;
478 CPVT_WordRange m_wrSel;
479 FX_WORD m_Word;
480 FX_INT32 m_nCharset;
481 CPVT_SecProps m_SecProps;
482 CPVT_WordProps m_WordProps;
483 };
484
485 class CFXEU_InsertText : public CFX_Edit_UndoItem
486 {
487 public:
488 CFXEU_InsertText(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace, const CPVT_WordPlace & wpNewPlace,
489 const CFX_WideString & swText, FX_INT32 charset,
490 const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps);
491 virtual ~CFXEU_InsertText();
492
493 void Redo();
494 void Undo();
495
496 private:
497 CFX_Edit * m_pEdit;
498
499 CPVT_WordPlace m_wpOld;
500 CPVT_WordPlace m_wpNew;
501 CFX_WideString m_swText;
502 FX_INT32 m_nCharset;
503 CPVT_SecProps m_SecProps;
504 CPVT_WordProps m_WordProps;
505 };
506
507 class CFXEU_SetSecProps : public CFX_Edit_UndoItem
508 {
509 public:
510 CFXEU_SetSecProps(CFX_Edit * pEdit, const CPVT_WordPlace & place, EDIT_PROPS_E ep,
511 const CPVT_SecProps & oldsecprops, const CPVT_WordProps & oldwordprops,
512 const CPVT_SecProps & newsecprops, const CPVT_WordProps & newwordprops, const CPVT_WordRange & range);
513 virtual ~CFXEU_SetSecProps();
514
515 void Redo();
516 void Undo();
517
518 private:
519 CFX_Edit * m_pEdit;
520 CPVT_WordPlace m_wpPlace;
521 CPVT_WordRange m_wrPlace;
522 EDIT_PROPS_E m_eProps;
523
524 CPVT_SecProps m_OldSecProps;
525 CPVT_SecProps m_NewSecProps;
526 CPVT_WordProps m_OldWordProps;
527 CPVT_WordProps m_NewWordProps;
528 };
529
530 class CFXEU_SetWordProps : public CFX_Edit_UndoItem
531 {
532 public:
533 CFXEU_SetWordProps(CFX_Edit * pEdit, const CPVT_WordPlace & place, EDIT_PROPS_E ep,
534 const CPVT_WordProps & oldprops, const CPVT_WordProps & newprops, const CPVT_WordRange & range);
535 virtual ~CFXEU_SetWordProps();
536
537 void Redo();
538 void Undo();
539
540 private:
541 CFX_Edit * m_pEdit;
542 CPVT_WordPlace m_wpPlace;
543 CPVT_WordRange m_wrPlace;
544 EDIT_PROPS_E m_eProps;
545
546 CPVT_WordProps m_OldWordProps;
547 CPVT_WordProps m_NewWordProps;
548 };
549
550 /* ------------------------- CFX_Edit ---------------------------- */
551
552 class CFX_Edit : public IFX_Edit
553 {
554 friend class CFX_Edit_Iterator;
555 friend class CFXEU_InsertWord;
556 friend class CFXEU_InsertReturn;
557 friend class CFXEU_Backspace;
558 friend class CFXEU_Delete;
559 friend class CFXEU_Clear;
560 friend class CFXEU_ClearRich;
561 friend class CFXEU_SetSecProps;
562 friend class CFXEU_SetWordProps;
563 friend class CFXEU_InsertText;
564
565 public:
566 CFX_Edit(IPDF_VariableText * pVT);
567 virtual ~CFX_Edit();
568
569 void SetFontMap(IFX_Edit_FontMap * pFontMap);
570 void SetVTProvider(IPDF_VariableText_Provider* pProvider);
571 void SetNotify(IFX_Edit_Notify * pNotify);
572 void SetOprNotify(IFX_Edit_OprNotify* pOprNotify);
573 IFX_Edit_Iterator* GetIterator();
574 IPDF_VariableText * GetVariableText();
575 IFX_Edit_FontMap* GetFontMap();
576
577 void Initialize();
578 void SetPlateRect(const CPDF_Rect & rect, FX_BOOL bPaint = TRUE);
579 void SetScrollPos(const CPDF_Point & point);
580
581 void SetAlignmentH(FX_INT32 nFormat = 0, FX_BOOL bPaint = TRUE);
582 void SetAlignmentV(FX_INT32 nFormat = 0, FX_BOOL bPaint = TRUE);
583 void SetPasswordChar(FX_WORD wSubWord = '*', FX_BOOL bPaint = TRUE);
584 void SetLimitChar(FX_INT32 nLimitChar = 0, FX_BOOL bPaint = TRUE);
585 void SetCharArray(FX_INT32 nCharArray = 0, FX_BOOL bPaint = TRUE);
586 void SetCharSpace(FX_FLOAT fCharSpace = 0.0f, FX_BOOL bPaint = TRUE);
587 void SetHorzScale(FX_INT32 nHorzScale = 100, FX_BOOL bPaint = TRUE);
588 void SetLineLeading(FX_FLOAT fLineLeading, FX_BOOL bPaint = TRUE);
589 void SetMultiLine(FX_BOOL bMultiLine = TRUE, FX_BOOL bPaint = TRUE);
590 void SetAutoReturn(FX_BOOL bAuto = TRUE, FX_BOOL bPaint = TRUE);
591 void SetAutoFontSize(FX_BOOL bAuto = TRUE, FX_BOOL bPaint = TRUE);
592 void SetAutoScroll(FX_BOOL bAuto = TRUE, FX_BOOL bPaint = TRUE);
593 void SetFontSize(FX_FLOAT fFontSize, FX_BOOL bPaint = TRUE);
594 void SetTextOverflow(FX_BOOL bAllowed = FALSE, FX_BOOL bPaint = TRUE);
595
596 FX_BOOL IsRichText() const;
597 void SetRichText(FX_BOOL bRichText = TRUE, FX_BOOL bPaint = TRUE);
598 FX_BOOL SetRichFontSize(FX_FLOAT fFontSize);
599 FX_BOOL SetRichFontIndex(FX_INT32 nFontIndex);
600 FX_BOOL SetRichTextColor(FX_COLORREF dwColor);
601 FX_BOOL SetRichTextScript(FX_INT32 nScriptType);
602 FX_BOOL SetRichTextBold(FX_BOOL bBold = TRUE);
603 FX_BOOL SetRichTextItalic(FX_BOOL bItalic = TRUE);
604 FX_BOOL SetRichTextUnderline(FX_BOOL bUnderline = TRUE);
605 FX_BOOL SetRichTextCrossout(FX_BOOL bCrossout = TRUE);
606 FX_BOOL SetRichTextCharSpace(FX_FLOAT fCharSpace);
607 FX_BOOL SetRichTextHorzScale(FX_INT32 nHorzScale = 100);
608 FX_BOOL SetRichTextLineLeading(FX_FLOAT fLineLeading);
609 FX_BOOL SetRichTextLineIndent(FX_FLOAT fLineIndent);
610 FX_BOOL SetRichTextAlignment(FX_INT32 nAlignment);
611
612 void OnMouseDown(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl);
613 void OnMouseMove(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl);
614 void OnVK_UP(FX_BOOL bShift,FX_BOOL bCtrl);
615 void OnVK_DOWN(FX_BOOL bShift,FX_BOOL bCtrl);
616 void OnVK_LEFT(FX_BOOL bShift,FX_BOOL bCtrl);
617 void OnVK_RIGHT(FX_BOOL bShift,FX_BOOL bCtrl);
618 void OnVK_HOME(FX_BOOL bShift,FX_BOOL bCtrl);
619 void OnVK_END(FX_BOOL bShift,FX_BOOL bCtrl);
620
621 void SetText(FX_LPCWSTR text,FX_INT32 charset = DEFAULT_CHARSET,
622 const CPVT_SecProps * pSecProps = NULL,const CPVT_WordProps * pWordProps = NULL);
623 FX_BOOL InsertWord(FX_WORD word, FX_INT32 charset = DEFAULT_CHARSET, const CPVT_WordProps * pWordProps = NULL);
624 FX_BOOL InsertReturn(const CPVT_SecProps * pSecProps = NULL,const CPVT_WordProps * pWordProps = NULL);
625 FX_BOOL Backspace();
626 FX_BOOL Delete();
627 FX_BOOL Clear();
628 FX_BOOL Empty();
629 FX_BOOL InsertText(FX_LPCWSTR text, FX_INT32 charset = DEFAULT_CHARSET,
630 const CPVT_SecProps * pSecProps = NULL,const CPVT_WordProps * pWordProps = NULL);
631 FX_BOOL Redo();
632 FX_BOOL Undo();
633 CPVT_WordPlace DoInsertText(const CPVT_WordPlace& place, FX_LPCWSTR text, FX_INT32 charset,
634 const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps);
635 FX_INT32 GetCharSetFromUnicode(FX_WORD word, FX_INT32 nOldCharset);
636
637 FX_INT32 WordPlaceToWordIndex(const CPVT_WordPlace & place) const;
638 CPVT_WordPlace WordIndexToWordPlace(FX_INT32 index) const;
639
640 CPVT_WordPlace GetLineBeginPlace(const CPVT_WordPlace & place) const;
641 CPVT_WordPlace GetLineEndPlace(const CPVT_WordPlace & place) const;
642 CPVT_WordPlace GetSectionBeginPlace(const CPVT_WordPlace & place) const;
643 CPVT_WordPlace GetSectionEndPlace(const CPVT_WordPlace & place) const;
644 CPVT_WordPlace SearchWordPlace(const CPDF_Point& point) const;
645
646 FX_INT32 GetCaret() const;
647 CPVT_WordPlace GetCaretWordPlace() const;
648 CFX_WideString GetSelText() const;
649 CFX_WideString GetText() const;
650 FX_FLOAT GetFontSize() const;
651 FX_WORD GetPasswordChar() const;
652 CPDF_Point GetScrollPos() const;
653 FX_INT32 GetCharArray() const;
654 CPDF_Rect GetPlateRect() const;
655 CPDF_Rect GetContentRect() const;
656 CFX_WideString GetRangeText(const CPVT_WordRange & range) const;
657 FX_INT32 GetHorzScale() const;
658 FX_FLOAT GetCharSpace() const;
659 FX_INT32 GetTotalWords() const;
660 FX_INT32 GetTotalLines() const;
661
662 void SetSel(FX_INT32 nStartChar,FX_INT32 nEndChar);
663 void GetSel(FX_INT32 & nStartChar, FX_INT32 & nEndChar) const;
664
665 private:
666 void SelectAll();
667 void SelectNone();
668 void SetSel(const CPVT_WordPlace & begin,const CPVT_WordPlace & end);
669 FX_BOOL IsSelected() const;
670
671 void RearrangeAll();
672 void RearrangePart(const CPVT_WordRange & range);
673 void Paint();
674 void ScrollToCaret();
675 void SetScrollInfo();
676 void SetScrollPosX(FX_FLOAT fx);
677 void SetScrollPosY(FX_FLOAT fy);
678 void SetScrollLimit();
679 void SetContentChanged();
680 void EnableNotify(FX_BOOL bNotify);
681
682 void SetText(FX_LPCWSTR text,FX_INT32 charset,
683 const CPVT_SecProps * pSecProps,const CPVT_WordProps * pWordProps,FX_BOOL bAddUndo, FX_BOOL bPaint);
684 FX_BOOL InsertWord(FX_WORD word, FX_INT32 charset, const CPVT_WordProps * pWordProps,FX_BOOL bAddUndo, FX_BOOL bPaint);
685 FX_BOOL InsertReturn(const CPVT_SecProps * pSecProps,const CPVT_WordProps * pWordProps,FX_BOOL bAddUndo, FX_BOOL bPaint);
686 FX_BOOL Backspace(FX_BOOL bAddUndo, FX_BOOL bPaint);
687 FX_BOOL Delete(FX_BOOL bAddUndo, FX_BOOL bPaint);
688 FX_BOOL Clear(FX_BOOL bAddUndo, FX_BOOL bPaint);
689 FX_BOOL InsertText(FX_LPCWSTR text, FX_INT32 charset,
690 const CPVT_SecProps * pSecProps,const CPVT_WordProps * pWordProps,FX_BOOL bAddUndo, FX_BOOL bPaint);
691 FX_BOOL SetRichTextProps(EDIT_PROPS_E eProps,
692 const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps);
693 FX_BOOL SetSecProps(EDIT_PROPS_E eProps, const CPVT_WordPlace & place,
694 const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps, const CPVT_WordRange & wr, FX_BOOL bAddUndo);
695 FX_BOOL SetWordProps(EDIT_PROPS_E eProps, const CPVT_WordPlace & place,
696 const CPVT_WordProps * pWordProps, const CPVT_WordRange & wr, FX_BOOL bAddUndo);
697 void PaintSetProps(EDIT_PROPS_E eProps, const CPVT_WordRange & wr);
698 void PaintInsertText(const CPVT_WordPlace & wpOld, const CPVT_WordPlace & wpNew);
699
700 inline CPDF_Point VTToEdit(const CPDF_Point & point) const;
701 inline CPDF_Point EditToVT(const CPDF_Point & point) const;
702 inline CPDF_Rect VTToEdit(const CPDF_Rect & rect) const;
703 inline CPDF_Rect EditToVT(const CPDF_Rect & rect) const;
704
705 void EnableRefresh(FX_BOOL bRefresh);
706 void Refresh(REFRESH_PLAN_E ePlan,const CPVT_WordRange * pRange1 = NULL,const CPVT_WordRange * pRange2 = NULL);
707 void RefreshPushLineRects(const CPVT_WordRange & wr);
708 void RefreshPushRandomRects(const CPVT_WordRange & wr);
709 void RefreshWordRange(const CPVT_WordRange& wr);
710
711 void SetCaret(FX_INT32 nPos);
712 void SetCaret(const CPVT_WordPlace & place);
713 void SetCaretInfo();
714 void SetCaretOrigin();
715 void SetCaretChange();
716
717 CPVT_WordRange GetWholeWordRange() const;
718 CPVT_WordRange GetVisibleWordRange() const;
719 CPVT_WordRange GetLatinWordsRange(const CPVT_WordPlace & place) const;
720 CPVT_WordRange CombineWordRange(const CPVT_WordRange & wr1, const CPVT_WordRange & wr2);
721 CPVT_WordRange GetSelectWordRange() const;
722
723 void EnableUndo(FX_BOOL bUndo);
724 void EnableOprNotify(FX_BOOL bNotify);
725
726 FX_BOOL IsTextFull() const;
727 FX_BOOL IsTextOverflow() const;
728 FX_BOOL CanUndo() const;
729 FX_BOOL CanRedo() const;
730 FX_BOOL IsModified() const;
731
732 void BeginGroupUndo(const CFX_WideString& sTitle);
733 void EndGroupUndo();
734 void AddEditUndoItem(CFX_Edit_UndoItem* pEditUndoItem);
735 void AddUndoItem(IFX_Edit_UndoItem* pUndoItem);
736
737 void SetPageInfo(const CPVT_WordPlace& place);
738 CPVT_WordPlace SearchPageEndPlace(const CPVT_WordPlace& wpPageBegin, const CPDF_Point& point) const;
739 FX_FLOAT GetLineTop(const CPVT_WordPlace& place) const;
740 FX_FLOAT GetLineBottom(const CPVT_WordPlace& place) const;
741
742 private:
743 IPDF_VariableText* m_pVT;
744 IFX_Edit_Notify* m_pNotify;
745 IFX_Edit_OprNotify* m_pOprNotify;
746 CFX_Edit_Provider* m_pVTProvide;
747
748 CPVT_WordPlace m_wpCaret;
749 CPVT_WordPlace m_wpOldCaret;
750 CFX_Edit_Select m_SelState;
751
752 CPDF_Point m_ptScrollPos;
753 CPDF_Point m_ptRefreshScrollPos;
754 FX_BOOL m_bEnableScroll;
755 IFX_Edit_Iterator * m_pIterator;
756 CFX_Edit_Refresh m_Refresh;
757 CPDF_Point m_ptCaret;
758 CFX_Edit_Undo m_Undo;
759 FX_INT32 m_nAlignment;
760 FX_BOOL m_bNotifyFlag;
761 FX_BOOL m_bEnableOverflow;
762 FX_BOOL m_bEnableRefresh;
763 CPDF_Rect m_rcOldContent;
764 FX_BOOL m_bEnableUndo;
765 FX_BOOL m_bNotify;
766 FX_BOOL m_bOprNotify;
767 CFX_Edit_GroupUndoItem* m_pGroupUndoItem;
768 };
769
770 /* ------------------------- CFX_Edit_Iterator ---------------------------- */
771
772 class CFX_Edit_Iterator : public IFX_Edit_Iterator
773 {
774 public:
775 CFX_Edit_Iterator(CFX_Edit * pEdit,IPDF_VariableText_Iterator * pVTIterator);
776 virtual ~CFX_Edit_Iterator();
777
778 FX_BOOL NextWord();
779 FX_BOOL NextLine();
780 FX_BOOL NextSection();
781 FX_BOOL PrevWord();
782 FX_BOOL PrevLine();
783 FX_BOOL PrevSection();
784
785 FX_BOOL GetWord(CPVT_Word & word) const;
786 FX_BOOL GetLine(CPVT_Line & line) const;
787 FX_BOOL GetSection(CPVT_Section & section) const;
788 void SetAt(FX_INT32 nWordIndex);
789 void SetAt(const CPVT_WordPlace & place);
790 const CPVT_WordPlace & GetAt() const;
791 IFX_Edit* GetEdit() const;
792
793 private:
794 CFX_Edit * m_pEdit;
795 IPDF_VariableText_Iterator* m_pVTIterator;
796 };
797
798 class CFX_Edit_Provider : public IPDF_VariableText_Provider
799 {
800 public:
801 CFX_Edit_Provider(IFX_Edit_FontMap* pFontMap);
802 virtual ~CFX_Edit_Provider();
803
804 IFX_Edit_FontMap* GetFontMap();
805
806 FX_INT32 GetCharWidth(FX_INT32 nFontIndex, FX_WORD word, FX_INT32 nWordStyle);
807 FX_INT32 GetTypeAscent(FX_INT32 nFontIndex);
808 FX_INT32 GetTypeDescent(FX_INT32 nFontIndex);
809 FX_INT32 GetWordFontIndex(FX_WORD word, FX_INT32 charset, FX_INT32 nFontIndex);
810 FX_INT32 GetDefaultFontIndex();
811 FX_BOOL IsLatinWord(FX_WORD word);
812
813 private:
814 IFX_Edit_FontMap* m_pFontMap;
815 };
816
817 #endif // FPDFSDK_INCLUDE_FXEDIT_FXET_EDIT_H_
818