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