Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / fpdfsdk / include / pdfwindow / PWL_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 _PWL_EDIT_H_
8 #define _PWL_EDIT_H_
9
10 class IPWL_Filler_Notify;
11 class CPWL_Edit;
12 class IPWL_SpellCheck;
13
14 class IPWL_Filler_Notify
15 {
16 public:
17         virtual void                                    QueryWherePopup(void* pPrivateData, FX_FLOAT fPopupMin,FX_FLOAT fPopupMax, 
18                                                                                 FX_INT32 & nRet, FX_FLOAT & fPopupRet) = 0; //nRet: (0:bottom 1:top)
19         virtual void                                    OnBeforeKeyStroke(FX_BOOL bEditOrList, void* pPrivateData, FX_INT32 nKeyCode,
20                                                                                 CFX_WideString & strChange, const CFX_WideString& strChangeEx, 
21                                                                                 int nSelStart, int nSelEnd,
22                                                                                 FX_BOOL bKeyDown, FX_BOOL & bRC, FX_BOOL & bExit, FX_DWORD nFlag) = 0;
23         virtual void                                    OnAfterKeyStroke(FX_BOOL bEditOrList, void* pPrivateData, FX_BOOL & bExit, FX_DWORD nFlag) = 0;
24
25         virtual void                                    OnPopupPreOpen(void* pPrivateData, FX_BOOL& bExit, FX_DWORD nFlag) = 0;
26         virtual void                                    OnPopupPostOpen(void* pPrivateData, FX_BOOL& bExit, FX_DWORD nFlag) = 0;
27 };
28
29 class PWL_CLASS CPWL_Edit : public CPWL_EditCtrl, public IFX_Edit_OprNotify
30 {
31 public:
32         CPWL_Edit();
33         virtual ~CPWL_Edit();
34
35 public:
36         virtual CFX_ByteString                  GetClassName() const;
37         virtual void                                    OnDestroy();
38         virtual void                                    OnCreated();
39         virtual void                                    RePosChildWnd();
40         virtual CPDF_Rect                               GetClientRect() const;
41
42         virtual void                                    GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream);
43         virtual void                                    DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device);
44
45         virtual FX_BOOL                                 OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag);
46         virtual FX_BOOL                                 OnLButtonDblClk(const CPDF_Point & point, FX_DWORD nFlag);
47         virtual FX_BOOL                                 OnRButtonUp(const CPDF_Point & point, FX_DWORD nFlag);
48         virtual FX_BOOL                                 OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD nFlag);
49
50         virtual FX_BOOL                                 OnKeyDown(FX_WORD nChar, FX_DWORD nFlag);
51         virtual FX_BOOL                                 OnChar(FX_WORD nChar, FX_DWORD nFlag);
52
53         virtual CPDF_Rect                               GetFocusRect() const;
54
55 public:         
56         void                                                    SetAlignFormatH(PWL_EDIT_ALIGNFORMAT_H nFormat = PEAH_LEFT, FX_BOOL bPaint = TRUE);     //0:left 1:right 2:middle 
57         void                                                    SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat = PEAV_TOP, FX_BOOL bPaint = TRUE);      //0:top 1:bottom 2:center
58
59         void                                                    SetCharArray(FX_INT32 nCharArray);
60         void                                                    SetLimitChar(FX_INT32 nLimitChar);
61
62         void                                                    SetHorzScale(FX_INT32 nHorzScale, FX_BOOL bPaint = TRUE);
63         void                                                    SetCharSpace(FX_FLOAT fCharSpace, FX_BOOL bPaint = TRUE);
64
65         void                                                    SetLineLeading(FX_FLOAT fLineLeading, FX_BOOL bPaint = TRUE);
66
67         void                                                    EnableSpellCheck(FX_BOOL bEnabled);
68
69         FX_BOOL                                                 CanSelectAll() const;
70         FX_BOOL                                                 CanClear() const;
71         FX_BOOL                                                 CanCopy() const;
72         FX_BOOL                                                 CanCut() const;
73         FX_BOOL                                                 CanPaste() const;
74
75         virtual void                                    CopyText();
76         virtual void                                    PasteText();
77         virtual void                                    CutText();
78
79         virtual void                                    SetText(FX_LPCWSTR csText);
80         void                                                    ReplaceSel(FX_LPCWSTR csText);
81
82         CFX_ByteString                                  GetTextAppearanceStream(const CPDF_Point & ptOffset) const;
83         CFX_ByteString                                  GetCaretAppearanceStream(const CPDF_Point & ptOffset) const;    
84         CFX_ByteString                                  GetSelectAppearanceStream(const CPDF_Point & ptOffset) const;
85
86         FX_BOOL                                                 IsTextFull() const;     
87
88         static FX_FLOAT                                 GetCharArrayAutoFontSize(CPDF_Font* pFont, const CPDF_Rect& rcPlate, FX_INT32 nCharArray);
89
90         void                                                    SetFillerNotify(IPWL_Filler_Notify* pNotify) {m_pFillerNotify = pNotify;}
91
92         void                                                    GeneratePageObjects(CPDF_PageObjects* pPageObjects, 
93                                                                                 const CPDF_Point& ptOffset, CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray);
94         void                                                    GeneratePageObjects(CPDF_PageObjects* pPageObjects, 
95                                                                                 const CPDF_Point& ptOffset);
96
97 protected:
98         virtual void                                    OnSetFocus();
99         virtual void                                    OnKillFocus();
100
101 protected:
102         virtual void                                    OnInsertWord(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
103         virtual void                                    OnInsertReturn(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
104         virtual void                                    OnBackSpace(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
105         virtual void                                    OnDelete(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
106         virtual void                                    OnClear(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
107         virtual void                                    OnSetText(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
108         virtual void                                    OnInsertText(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
109         virtual void                                    OnAddUndo(IFX_Edit_UndoItem* pUndoItem);
110
111 private:        
112         CPVT_WordRange                                  GetSelectWordRange() const;
113         virtual void                                    ShowVScrollBar(FX_BOOL bShow);
114         FX_BOOL                                                 IsVScrollBarVisible() const;
115         void                                                    SetParamByFlag();
116
117         FX_FLOAT                                                GetCharArrayAutoFontSize(FX_INT32 nCharArray);
118         CPDF_Point                                              GetWordRightBottomPoint(const CPVT_WordPlace& wpWord);
119
120         CPVT_WordRange                                  CombineWordRange(const CPVT_WordRange& wr1, const CPVT_WordRange& wr2);
121         CPVT_WordRange                                  GetLatinWordsRange(const CPDF_Point & point) const;
122         CPVT_WordRange                                  GetLatinWordsRange(const CPVT_WordPlace & place) const;
123         CPVT_WordRange                                  GetArabicWordsRange(const CPVT_WordPlace & place) const;
124         CPVT_WordRange                                  GetSameWordsRange(const CPVT_WordPlace & place, FX_BOOL bLatin, FX_BOOL bArabic) const;
125
126         void                                                    AjustArabicWords(const CPVT_WordRange& wr);
127 public:
128         FX_BOOL                                                 IsProceedtoOnChar(FX_WORD nKeyCode, FX_DWORD nFlag);
129 private:
130         IPWL_Filler_Notify*                             m_pFillerNotify;
131         IPWL_SpellCheck*                                m_pSpellCheck;
132         FX_BOOL                                                 m_bFocus;
133         CPDF_Rect                                               m_rcOldWindow;
134 public:
135         void                                                    AttachFFLData(void* pData) {m_pFormFiller = pData;}
136 private:
137         void*                                                   m_pFormFiller;
138 };
139
140 #endif 
141