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