PWL_EditCtrl.h revision 4d3acf4ec42bf6e838f9060103aff98fbf170794
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 FPDFSDK_PDFWINDOW_PWL_EDITCTRL_H_ 8#define FPDFSDK_PDFWINDOW_PWL_EDITCTRL_H_ 9 10#include <memory> 11 12#include "core/fxcrt/fx_string.h" 13#include "fpdfsdk/fxedit/fx_edit.h" 14#include "fpdfsdk/pdfwindow/PWL_Wnd.h" 15 16class CFX_Edit; 17class CPWL_Caret; 18class CPWL_Edit; 19class CPWL_EditCtrl; 20struct CPVT_SecProps; 21struct CPVT_WordPlace; 22struct CPVT_WordProps; 23struct CPVT_WordRange; 24 25enum PWL_EDIT_ALIGNFORMAT_H { PEAH_LEFT = 0, PEAH_MIDDLE, PEAH_RIGHT }; 26 27enum PWL_EDIT_ALIGNFORMAT_V { PEAV_TOP = 0, PEAV_CENTER, PEAV_BOTTOM }; 28 29class CPWL_EditCtrl : public CPWL_Wnd { 30 friend class CPWL_Edit_Notify; 31 32 public: 33 CPWL_EditCtrl(); 34 ~CPWL_EditCtrl() override; 35 36 CFX_FloatRect GetContentRect() const; 37 void GetCaretPos(int32_t& x, int32_t& y) const; 38 39 CFX_WideString GetText() const; 40 void SetSel(int32_t nStartChar, int32_t nEndChar); 41 void GetSel(int32_t& nStartChar, int32_t& nEndChar) const; 42 void GetTextRange(const CFX_FloatRect& rect, 43 int32_t& nStartChar, 44 int32_t& nEndChar) const; 45 CFX_WideString GetText(int32_t& nStartChar, int32_t& nEndChar) const; 46 void Clear(); 47 void SelectAll(); 48 49 int32_t GetCaret() const; 50 void SetCaret(int32_t nPos); 51 int32_t GetTotalWords() const; 52 53 void Paint(); 54 55 void EnableRefresh(bool bRefresh); 56 CFX_FloatPoint GetScrollPos() const; 57 void SetScrollPos(const CFX_FloatPoint& point); 58 59 void SetCharSet(uint8_t nCharSet) { m_nCharSet = nCharSet; } 60 int32_t GetCharSet() const; 61 62 void SetCodePage(int32_t nCodePage) { m_nCodePage = nCodePage; } 63 int32_t GetCodePage() const { return m_nCodePage; } 64 65 CPDF_Font* GetCaretFont() const; 66 FX_FLOAT GetCaretFontSize() const; 67 68 bool CanUndo() const; 69 bool CanRedo() const; 70 void Redo(); 71 void Undo(); 72 73 void SetReadyToInput(); 74 75 // CPWL_Wnd 76 void OnCreate(PWL_CREATEPARAM& cp) override; 77 void OnCreated() override; 78 bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override; 79 bool OnChar(uint16_t nChar, uint32_t nFlag) override; 80 bool OnLButtonDown(const CFX_FloatPoint& point, uint32_t nFlag) override; 81 bool OnLButtonUp(const CFX_FloatPoint& point, uint32_t nFlag) override; 82 bool OnMouseMove(const CFX_FloatPoint& point, uint32_t nFlag) override; 83 void OnNotify(CPWL_Wnd* pWnd, 84 uint32_t msg, 85 intptr_t wParam = 0, 86 intptr_t lParam = 0) override; 87 void CreateChildWnd(const PWL_CREATEPARAM& cp) override; 88 void RePosChildWnd() override; 89 void SetFontSize(FX_FLOAT fFontSize) override; 90 FX_FLOAT GetFontSize() const override; 91 void SetCursor() override; 92 93 void IOnSetScrollInfoY(FX_FLOAT fPlateMin, 94 FX_FLOAT fPlateMax, 95 FX_FLOAT fContentMin, 96 FX_FLOAT fContentMax, 97 FX_FLOAT fSmallStep, 98 FX_FLOAT fBigStep); 99 void IOnSetScrollPosY(FX_FLOAT fy); 100 void IOnSetCaret(bool bVisible, 101 const CFX_FloatPoint& ptHead, 102 const CFX_FloatPoint& ptFoot, 103 const CPVT_WordPlace& place); 104 void IOnCaretChange(const CPVT_SecProps& secProps, 105 const CPVT_WordProps& wordProps); 106 void IOnContentChange(const CFX_FloatRect& rcContent); 107 void IOnInvalidateRect(CFX_FloatRect* pRect); 108 109 protected: 110 void InsertText(const CFX_WideString& wsText); 111 void SetText(const CFX_WideString& wsText); 112 void CopyText(); 113 void PasteText(); 114 void CutText(); 115 void ShowVScrollBar(bool bShow); 116 void InsertWord(uint16_t word, int32_t nCharset); 117 void InsertReturn(); 118 119 bool IsWndHorV(); 120 121 void Delete(); 122 void Backspace(); 123 124 void GetCaretInfo(CFX_FloatPoint& ptHead, CFX_FloatPoint& ptFoot) const; 125 void SetCaret(bool bVisible, 126 const CFX_FloatPoint& ptHead, 127 const CFX_FloatPoint& ptFoot); 128 129 void SetEditCaret(bool bVisible); 130 131 std::unique_ptr<CFX_Edit> m_pEdit; 132 CPWL_Caret* m_pEditCaret; 133 bool m_bMouseDown; 134 135 private: 136 void CreateEditCaret(const PWL_CREATEPARAM& cp); 137 138 int32_t m_nCharSet; 139 int32_t m_nCodePage; 140}; 141 142#endif // FPDFSDK_PDFWINDOW_PWL_EDITCTRL_H_ 143