Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fwl / src / basewidget / include / fwl_editimp.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 _FWL_EDIT_IMP_H\r
8 #define _FWL_EDIT_IMP_H\r
9 class CFWL_WidgetImp;\r
10 class CFWL_WidgetImpProperties;\r
11 class CFWL_WidgetImpDelegate;\r
12 class CFWL_ScrollBarImp;\r
13 class IFWL_Caret;\r
14 class IFWL_AdapterTextField;\r
15 class CFWL_EditImp;\r
16 class CFWL_EditImpDelegate;\r
17 class CFWL_EditImp : public CFWL_WidgetImp, public IFDE_TxtEdtEventSink\r
18 {\r
19 public:\r
20     CFWL_EditImp(IFWL_Widget *pOuter = NULL);\r
21     CFWL_EditImp(const CFWL_WidgetImpProperties &properties, IFWL_Widget *pOuter = NULL);\r
22     ~CFWL_EditImp();\r
23     virtual FWL_ERR             GetClassName(CFX_WideString &wsClass) const;\r
24     virtual FX_DWORD    GetClassID() const;\r
25     virtual FWL_ERR             Initialize();\r
26     virtual FWL_ERR             Finalize();\r
27     virtual FWL_ERR             GetWidgetRect(CFX_RectF &rect, FX_BOOL bAutoSize = FALSE);\r
28     virtual FWL_ERR             SetWidgetRect(const CFX_RectF &rect);\r
29     virtual     FWL_ERR         Update();\r
30     virtual FX_DWORD    HitTest(FX_FLOAT fx, FX_FLOAT fy);\r
31     virtual FWL_ERR             SetStates(FX_DWORD dwStates, FX_BOOL bSet = TRUE);\r
32     virtual FWL_ERR             DrawWidget(CFX_Graphics *pGraphics, const CFX_Matrix *pMatrix = NULL);\r
33     virtual FWL_ERR             SetThemeProvider(IFWL_ThemeProvider *pThemeProvider);\r
34     virtual FWL_ERR             SetText(const CFX_WideString &wsText);\r
35     virtual FX_INT32    GetTextLength() const;\r
36     virtual FWL_ERR             GetText(CFX_WideString &wsText, FX_INT32 nStart = 0, FX_INT32 nCount = -1) const;\r
37     virtual FWL_ERR             ClearText();\r
38     virtual FX_INT32    GetCaretPos() const;\r
39     virtual FX_INT32    SetCaretPos(FX_INT32 nIndex, FX_BOOL bBefore = TRUE);\r
40     virtual FWL_ERR             AddSelRange(FX_INT32 nStart, FX_INT32 nCount = -1);\r
41     virtual FX_INT32    CountSelRanges();\r
42     virtual FX_INT32    GetSelRange(FX_INT32 nIndex, FX_INT32 &nStart);\r
43     virtual FWL_ERR             ClearSelections();\r
44     virtual FX_INT32    GetLimit();\r
45     virtual FWL_ERR             SetLimit(FX_INT32 nLimit);\r
46     virtual FWL_ERR             SetAliasChar(FX_WCHAR wAlias);\r
47     virtual FWL_ERR             SetFormatString(const CFX_WideString &wsFormat);\r
48     virtual FWL_ERR             Insert(FX_INT32 nStart, FX_LPCWSTR lpText, FX_INT32 nLen);\r
49     virtual FWL_ERR             DeleteSelections();\r
50     virtual FWL_ERR             DeleteRange(FX_INT32 nStart, FX_INT32 nCount = -1);\r
51     virtual FWL_ERR             ReplaceSelections(const CFX_WideStringC &wsReplace);\r
52     virtual FWL_ERR             Replace(FX_INT32 nStart, FX_INT32 nLen, const CFX_WideStringC &wsReplace);\r
53     virtual FWL_ERR             DoClipboard(FX_INT32 iCmd);\r
54     virtual FX_BOOL             Copy(CFX_WideString &wsCopy);\r
55     virtual FX_BOOL             Cut(CFX_WideString &wsCut);\r
56     virtual FX_BOOL             Paste(const CFX_WideString &wsPaste);\r
57     virtual FX_BOOL             Delete();\r
58     virtual FX_BOOL             Redo(FX_BSTR bsRecord);\r
59     virtual FX_BOOL             Undo(FX_BSTR bsRecord);\r
60     virtual FX_BOOL             Undo();\r
61     virtual FX_BOOL             Redo();\r
62     virtual FX_BOOL             CanUndo();\r
63     virtual FX_BOOL             CanRedo();\r
64     virtual FWL_ERR             SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant);\r
65     virtual FWL_ERR             SetOuter(IFWL_Widget *pOuter);\r
66     virtual FWL_ERR             SetNumberRange(FX_INT32 iMin, FX_INT32 iMax);\r
67     virtual void                On_CaretChanged(IFDE_TxtEdtEngine *pEdit, FX_INT32 nPage, FX_BOOL bVisible = TRUE);\r
68     virtual void                On_TextChanged(IFDE_TxtEdtEngine * pEdit, FDE_TXTEDT_TEXTCHANGE_INFO &ChangeInfo);\r
69     virtual void                On_PageCountChanged(IFDE_TxtEdtEngine *pEdit) {}\r
70     virtual void                On_SelChanged(IFDE_TxtEdtEngine *pEdit);\r
71     virtual FX_BOOL             On_PageLoad(IFDE_TxtEdtEngine *pEdit, FX_INT32 nPageIndex, FX_INT32 nPurpose);\r
72     virtual FX_BOOL             On_PageUnload(IFDE_TxtEdtEngine *pEdit, FX_INT32 nPageIndex, FX_INT32 nPurpose);\r
73     virtual FX_BOOL             On_PageChange(IFDE_TxtEdtEngine *pEdit, FX_BOOL bPageUp = TRUE)\r
74     {\r
75         return TRUE;\r
76     }\r
77     virtual void                On_AddDoRecord(IFDE_TxtEdtEngine *pEdit, FX_BSTR bsDoRecord);\r
78     virtual FX_BOOL             On_ValidateField(IFDE_TxtEdtEngine *pEdit, FX_INT32 nBlockIndex, FX_INT32 nFieldIndex, \\r
79                                          const CFX_WideString &wsFieldText, FX_INT32 nCharIndex);\r
80     virtual FX_BOOL             On_ValidateBlock(IFDE_TxtEdtEngine *pEdit, FX_INT32 nBlockIndex);\r
81     virtual FX_BOOL             On_GetBlockFormatText(IFDE_TxtEdtEngine *pEdit, FX_INT32 nBlockIndex, CFX_WideString &wsBlockText);\r
82     virtual FX_BOOL             On_Validate(IFDE_TxtEdtEngine * pEdit, CFX_WideString &wsText);\r
83     virtual FWL_ERR     SetBackgroundColor(FX_DWORD color);\r
84     virtual FWL_ERR     SetFont(const CFX_WideString &wsFont, FX_FLOAT fSize);\r
85     void                                SetScrollOffset(FX_FLOAT fScrollOffset);\r
86     FX_BOOL                             GetSuggestWords(CFX_PointF pointf, CFX_ByteStringArray &sSuggest);\r
87     FX_BOOL                             ReplaceSpellCheckWord(CFX_PointF pointf, FX_BSTR bsReplace);\r
88 protected:\r
89     void                                DrawTextBk(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix = NULL);\r
90     void                                DrawContent(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix = NULL);\r
91     void                                UpdateEditEngine();\r
92     void                                UpdateEditParams();\r
93     void                                UpdateEditLayout();\r
94     FX_BOOL                             UpdateOffset();\r
95     FX_BOOL                             UpdateOffset(IFWL_ScrollBar *pScrollBar, FX_FLOAT fPosChanged);\r
96     void                                UpdateVAlignment();\r
97     void                                UpdateCaret();\r
98     IFWL_ScrollBar*             UpdateScroll();\r
99     void                                Layout();\r
100     void                                LayoutScrollBar();\r
101     void                                DeviceToEngine(CFX_PointF &pt);\r
102     void                                InitScrollBar(FX_BOOL bVert = TRUE);\r
103     void                                InitEngine();\r
104     virtual     void            ShowCaret(FX_BOOL bVisible, CFX_RectF *pRect = NULL);\r
105     FX_BOOL                             ValidateNumberChar(FX_WCHAR cNum);\r
106     void                                InitCaret();\r
107     void                                ClearRecord();\r
108     FX_BOOL                             IsShowScrollBar(FX_BOOL bVert);\r
109     FX_BOOL                             IsContentHeightOverflow();\r
110     FX_INT32                    AddDoRecord(FX_BSTR bsDoRecord);\r
111     void                                ProcessInsertError(FX_INT32 iError);\r
112 \r
113     void                                DrawSpellCheck(CFX_Graphics *pGraphics, const CFX_Matrix *pMatrix = NULL);\r
114     void                                AddSpellCheckObj(CFX_Path& PathData, FX_INT32 nStart, FX_INT32 nCount, FX_FLOAT fOffSetX, FX_FLOAT fOffSetY);\r
115     FX_INT32                    GetWordAtPoint(CFX_PointF pointf, FX_INT32& nCount);\r
116     CFX_RectF                   m_rtClient;\r
117     CFX_RectF                   m_rtEngine;\r
118     CFX_RectF                   m_rtStatic;\r
119     FX_FLOAT                    m_fVAlignOffset;\r
120     FX_FLOAT                    m_fScrollOffsetX;\r
121     FX_FLOAT                    m_fScrollOffsetY;\r
122     IFDE_TxtEdtEngine*  m_pEdtEngine;\r
123     FX_BOOL                             m_bLButtonDown;\r
124     FX_INT32                    m_nSelStart;\r
125     FX_INT32                    m_nLimit;\r
126     FX_FLOAT                    m_fSpaceAbove;\r
127     FX_FLOAT                    m_fSpaceBelow;\r
128     FX_FLOAT                    m_fFontSize;\r
129     FX_ARGB                             m_argbSel;\r
130     FX_BOOL             m_bSetRange;\r
131     FX_INT32                    m_iMin;\r
132     FX_INT32                    m_iMax;\r
133     IFWL_ScrollBar*             m_pVertScrollBar;\r
134     IFWL_ScrollBar*             m_pHorzScrollBar;\r
135     IFWL_Caret*                 m_pCaret;\r
136     IFWL_AdapterTextField*      m_pTextField;\r
137     CFX_WideString                      m_wsCache;\r
138     friend class CFWL_TxtEdtEventSink;\r
139     friend class CFWL_EditImpDelegate;\r
140     FX_DWORD            m_backColor;\r
141     FX_BOOL             m_updateBackColor;\r
142     CFX_WideString      m_wsFont;\r
143     CFX_ByteStringArray m_RecordArr;\r
144     FX_INT32                    m_iCurRecord;\r
145     FX_INT32                    m_iMaxRecord;\r
146 };\r
147 class CFWL_EditImpDelegate : public CFWL_WidgetImpDelegate\r
148 {\r
149 public:\r
150     CFWL_EditImpDelegate(CFWL_EditImp *pOwner);\r
151     virtual FX_INT32    OnProcessMessage(CFWL_Message *pMessage);\r
152     virtual FWL_ERR             OnProcessEvent(CFWL_Event *pEvent);\r
153     virtual FWL_ERR             OnDrawWidget(CFX_Graphics *pGraphics, const CFX_Matrix *pMatrix = NULL);\r
154 protected:\r
155     void    DoActivate(CFWL_MsgActivate *pMsg);\r
156     void    DoDeactivate(CFWL_MsgDeactivate *pMsg);\r
157     void        DoButtonDown(CFWL_MsgMouse *pMsg);\r
158     void        OnFocusChanged(CFWL_Message *pMsg, FX_BOOL bSet = TRUE);\r
159     void        OnLButtonDown(CFWL_MsgMouse *pMsg);\r
160     void        OnLButtonUp(CFWL_MsgMouse *pMsg);\r
161     void        OnButtonDblClk(CFWL_MsgMouse *pMsg);\r
162     void        OnMouseMove(CFWL_MsgMouse *pMsg);\r
163     void        OnKeyDown(CFWL_MsgKey *pMsg);\r
164     void        OnChar(CFWL_MsgKey *pMsg);\r
165     FX_BOOL     OnScroll(IFWL_ScrollBar *pScrollBar, FX_DWORD dwCode, FX_FLOAT fPos);\r
166     void    DoCursor(CFWL_MsgMouse *pMsg);\r
167     CFWL_EditImp *m_pOwner;\r
168 };\r
169 #endif\r