OLD | NEW |
| (Empty) |
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 XFA_FWL_BASEWIDGET_FWL_EDITIMP_H_ | |
8 #define XFA_FWL_BASEWIDGET_FWL_EDITIMP_H_ | |
9 | |
10 #include <deque> | |
11 #include <memory> | |
12 #include <vector> | |
13 | |
14 #include "xfa/fde/ifde_txtedtdorecord.h" | |
15 #include "xfa/fde/ifde_txtedtengine.h" | |
16 #include "xfa/fwl/basewidget/ifwl_scrollbar.h" | |
17 #include "xfa/fwl/core/fwl_widgetimp.h" | |
18 #include "xfa/fxgraphics/cfx_path.h" | |
19 | |
20 class CFWL_EditImp; | |
21 class CFWL_EditImpDelegate; | |
22 class CFWL_MsgActivate; | |
23 class CFWL_MsgDeactivate; | |
24 class CFWL_MsgMouse; | |
25 class CFWL_WidgetImpDelegate; | |
26 class CFWL_WidgetImpProperties; | |
27 class IFWL_Caret; | |
28 | |
29 class CFWL_EditImp : public CFWL_WidgetImp { | |
30 public: | |
31 CFWL_EditImp(const CFWL_WidgetImpProperties& properties, IFWL_Widget* pOuter); | |
32 ~CFWL_EditImp() override; | |
33 | |
34 // CFWL_WidgetImp: | |
35 FWL_Error GetClassName(CFX_WideString& wsClass) const override; | |
36 FWL_Type GetClassID() const override; | |
37 FWL_Error Initialize() override; | |
38 FWL_Error Finalize() override; | |
39 FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE) override; | |
40 FWL_Error SetWidgetRect(const CFX_RectF& rect) override; | |
41 FWL_Error Update() override; | |
42 FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; | |
43 void SetStates(uint32_t dwStates, FX_BOOL bSet = TRUE) override; | |
44 FWL_Error DrawWidget(CFX_Graphics* pGraphics, | |
45 const CFX_Matrix* pMatrix = nullptr) override; | |
46 FWL_Error SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; | |
47 | |
48 virtual FWL_Error SetText(const CFX_WideString& wsText); | |
49 virtual int32_t GetTextLength() const; | |
50 virtual FWL_Error GetText(CFX_WideString& wsText, | |
51 int32_t nStart = 0, | |
52 int32_t nCount = -1) const; | |
53 virtual FWL_Error ClearText(); | |
54 virtual int32_t GetCaretPos() const; | |
55 virtual int32_t SetCaretPos(int32_t nIndex, FX_BOOL bBefore = TRUE); | |
56 virtual FWL_Error AddSelRange(int32_t nStart, int32_t nCount = -1); | |
57 virtual int32_t CountSelRanges(); | |
58 virtual int32_t GetSelRange(int32_t nIndex, int32_t& nStart); | |
59 virtual FWL_Error ClearSelections(); | |
60 virtual int32_t GetLimit(); | |
61 virtual FWL_Error SetLimit(int32_t nLimit); | |
62 virtual FWL_Error SetAliasChar(FX_WCHAR wAlias); | |
63 virtual FWL_Error Insert(int32_t nStart, | |
64 const FX_WCHAR* lpText, | |
65 int32_t nLen); | |
66 virtual FWL_Error DeleteSelections(); | |
67 virtual FWL_Error DeleteRange(int32_t nStart, int32_t nCount = -1); | |
68 virtual FWL_Error Replace(int32_t nStart, | |
69 int32_t nLen, | |
70 const CFX_WideStringC& wsReplace); | |
71 virtual FWL_Error DoClipboard(int32_t iCmd); | |
72 virtual FX_BOOL Copy(CFX_WideString& wsCopy); | |
73 virtual FX_BOOL Cut(CFX_WideString& wsCut); | |
74 virtual FX_BOOL Paste(const CFX_WideString& wsPaste); | |
75 virtual FX_BOOL Delete(); | |
76 virtual FX_BOOL Redo(const IFDE_TxtEdtDoRecord* pRecord); | |
77 virtual FX_BOOL Undo(const IFDE_TxtEdtDoRecord* pRecord); | |
78 virtual FX_BOOL Undo(); | |
79 virtual FX_BOOL Redo(); | |
80 virtual FX_BOOL CanUndo(); | |
81 virtual FX_BOOL CanRedo(); | |
82 virtual FWL_Error SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant); | |
83 virtual FWL_Error SetOuter(IFWL_Widget* pOuter); | |
84 virtual FWL_Error SetNumberRange(int32_t iMin, int32_t iMax); | |
85 virtual FWL_Error SetBackgroundColor(uint32_t color); | |
86 virtual FWL_Error SetFont(const CFX_WideString& wsFont, FX_FLOAT fSize); | |
87 | |
88 void On_CaretChanged(CFDE_TxtEdtEngine* pEdit, | |
89 int32_t nPage, | |
90 FX_BOOL bVisible = true); | |
91 void On_TextChanged(CFDE_TxtEdtEngine* pEdit, | |
92 FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo); | |
93 void On_SelChanged(CFDE_TxtEdtEngine* pEdit); | |
94 FX_BOOL On_PageLoad(CFDE_TxtEdtEngine* pEdit, | |
95 int32_t nPageIndex, | |
96 int32_t nPurpose); | |
97 FX_BOOL On_PageUnload(CFDE_TxtEdtEngine* pEdit, | |
98 int32_t nPageIndex, | |
99 int32_t nPurpose); | |
100 void On_AddDoRecord(CFDE_TxtEdtEngine* pEdit, IFDE_TxtEdtDoRecord* pRecord); | |
101 FX_BOOL On_Validate(CFDE_TxtEdtEngine* pEdit, CFX_WideString& wsText); | |
102 void SetScrollOffset(FX_FLOAT fScrollOffset); | |
103 FX_BOOL GetSuggestWords(CFX_PointF pointf, | |
104 std::vector<CFX_ByteString>& sSuggest); | |
105 FX_BOOL ReplaceSpellCheckWord(CFX_PointF pointf, | |
106 const CFX_ByteStringC& bsReplace); | |
107 | |
108 protected: | |
109 friend class CFWL_TxtEdtEventSink; | |
110 friend class CFWL_EditImpDelegate; | |
111 | |
112 void DrawTextBk(CFX_Graphics* pGraphics, | |
113 IFWL_ThemeProvider* pTheme, | |
114 const CFX_Matrix* pMatrix = nullptr); | |
115 void DrawContent(CFX_Graphics* pGraphics, | |
116 IFWL_ThemeProvider* pTheme, | |
117 const CFX_Matrix* pMatrix = nullptr); | |
118 void UpdateEditEngine(); | |
119 void UpdateEditParams(); | |
120 void UpdateEditLayout(); | |
121 FX_BOOL UpdateOffset(); | |
122 FX_BOOL UpdateOffset(IFWL_ScrollBar* pScrollBar, FX_FLOAT fPosChanged); | |
123 void UpdateVAlignment(); | |
124 void UpdateCaret(); | |
125 IFWL_ScrollBar* UpdateScroll(); | |
126 void Layout(); | |
127 void LayoutScrollBar(); | |
128 void DeviceToEngine(CFX_PointF& pt); | |
129 void InitScrollBar(FX_BOOL bVert = TRUE); | |
130 void InitEngine(); | |
131 virtual void ShowCaret(FX_BOOL bVisible, CFX_RectF* pRect = nullptr); | |
132 FX_BOOL ValidateNumberChar(FX_WCHAR cNum); | |
133 void InitCaret(); | |
134 void ClearRecord(); | |
135 FX_BOOL IsShowScrollBar(FX_BOOL bVert); | |
136 FX_BOOL IsContentHeightOverflow(); | |
137 int32_t AddDoRecord(IFDE_TxtEdtDoRecord* pRecord); | |
138 void ProcessInsertError(int32_t iError); | |
139 | |
140 void DrawSpellCheck(CFX_Graphics* pGraphics, | |
141 const CFX_Matrix* pMatrix = nullptr); | |
142 void AddSpellCheckObj(CFX_Path& PathData, | |
143 int32_t nStart, | |
144 int32_t nCount, | |
145 FX_FLOAT fOffSetX, | |
146 FX_FLOAT fOffSetY); | |
147 int32_t GetWordAtPoint(CFX_PointF pointf, int32_t& nCount); | |
148 | |
149 CFX_RectF m_rtClient; | |
150 CFX_RectF m_rtEngine; | |
151 CFX_RectF m_rtStatic; | |
152 FX_FLOAT m_fVAlignOffset; | |
153 FX_FLOAT m_fScrollOffsetX; | |
154 FX_FLOAT m_fScrollOffsetY; | |
155 std::unique_ptr<CFDE_TxtEdtEngine> m_pEdtEngine; | |
156 FX_BOOL m_bLButtonDown; | |
157 int32_t m_nSelStart; | |
158 int32_t m_nLimit; | |
159 FX_FLOAT m_fSpaceAbove; | |
160 FX_FLOAT m_fSpaceBelow; | |
161 FX_FLOAT m_fFontSize; | |
162 FX_ARGB m_argbSel; | |
163 FX_BOOL m_bSetRange; | |
164 int32_t m_iMin; | |
165 int32_t m_iMax; | |
166 std::unique_ptr<IFWL_ScrollBar> m_pVertScrollBar; | |
167 std::unique_ptr<IFWL_ScrollBar> m_pHorzScrollBar; | |
168 std::unique_ptr<IFWL_Caret> m_pCaret; | |
169 CFX_WideString m_wsCache; | |
170 uint32_t m_backColor; | |
171 FX_BOOL m_updateBackColor; | |
172 CFX_WideString m_wsFont; | |
173 std::deque<std::unique_ptr<IFDE_TxtEdtDoRecord>> m_DoRecords; | |
174 int32_t m_iCurRecord; | |
175 int32_t m_iMaxRecord; | |
176 }; | |
177 | |
178 class CFWL_EditImpDelegate : public CFWL_WidgetImpDelegate { | |
179 public: | |
180 CFWL_EditImpDelegate(CFWL_EditImp* pOwner); | |
181 void OnProcessMessage(CFWL_Message* pMessage) override; | |
182 void OnProcessEvent(CFWL_Event* pEvent) override; | |
183 void OnDrawWidget(CFX_Graphics* pGraphics, | |
184 const CFX_Matrix* pMatrix = nullptr) override; | |
185 | |
186 protected: | |
187 void DoActivate(CFWL_MsgActivate* pMsg); | |
188 void DoDeactivate(CFWL_MsgDeactivate* pMsg); | |
189 void DoButtonDown(CFWL_MsgMouse* pMsg); | |
190 void OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet = TRUE); | |
191 void OnLButtonDown(CFWL_MsgMouse* pMsg); | |
192 void OnLButtonUp(CFWL_MsgMouse* pMsg); | |
193 void OnButtonDblClk(CFWL_MsgMouse* pMsg); | |
194 void OnMouseMove(CFWL_MsgMouse* pMsg); | |
195 void OnKeyDown(CFWL_MsgKey* pMsg); | |
196 void OnChar(CFWL_MsgKey* pMsg); | |
197 FX_BOOL OnScroll(IFWL_ScrollBar* pScrollBar, uint32_t dwCode, FX_FLOAT fPos); | |
198 void DoCursor(CFWL_MsgMouse* pMsg); | |
199 CFWL_EditImp* m_pOwner; | |
200 }; | |
201 | |
202 #endif // XFA_FWL_BASEWIDGET_FWL_EDITIMP_H_ | |
OLD | NEW |