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