| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #ifndef XFA_FWL_CORE_IFWL_EDIT_H_ | 7 #ifndef XFA_FWL_CORE_IFWL_EDIT_H_ |
| 8 #define XFA_FWL_CORE_IFWL_EDIT_H_ | 8 #define XFA_FWL_CORE_IFWL_EDIT_H_ |
| 9 | 9 |
| 10 #include <deque> | 10 #include <deque> |
| 11 #include <memory> | |
| 12 #include <vector> | 11 #include <vector> |
| 13 | 12 |
| 13 #include "xfa/fde/cfde_txtedtengine.h" |
| 14 #include "xfa/fde/ifde_txtedtdorecord.h" | 14 #include "xfa/fde/ifde_txtedtdorecord.h" |
| 15 #include "xfa/fde/ifde_txtedtengine.h" | |
| 16 #include "xfa/fwl/core/cfwl_event.h" | 15 #include "xfa/fwl/core/cfwl_event.h" |
| 17 #include "xfa/fwl/core/cfwl_widget.h" | 16 #include "xfa/fwl/core/cfwl_widget.h" |
| 18 #include "xfa/fwl/core/ifwl_dataprovider.h" | 17 #include "xfa/fwl/core/ifwl_dataprovider.h" |
| 19 #include "xfa/fwl/core/ifwl_scrollbar.h" | 18 #include "xfa/fwl/core/ifwl_scrollbar.h" |
| 20 #include "xfa/fxgraphics/cfx_path.h" | 19 #include "xfa/fxgraphics/cfx_path.h" |
| 21 | 20 |
| 22 #define FWL_STYLEEXT_EDT_ReadOnly (1L << 0) | 21 #define FWL_STYLEEXT_EDT_ReadOnly (1L << 0) |
| 23 #define FWL_STYLEEXT_EDT_MultiLine (1L << 1) | 22 #define FWL_STYLEEXT_EDT_MultiLine (1L << 1) |
| 24 #define FWL_STYLEEXT_EDT_WantReturn (1L << 2) | 23 #define FWL_STYLEEXT_EDT_WantReturn (1L << 2) |
| 25 #define FWL_STYLEEXT_EDT_NoHideSel (1L << 3) | 24 #define FWL_STYLEEXT_EDT_NoHideSel (1L << 3) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 CFWL_EventType::Validate, | 77 CFWL_EventType::Validate, |
| 79 IFWL_Widget* pDstWidget; | 78 IFWL_Widget* pDstWidget; |
| 80 CFX_WideString wsInsert; | 79 CFX_WideString wsInsert; |
| 81 bool bValidate;) | 80 bool bValidate;) |
| 82 | 81 |
| 83 FWL_EVENT_DEF(CFWL_EvtEdtCheckWord, | 82 FWL_EVENT_DEF(CFWL_EvtEdtCheckWord, |
| 84 CFWL_EventType::CheckWord, | 83 CFWL_EventType::CheckWord, |
| 85 CFX_ByteString bsWord; | 84 CFX_ByteString bsWord; |
| 86 bool bCheckWord;) | 85 bool bCheckWord;) |
| 87 | 86 |
| 88 FWL_EVENT_DEF(CFWL_EvtEdtGetSuggestWords, | |
| 89 CFWL_EventType::GetSuggestedWords, | |
| 90 bool bSuggestWords; | |
| 91 CFX_ByteString bsWord; | |
| 92 std::vector<CFX_ByteString> bsArraySuggestWords;) | |
| 93 | |
| 94 class IFDE_TxtEdtDoRecord; | 87 class IFDE_TxtEdtDoRecord; |
| 95 class IFWL_Edit; | 88 class IFWL_Edit; |
| 96 class CFWL_MsgActivate; | 89 class CFWL_MsgActivate; |
| 97 class CFWL_MsgDeactivate; | 90 class CFWL_MsgDeactivate; |
| 98 class CFWL_MsgMouse; | 91 class CFWL_MsgMouse; |
| 99 class CFWL_WidgetProperties; | 92 class CFWL_WidgetProperties; |
| 100 class IFWL_Caret; | 93 class IFWL_Caret; |
| 101 | 94 |
| 102 class IFWL_EditDP : public IFWL_DataProvider {}; | |
| 103 | |
| 104 class IFWL_Edit : public IFWL_Widget { | 95 class IFWL_Edit : public IFWL_Widget { |
| 105 public: | 96 public: |
| 106 IFWL_Edit(const IFWL_App* app, | 97 IFWL_Edit(const IFWL_App* app, |
| 107 std::unique_ptr<CFWL_WidgetProperties> properties, | 98 std::unique_ptr<CFWL_WidgetProperties> properties, |
| 108 IFWL_Widget* pOuter); | 99 IFWL_Widget* pOuter); |
| 109 ~IFWL_Edit() override; | 100 ~IFWL_Edit() override; |
| 110 | 101 |
| 111 // IFWL_Widget: | 102 // IFWL_Widget: |
| 112 FWL_Type GetClassID() const override; | 103 FWL_Type GetClassID() const override; |
| 113 void GetWidgetRect(CFX_RectF& rect, bool bAutoSize = false) override; | 104 void GetWidgetRect(CFX_RectF& rect, bool bAutoSize = false) override; |
| 114 void Update() override; | 105 void Update() override; |
| 115 FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; | 106 FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; |
| 116 void SetStates(uint32_t dwStates, bool bSet = true) override; | 107 void SetStates(uint32_t dwStates, bool bSet = true) override; |
| 117 void DrawWidget(CFX_Graphics* pGraphics, | 108 void DrawWidget(CFX_Graphics* pGraphics, |
| 118 const CFX_Matrix* pMatrix = nullptr) override; | 109 const CFX_Matrix* pMatrix = nullptr) override; |
| 119 void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; | 110 void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; |
| 120 void OnProcessMessage(CFWL_Message* pMessage) override; | 111 void OnProcessMessage(CFWL_Message* pMessage) override; |
| 121 void OnProcessEvent(CFWL_Event* pEvent) override; | 112 void OnProcessEvent(CFWL_Event* pEvent) override; |
| 122 void OnDrawWidget(CFX_Graphics* pGraphics, | 113 void OnDrawWidget(CFX_Graphics* pGraphics, |
| 123 const CFX_Matrix* pMatrix) override; | 114 const CFX_Matrix* pMatrix) override; |
| 124 | 115 |
| 125 virtual FWL_Error SetText(const CFX_WideString& wsText); | 116 virtual void SetText(const CFX_WideString& wsText); |
| 126 virtual int32_t GetTextLength() const; | 117 |
| 127 virtual FWL_Error GetText(CFX_WideString& wsText, | 118 int32_t GetTextLength() const; |
| 128 int32_t nStart = 0, | 119 void GetText(CFX_WideString& wsText, int32_t nStart = 0, int32_t nCount = -1); |
| 129 int32_t nCount = -1) const; | 120 void ClearText(); |
| 130 virtual FWL_Error ClearText(); | 121 |
| 131 virtual int32_t GetCaretPos() const; | 122 void AddSelRange(int32_t nStart, int32_t nCount = -1); |
| 132 virtual int32_t SetCaretPos(int32_t nIndex, bool bBefore = true); | 123 int32_t CountSelRanges(); |
| 133 virtual FWL_Error AddSelRange(int32_t nStart, int32_t nCount = -1); | 124 int32_t GetSelRange(int32_t nIndex, int32_t& nStart); |
| 134 virtual int32_t CountSelRanges(); | 125 void ClearSelections(); |
| 135 virtual int32_t GetSelRange(int32_t nIndex, int32_t& nStart); | 126 int32_t GetLimit(); |
| 136 virtual FWL_Error ClearSelections(); | 127 void SetLimit(int32_t nLimit); |
| 137 virtual int32_t GetLimit(); | 128 void SetAliasChar(FX_WCHAR wAlias); |
| 138 virtual FWL_Error SetLimit(int32_t nLimit); | 129 bool Copy(CFX_WideString& wsCopy); |
| 139 virtual FWL_Error SetAliasChar(FX_WCHAR wAlias); | 130 bool Cut(CFX_WideString& wsCut); |
| 140 virtual FWL_Error Insert(int32_t nStart, | 131 bool Paste(const CFX_WideString& wsPaste); |
| 141 const FX_WCHAR* lpText, | 132 bool Redo(const IFDE_TxtEdtDoRecord* pRecord); |
| 142 int32_t nLen); | 133 bool Undo(const IFDE_TxtEdtDoRecord* pRecord); |
| 143 virtual FWL_Error DeleteSelections(); | 134 bool Undo(); |
| 144 virtual FWL_Error DeleteRange(int32_t nStart, int32_t nCount = -1); | 135 bool Redo(); |
| 145 virtual FWL_Error Replace(int32_t nStart, | 136 bool CanUndo(); |
| 146 int32_t nLen, | 137 bool CanRedo(); |
| 147 const CFX_WideStringC& wsReplace); | 138 |
| 148 virtual FWL_Error DoClipboard(int32_t iCmd); | 139 void SetOuter(IFWL_Widget* pOuter); |
| 149 virtual bool Copy(CFX_WideString& wsCopy); | |
| 150 virtual bool Cut(CFX_WideString& wsCut); | |
| 151 virtual bool Paste(const CFX_WideString& wsPaste); | |
| 152 virtual bool Delete(); | |
| 153 virtual bool Redo(const IFDE_TxtEdtDoRecord* pRecord); | |
| 154 virtual bool Undo(const IFDE_TxtEdtDoRecord* pRecord); | |
| 155 virtual bool Undo(); | |
| 156 virtual bool Redo(); | |
| 157 virtual bool CanUndo(); | |
| 158 virtual bool CanRedo(); | |
| 159 virtual FWL_Error SetTabWidth(FX_FLOAT fTabWidth, bool bEquidistant); | |
| 160 virtual FWL_Error SetOuter(IFWL_Widget* pOuter); | |
| 161 virtual FWL_Error SetNumberRange(int32_t iMin, int32_t iMax); | |
| 162 virtual FWL_Error SetBackgroundColor(uint32_t color); | |
| 163 virtual FWL_Error SetFont(const CFX_WideString& wsFont, FX_FLOAT fSize); | |
| 164 | 140 |
| 165 void On_CaretChanged(CFDE_TxtEdtEngine* pEdit, | 141 void On_CaretChanged(CFDE_TxtEdtEngine* pEdit, |
| 166 int32_t nPage, | 142 int32_t nPage, |
| 167 bool bVisible = true); | 143 bool bVisible = true); |
| 168 void On_TextChanged(CFDE_TxtEdtEngine* pEdit, | 144 void On_TextChanged(CFDE_TxtEdtEngine* pEdit, |
| 169 FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo); | 145 FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo); |
| 170 void On_SelChanged(CFDE_TxtEdtEngine* pEdit); | 146 void On_SelChanged(CFDE_TxtEdtEngine* pEdit); |
| 171 bool On_PageLoad(CFDE_TxtEdtEngine* pEdit, | 147 bool On_PageLoad(CFDE_TxtEdtEngine* pEdit, |
| 172 int32_t nPageIndex, | 148 int32_t nPageIndex, |
| 173 int32_t nPurpose); | 149 int32_t nPurpose); |
| 174 bool On_PageUnload(CFDE_TxtEdtEngine* pEdit, | 150 bool On_PageUnload(CFDE_TxtEdtEngine* pEdit, |
| 175 int32_t nPageIndex, | 151 int32_t nPageIndex, |
| 176 int32_t nPurpose); | 152 int32_t nPurpose); |
| 177 void On_AddDoRecord(CFDE_TxtEdtEngine* pEdit, IFDE_TxtEdtDoRecord* pRecord); | 153 void On_AddDoRecord(CFDE_TxtEdtEngine* pEdit, IFDE_TxtEdtDoRecord* pRecord); |
| 178 bool On_Validate(CFDE_TxtEdtEngine* pEdit, CFX_WideString& wsText); | 154 bool On_Validate(CFDE_TxtEdtEngine* pEdit, CFX_WideString& wsText); |
| 179 void SetScrollOffset(FX_FLOAT fScrollOffset); | 155 void SetScrollOffset(FX_FLOAT fScrollOffset); |
| 180 bool GetSuggestWords(CFX_PointF pointf, | |
| 181 std::vector<CFX_ByteString>& sSuggest); | |
| 182 bool ReplaceSpellCheckWord(CFX_PointF pointf, | |
| 183 const CFX_ByteStringC& bsReplace); | |
| 184 | 156 |
| 185 protected: | 157 protected: |
| 186 friend class CFWL_TxtEdtEventSink; | 158 void ShowCaret(bool bVisible, CFX_RectF* pRect = nullptr); |
| 159 const CFX_RectF& GetRTClient() const { return m_rtClient; } |
| 160 CFDE_TxtEdtEngine* GetTxtEdtEngine() { return &m_EdtEngine; } |
| 187 | 161 |
| 162 private: |
| 188 void DrawTextBk(CFX_Graphics* pGraphics, | 163 void DrawTextBk(CFX_Graphics* pGraphics, |
| 189 IFWL_ThemeProvider* pTheme, | 164 IFWL_ThemeProvider* pTheme, |
| 190 const CFX_Matrix* pMatrix = nullptr); | 165 const CFX_Matrix* pMatrix = nullptr); |
| 191 void DrawContent(CFX_Graphics* pGraphics, | 166 void DrawContent(CFX_Graphics* pGraphics, |
| 192 IFWL_ThemeProvider* pTheme, | 167 IFWL_ThemeProvider* pTheme, |
| 193 const CFX_Matrix* pMatrix = nullptr); | 168 const CFX_Matrix* pMatrix = nullptr); |
| 194 void UpdateEditEngine(); | 169 void UpdateEditEngine(); |
| 195 void UpdateEditParams(); | 170 void UpdateEditParams(); |
| 196 void UpdateEditLayout(); | 171 void UpdateEditLayout(); |
| 197 bool UpdateOffset(); | 172 bool UpdateOffset(); |
| 198 bool UpdateOffset(IFWL_ScrollBar* pScrollBar, FX_FLOAT fPosChanged); | 173 bool UpdateOffset(IFWL_ScrollBar* pScrollBar, FX_FLOAT fPosChanged); |
| 199 void UpdateVAlignment(); | 174 void UpdateVAlignment(); |
| 200 void UpdateCaret(); | 175 void UpdateCaret(); |
| 201 IFWL_ScrollBar* UpdateScroll(); | 176 IFWL_ScrollBar* UpdateScroll(); |
| 202 void Layout(); | 177 void Layout(); |
| 203 void LayoutScrollBar(); | 178 void LayoutScrollBar(); |
| 204 void DeviceToEngine(CFX_PointF& pt); | 179 void DeviceToEngine(CFX_PointF& pt); |
| 205 void InitScrollBar(bool bVert = true); | 180 void InitScrollBar(bool bVert = true); |
| 206 void InitEngine(); | 181 void InitEngine(); |
| 207 virtual void ShowCaret(bool bVisible, CFX_RectF* pRect = nullptr); | |
| 208 bool ValidateNumberChar(FX_WCHAR cNum); | 182 bool ValidateNumberChar(FX_WCHAR cNum); |
| 209 void InitCaret(); | 183 void InitCaret(); |
| 210 void ClearRecord(); | 184 void ClearRecord(); |
| 211 bool IsShowScrollBar(bool bVert); | 185 bool IsShowScrollBar(bool bVert); |
| 212 bool IsContentHeightOverflow(); | 186 bool IsContentHeightOverflow(); |
| 213 int32_t AddDoRecord(IFDE_TxtEdtDoRecord* pRecord); | 187 int32_t AddDoRecord(IFDE_TxtEdtDoRecord* pRecord); |
| 214 void ProcessInsertError(int32_t iError); | 188 void ProcessInsertError(int32_t iError); |
| 215 | 189 |
| 216 void DrawSpellCheck(CFX_Graphics* pGraphics, | 190 void DrawSpellCheck(CFX_Graphics* pGraphics, |
| 217 const CFX_Matrix* pMatrix = nullptr); | 191 const CFX_Matrix* pMatrix = nullptr); |
| 218 void AddSpellCheckObj(CFX_Path& PathData, | 192 void AddSpellCheckObj(CFX_Path& PathData, |
| 219 int32_t nStart, | 193 int32_t nStart, |
| 220 int32_t nCount, | 194 int32_t nCount, |
| 221 FX_FLOAT fOffSetX, | 195 FX_FLOAT fOffSetX, |
| 222 FX_FLOAT fOffSetY); | 196 FX_FLOAT fOffSetY); |
| 223 int32_t GetWordAtPoint(CFX_PointF pointf, int32_t& nCount); | 197 void DoActivate(CFWL_MsgActivate* pMsg); |
| 198 void DoDeactivate(CFWL_MsgDeactivate* pMsg); |
| 199 void DoButtonDown(CFWL_MsgMouse* pMsg); |
| 200 void OnFocusChanged(CFWL_Message* pMsg, bool bSet); |
| 201 void OnLButtonDown(CFWL_MsgMouse* pMsg); |
| 202 void OnLButtonUp(CFWL_MsgMouse* pMsg); |
| 203 void OnButtonDblClk(CFWL_MsgMouse* pMsg); |
| 204 void OnMouseMove(CFWL_MsgMouse* pMsg); |
| 205 void OnKeyDown(CFWL_MsgKey* pMsg); |
| 206 void OnChar(CFWL_MsgKey* pMsg); |
| 207 bool OnScroll(IFWL_ScrollBar* pScrollBar, FWL_SCBCODE dwCode, FX_FLOAT fPos); |
| 224 | 208 |
| 225 CFX_RectF m_rtClient; | 209 CFX_RectF m_rtClient; |
| 226 CFX_RectF m_rtEngine; | 210 CFX_RectF m_rtEngine; |
| 227 CFX_RectF m_rtStatic; | 211 CFX_RectF m_rtStatic; |
| 228 FX_FLOAT m_fVAlignOffset; | 212 FX_FLOAT m_fVAlignOffset; |
| 229 FX_FLOAT m_fScrollOffsetX; | 213 FX_FLOAT m_fScrollOffsetX; |
| 230 FX_FLOAT m_fScrollOffsetY; | 214 FX_FLOAT m_fScrollOffsetY; |
| 231 std::unique_ptr<CFDE_TxtEdtEngine> m_pEdtEngine; | 215 CFDE_TxtEdtEngine m_EdtEngine; |
| 232 bool m_bLButtonDown; | 216 bool m_bLButtonDown; |
| 233 int32_t m_nSelStart; | 217 int32_t m_nSelStart; |
| 234 int32_t m_nLimit; | 218 int32_t m_nLimit; |
| 235 FX_FLOAT m_fSpaceAbove; | |
| 236 FX_FLOAT m_fSpaceBelow; | |
| 237 FX_FLOAT m_fFontSize; | 219 FX_FLOAT m_fFontSize; |
| 238 FX_ARGB m_argbSel; | |
| 239 bool m_bSetRange; | 220 bool m_bSetRange; |
| 240 int32_t m_iMin; | |
| 241 int32_t m_iMax; | 221 int32_t m_iMax; |
| 242 std::unique_ptr<IFWL_ScrollBar> m_pVertScrollBar; | 222 std::unique_ptr<IFWL_ScrollBar> m_pVertScrollBar; |
| 243 std::unique_ptr<IFWL_ScrollBar> m_pHorzScrollBar; | 223 std::unique_ptr<IFWL_ScrollBar> m_pHorzScrollBar; |
| 244 std::unique_ptr<IFWL_Caret> m_pCaret; | 224 std::unique_ptr<IFWL_Caret> m_pCaret; |
| 245 CFX_WideString m_wsCache; | 225 CFX_WideString m_wsCache; |
| 246 uint32_t m_backColor; | |
| 247 bool m_updateBackColor; | |
| 248 CFX_WideString m_wsFont; | 226 CFX_WideString m_wsFont; |
| 249 std::deque<std::unique_ptr<IFDE_TxtEdtDoRecord>> m_DoRecords; | 227 std::deque<std::unique_ptr<IFDE_TxtEdtDoRecord>> m_DoRecords; |
| 250 int32_t m_iCurRecord; | 228 int32_t m_iCurRecord; |
| 251 int32_t m_iMaxRecord; | 229 int32_t m_iMaxRecord; |
| 252 | |
| 253 private: | |
| 254 void DoActivate(CFWL_MsgActivate* pMsg); | |
| 255 void DoDeactivate(CFWL_MsgDeactivate* pMsg); | |
| 256 void DoButtonDown(CFWL_MsgMouse* pMsg); | |
| 257 void OnFocusChanged(CFWL_Message* pMsg, bool bSet); | |
| 258 void OnLButtonDown(CFWL_MsgMouse* pMsg); | |
| 259 void OnLButtonUp(CFWL_MsgMouse* pMsg); | |
| 260 void OnButtonDblClk(CFWL_MsgMouse* pMsg); | |
| 261 void OnMouseMove(CFWL_MsgMouse* pMsg); | |
| 262 void OnKeyDown(CFWL_MsgKey* pMsg); | |
| 263 void OnChar(CFWL_MsgKey* pMsg); | |
| 264 bool OnScroll(IFWL_ScrollBar* pScrollBar, FWL_SCBCODE dwCode, FX_FLOAT fPos); | |
| 265 }; | 230 }; |
| 266 | 231 |
| 267 #endif // XFA_FWL_CORE_IFWL_EDIT_H_ | 232 #endif // XFA_FWL_CORE_IFWL_EDIT_H_ |
| OLD | NEW |