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_CFWL_EDIT_H_ | 7 #ifndef XFA_FWL_CORE_CFWL_EDIT_H_ |
8 #define XFA_FWL_CORE_CFWL_EDIT_H_ | 8 #define XFA_FWL_CORE_CFWL_EDIT_H_ |
9 | 9 |
| 10 #include <deque> |
| 11 #include <memory> |
10 #include <vector> | 12 #include <vector> |
11 | 13 |
| 14 #include "xfa/fde/cfde_txtedtengine.h" |
| 15 #include "xfa/fde/ifde_txtedtdorecord.h" |
| 16 #include "xfa/fwl/core/cfwl_event.h" |
| 17 #include "xfa/fwl/core/cfwl_scrollbar.h" |
12 #include "xfa/fwl/core/cfwl_widget.h" | 18 #include "xfa/fwl/core/cfwl_widget.h" |
13 #include "xfa/fwl/core/ifwl_edit.h" | 19 #include "xfa/fxgraphics/cfx_path.h" |
| 20 |
| 21 #define FWL_STYLEEXT_EDT_ReadOnly (1L << 0) |
| 22 #define FWL_STYLEEXT_EDT_MultiLine (1L << 1) |
| 23 #define FWL_STYLEEXT_EDT_WantReturn (1L << 2) |
| 24 #define FWL_STYLEEXT_EDT_NoHideSel (1L << 3) |
| 25 #define FWL_STYLEEXT_EDT_AutoHScroll (1L << 4) |
| 26 #define FWL_STYLEEXT_EDT_AutoVScroll (1L << 5) |
| 27 #define FWL_STYLEEXT_EDT_NoRedoUndo (1L << 6) |
| 28 #define FWL_STYLEEXT_EDT_Validate (1L << 7) |
| 29 #define FWL_STYLEEXT_EDT_Password (1L << 8) |
| 30 #define FWL_STYLEEXT_EDT_Number (1L << 9) |
| 31 #define FWL_STYLEEXT_EDT_VerticalLayout (1L << 12) |
| 32 #define FWL_STYLEEXT_EDT_VerticalChars (1L << 13) |
| 33 #define FWL_STYLEEXT_EDT_ReverseLine (1L << 14) |
| 34 #define FWL_STYLEEXT_EDT_ArabicShapes (1L << 15) |
| 35 #define FWL_STYLEEXT_EDT_ExpandTab (1L << 16) |
| 36 #define FWL_STYLEEXT_EDT_CombText (1L << 17) |
| 37 #define FWL_STYLEEXT_EDT_HNear (0L << 18) |
| 38 #define FWL_STYLEEXT_EDT_HCenter (1L << 18) |
| 39 #define FWL_STYLEEXT_EDT_HFar (2L << 18) |
| 40 #define FWL_STYLEEXT_EDT_VNear (0L << 20) |
| 41 #define FWL_STYLEEXT_EDT_VCenter (1L << 20) |
| 42 #define FWL_STYLEEXT_EDT_VFar (2L << 20) |
| 43 #define FWL_STYLEEXT_EDT_Justified (1L << 22) |
| 44 #define FWL_STYLEEXT_EDT_Distributed (2L << 22) |
| 45 #define FWL_STYLEEXT_EDT_HAlignMask (3L << 18) |
| 46 #define FWL_STYLEEXT_EDT_VAlignMask (3L << 20) |
| 47 #define FWL_STYLEEXT_EDT_HAlignModeMask (3L << 22) |
| 48 #define FWL_STYLEEXT_EDT_InnerCaret (1L << 24) |
| 49 #define FWL_STYLEEXT_EDT_ShowScrollbarFocus (1L << 25) |
| 50 #define FWL_STYLEEXT_EDT_OuterScrollbar (1L << 26) |
| 51 #define FWL_STYLEEXT_EDT_LastLineHeight (1L << 27) |
14 | 52 |
15 class IFDE_TxtEdtDoRecord; | 53 class IFDE_TxtEdtDoRecord; |
| 54 class CFWL_Edit; |
| 55 class CFWL_MsgMouse; |
| 56 class CFWL_WidgetProperties; |
| 57 class CFWL_Caret; |
16 | 58 |
17 class CFWL_Edit : public CFWL_Widget { | 59 class CFWL_Edit : public CFWL_Widget { |
18 public: | 60 public: |
19 explicit CFWL_Edit(const CFWL_App*); | 61 CFWL_Edit(const CFWL_App* app, |
| 62 std::unique_ptr<CFWL_WidgetProperties> properties, |
| 63 CFWL_Widget* pOuter); |
20 ~CFWL_Edit() override; | 64 ~CFWL_Edit() override; |
21 | 65 |
22 void Initialize(); | 66 // CFWL_Widget: |
| 67 FWL_Type GetClassID() const override; |
| 68 void GetWidgetRect(CFX_RectF& rect, bool bAutoSize = false) override; |
| 69 void Update() override; |
| 70 FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; |
| 71 void SetStates(uint32_t dwStates, bool bSet = true) override; |
| 72 void DrawWidget(CFX_Graphics* pGraphics, |
| 73 const CFX_Matrix* pMatrix = nullptr) override; |
| 74 void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; |
| 75 void OnProcessMessage(CFWL_Message* pMessage) override; |
| 76 void OnProcessEvent(CFWL_Event* pEvent) override; |
| 77 void OnDrawWidget(CFX_Graphics* pGraphics, |
| 78 const CFX_Matrix* pMatrix) override; |
23 | 79 |
24 void SetText(const CFX_WideString& wsText); | 80 virtual void SetText(const CFX_WideString& wsText); |
| 81 |
| 82 int32_t GetTextLength() const; |
25 void GetText(CFX_WideString& wsText, | 83 void GetText(CFX_WideString& wsText, |
26 int32_t nStart = 0, | 84 int32_t nStart = 0, |
27 int32_t nCount = -1) const; | 85 int32_t nCount = -1) const; |
| 86 void ClearText(); |
28 | 87 |
| 88 void AddSelRange(int32_t nStart, int32_t nCount = -1); |
29 int32_t CountSelRanges() const; | 89 int32_t CountSelRanges() const; |
30 int32_t GetSelRange(int32_t nIndex, int32_t& nStart) const; | 90 int32_t GetSelRange(int32_t nIndex, int32_t& nStart) const; |
31 | 91 void ClearSelections(); |
32 int32_t GetLimit() const; | 92 int32_t GetLimit() const; |
33 void SetLimit(int32_t nLimit); | 93 void SetLimit(int32_t nLimit); |
| 94 void SetAliasChar(FX_WCHAR wAlias); |
| 95 bool Copy(CFX_WideString& wsCopy); |
| 96 bool Cut(CFX_WideString& wsCut); |
| 97 bool Paste(const CFX_WideString& wsPaste); |
| 98 bool Redo(const IFDE_TxtEdtDoRecord* pRecord); |
| 99 bool Undo(const IFDE_TxtEdtDoRecord* pRecord); |
| 100 bool Undo(); |
| 101 bool Redo(); |
| 102 bool CanUndo(); |
| 103 bool CanRedo(); |
34 | 104 |
35 void SetAliasChar(FX_WCHAR wAlias); | 105 void SetOuter(CFWL_Widget* pOuter); |
36 | 106 |
| 107 void On_CaretChanged(CFDE_TxtEdtEngine* pEdit, |
| 108 int32_t nPage, |
| 109 bool bVisible = true); |
| 110 void On_TextChanged(CFDE_TxtEdtEngine* pEdit, |
| 111 FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo); |
| 112 void On_SelChanged(CFDE_TxtEdtEngine* pEdit); |
| 113 bool On_PageLoad(CFDE_TxtEdtEngine* pEdit, |
| 114 int32_t nPageIndex, |
| 115 int32_t nPurpose); |
| 116 bool On_PageUnload(CFDE_TxtEdtEngine* pEdit, |
| 117 int32_t nPageIndex, |
| 118 int32_t nPurpose); |
| 119 void On_AddDoRecord(CFDE_TxtEdtEngine* pEdit, IFDE_TxtEdtDoRecord* pRecord); |
| 120 bool On_Validate(CFDE_TxtEdtEngine* pEdit, CFX_WideString& wsText); |
37 void SetScrollOffset(FX_FLOAT fScrollOffset); | 121 void SetScrollOffset(FX_FLOAT fScrollOffset); |
| 122 |
| 123 protected: |
| 124 void ShowCaret(bool bVisible, CFX_RectF* pRect = nullptr); |
| 125 const CFX_RectF& GetRTClient() const { return m_rtClient; } |
| 126 CFDE_TxtEdtEngine* GetTxtEdtEngine() { return &m_EdtEngine; } |
| 127 |
| 128 private: |
| 129 void DrawTextBk(CFX_Graphics* pGraphics, |
| 130 IFWL_ThemeProvider* pTheme, |
| 131 const CFX_Matrix* pMatrix = nullptr); |
| 132 void DrawContent(CFX_Graphics* pGraphics, |
| 133 IFWL_ThemeProvider* pTheme, |
| 134 const CFX_Matrix* pMatrix = nullptr); |
| 135 void UpdateEditEngine(); |
| 136 void UpdateEditParams(); |
| 137 void UpdateEditLayout(); |
| 138 bool UpdateOffset(); |
| 139 bool UpdateOffset(CFWL_ScrollBar* pScrollBar, FX_FLOAT fPosChanged); |
| 140 void UpdateVAlignment(); |
| 141 void UpdateCaret(); |
| 142 CFWL_ScrollBar* UpdateScroll(); |
| 143 void Layout(); |
| 144 void LayoutScrollBar(); |
| 145 void DeviceToEngine(CFX_PointF& pt); |
| 146 void InitScrollBar(bool bVert = true); |
| 147 void InitEngine(); |
| 148 bool ValidateNumberChar(FX_WCHAR cNum); |
| 149 void InitCaret(); |
| 150 void ClearRecord(); |
| 151 bool IsShowScrollBar(bool bVert); |
| 152 bool IsContentHeightOverflow(); |
| 153 int32_t AddDoRecord(IFDE_TxtEdtDoRecord* pRecord); |
| 154 void ProcessInsertError(int32_t iError); |
| 155 |
| 156 void DrawSpellCheck(CFX_Graphics* pGraphics, |
| 157 const CFX_Matrix* pMatrix = nullptr); |
| 158 void AddSpellCheckObj(CFX_Path& PathData, |
| 159 int32_t nStart, |
| 160 int32_t nCount, |
| 161 FX_FLOAT fOffSetX, |
| 162 FX_FLOAT fOffSetY); |
| 163 void DoButtonDown(CFWL_MsgMouse* pMsg); |
| 164 void OnFocusChanged(CFWL_Message* pMsg, bool bSet); |
| 165 void OnLButtonDown(CFWL_MsgMouse* pMsg); |
| 166 void OnLButtonUp(CFWL_MsgMouse* pMsg); |
| 167 void OnButtonDblClk(CFWL_MsgMouse* pMsg); |
| 168 void OnMouseMove(CFWL_MsgMouse* pMsg); |
| 169 void OnKeyDown(CFWL_MsgKey* pMsg); |
| 170 void OnChar(CFWL_MsgKey* pMsg); |
| 171 bool OnScroll(CFWL_ScrollBar* pScrollBar, FWL_SCBCODE dwCode, FX_FLOAT fPos); |
| 172 |
| 173 CFX_RectF m_rtClient; |
| 174 CFX_RectF m_rtEngine; |
| 175 CFX_RectF m_rtStatic; |
| 176 FX_FLOAT m_fVAlignOffset; |
| 177 FX_FLOAT m_fScrollOffsetX; |
| 178 FX_FLOAT m_fScrollOffsetY; |
| 179 CFDE_TxtEdtEngine m_EdtEngine; |
| 180 bool m_bLButtonDown; |
| 181 int32_t m_nSelStart; |
| 182 int32_t m_nLimit; |
| 183 FX_FLOAT m_fFontSize; |
| 184 bool m_bSetRange; |
| 185 int32_t m_iMax; |
| 186 std::unique_ptr<CFWL_ScrollBar> m_pVertScrollBar; |
| 187 std::unique_ptr<CFWL_ScrollBar> m_pHorzScrollBar; |
| 188 std::unique_ptr<CFWL_Caret> m_pCaret; |
| 189 CFX_WideString m_wsCache; |
| 190 CFX_WideString m_wsFont; |
| 191 std::deque<std::unique_ptr<IFDE_TxtEdtDoRecord>> m_DoRecords; |
| 192 int32_t m_iCurRecord; |
| 193 int32_t m_iMaxRecord; |
38 }; | 194 }; |
39 | 195 |
40 #endif // XFA_FWL_CORE_CFWL_EDIT_H_ | 196 #endif // XFA_FWL_CORE_CFWL_EDIT_H_ |
OLD | NEW |