1 // Copyright 2014 The PDFium Authors 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 FPDFSDK_PWL_CPWL_EDIT_H_ 8 #define FPDFSDK_PWL_CPWL_EDIT_H_ 9 10 #include <memory> 11 #include <utility> 12 13 #include "core/fpdfdoc/cpvt_wordrange.h" 14 #include "core/fxcrt/fx_codepage.h" 15 #include "core/fxcrt/unowned_ptr.h" 16 #include "core/fxcrt/widestring.h" 17 #include "fpdfsdk/pwl/cpwl_wnd.h" 18 #include "fpdfsdk/pwl/ipwl_fillernotify.h" 19 20 class CPDF_Font; 21 class CPWL_Caret; 22 class CPWL_EditImpl; 23 class IPWL_FillerNotify; 24 25 enum PWL_EDIT_ALIGNFORMAT_H { PEAH_LEFT = 0, PEAH_MIDDLE, PEAH_RIGHT }; 26 27 enum PWL_EDIT_ALIGNFORMAT_V { PEAV_TOP = 0, PEAV_CENTER, PEAV_BOTTOM }; 28 29 class CPWL_Edit final : public CPWL_Wnd { 30 public: 31 CPWL_Edit(const CreateParams& cp, 32 std::unique_ptr<IPWL_FillerNotify::PerWindowData> pAttachedData); 33 ~CPWL_Edit() override; 34 35 // CPWL_Wnd: 36 bool RepositionChildWnd() override; 37 CFX_FloatRect GetClientRect() const override; 38 void DrawThisAppearance(CFX_RenderDevice* pDevice, 39 const CFX_Matrix& mtUser2Device) override; 40 bool OnMouseWheel(Mask<FWL_EVENTFLAG> nFlag, 41 const CFX_PointF& point, 42 const CFX_Vector& delta) override; 43 bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlag) override; 44 bool OnChar(uint16_t nChar, Mask<FWL_EVENTFLAG> nFlag) override; 45 CFX_FloatRect GetFocusRect() const override; 46 void OnSetFocus() override; 47 void OnKillFocus() override; 48 void OnCreated() override; 49 void OnDestroy() override; 50 bool OnLButtonDown(Mask<FWL_EVENTFLAG> nFlag, 51 const CFX_PointF& point) override; 52 bool OnLButtonUp(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point) override; 53 bool OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlag, 54 const CFX_PointF& point) override; 55 bool OnRButtonUp(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point) override; 56 bool OnMouseMove(Mask<FWL_EVENTFLAG> nFlag, const CFX_PointF& point) override; 57 void SetScrollInfo(const PWL_SCROLL_INFO& info) override; 58 void SetScrollPosition(float pos) override; 59 void ScrollWindowVertically(float pos) override; 60 void CreateChildWnd(const CreateParams& cp) override; 61 void SetFontSize(float fFontSize) override; 62 float GetFontSize() const override; 63 void SetCursor() override; 64 WideString GetText() override; 65 WideString GetSelectedText() override; 66 void ReplaceAndKeepSelection(const WideString& text) override; 67 void ReplaceSelection(const WideString& text) override; 68 bool SelectAllText() override; 69 bool CanUndo() override; 70 bool CanRedo() override; 71 bool Undo() override; 72 bool Redo() override; 73 74 void SetSelection(int32_t nStartChar, int32_t nEndChar); 75 std::pair<int32_t, int32_t> GetSelection() const; 76 void ClearSelection(); 77 78 CFX_PointF GetScrollPos() const; 79 void SetScrollPos(const CFX_PointF& point); 80 SetCharSet(FX_Charset nCharSet)81 void SetCharSet(FX_Charset nCharSet) { m_nCharSet = nCharSet; } GetCharSet()82 FX_Charset GetCharSet() const { return m_nCharSet; } 83 84 void SetReadyToInput(); 85 void SetAlignFormatVerticalCenter(); 86 void SetCharArray(int32_t nCharArray); 87 void SetLimitChar(int32_t nLimitChar); 88 bool CanSelectAll() const; 89 bool CanCopy() const; 90 bool CanCut() const; 91 void CutText(); 92 void SetText(const WideString& csText); 93 bool IsTextFull() const; 94 95 static float GetCharArrayAutoFontSize(const CPDF_Font* pFont, 96 const CFX_FloatRect& rcPlate, 97 int32_t nCharArray); 98 99 bool SetCaret(bool bVisible, 100 const CFX_PointF& ptHead, 101 const CFX_PointF& ptFoot); 102 103 private: 104 // In case of implementation swallow the OnKeyDown event. If the event is 105 // swallowed, implementation may do other unexpected things, which is not the 106 // control means to do. 107 static bool IsProceedtoOnChar(FWL_VKEYCODE nKeyCode, 108 Mask<FWL_EVENTFLAG> nFlag); 109 110 bool OnKeyDownInternal(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlag); 111 bool OnCharInternal(uint16_t nChar, Mask<FWL_EVENTFLAG> nFlag); 112 113 void CopyText(); 114 void PasteText(); 115 void InsertWord(uint16_t word, FX_Charset nCharset); 116 void InsertReturn(); 117 bool IsWndHorV() const; 118 void Delete(); 119 void Backspace(); 120 void GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const; 121 void SetEditCaret(bool bVisible); 122 123 void CreateEditCaret(const CreateParams& cp); 124 125 CPVT_WordRange GetSelectWordRange() const; 126 bool IsVScrollBarVisible() const; 127 void SetParamByFlag(); 128 129 bool m_bMouseDown = false; 130 bool m_bFocus = false; 131 FX_Charset m_nCharSet = FX_Charset::kDefault; 132 CFX_FloatRect m_rcOldWindow; 133 std::unique_ptr<CPWL_EditImpl> const m_pEditImpl; 134 UnownedPtr<CPWL_Caret> m_pCaret; 135 }; 136 137 #endif // FPDFSDK_PWL_CPWL_EDIT_H_ 138