• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PWL_CPWL_EDIT_CTRL_H_
8 #define FPDFSDK_PWL_CPWL_EDIT_CTRL_H_
9 
10 #include <memory>
11 
12 #include "core/fxcrt/fx_string.h"
13 #include "fpdfsdk/pwl/cpwl_wnd.h"
14 
15 class CPWL_EditImpl;
16 class CPWL_Caret;
17 struct CPVT_WordPlace;
18 
19 enum PWL_EDIT_ALIGNFORMAT_H { PEAH_LEFT = 0, PEAH_MIDDLE, PEAH_RIGHT };
20 
21 enum PWL_EDIT_ALIGNFORMAT_V { PEAV_TOP = 0, PEAV_CENTER, PEAV_BOTTOM };
22 
23 class CPWL_EditCtrl : public CPWL_Wnd {
24  public:
25   CPWL_EditCtrl();
26   ~CPWL_EditCtrl() override;
27 
28   WideString GetText() const;
29   void SetSelection(int32_t nStartChar, int32_t nEndChar);
30   void GetSelection(int32_t& nStartChar, int32_t& nEndChar) const;
31   void ClearSelection();
32   void SelectAll();
33 
34   CFX_PointF GetScrollPos() const;
35   void SetScrollPos(const CFX_PointF& point);
36 
SetCharSet(uint8_t nCharSet)37   void SetCharSet(uint8_t nCharSet) { m_nCharSet = nCharSet; }
38   int32_t GetCharSet() const;
39 
40   bool CanUndo() const;
41   bool CanRedo() const;
42   void Redo();
43   void Undo();
44 
45   void SetReadyToInput();
46 
47   // CPWL_Wnd:
48   void OnCreate(CreateParams* pParamsToAdjust) override;
49   void OnCreated() override;
50   bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override;
51   bool OnChar(uint16_t nChar, uint32_t nFlag) override;
52   bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override;
53   bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override;
54   bool OnMouseMove(const CFX_PointF& point, uint32_t nFlag) override;
55   void SetScrollInfo(const PWL_SCROLL_INFO& info) override;
56   void SetScrollPosition(float pos) override;
57   void ScrollWindowVertically(float pos) override;
58   void CreateChildWnd(const CreateParams& cp) override;
59   bool RePosChildWnd() override;
60   void SetFontSize(float fFontSize) override;
61   float GetFontSize() const override;
62   void SetCursor() override;
63   WideString GetSelectedText() override;
64   void ReplaceSelection(const WideString& text) override;
65 
66   bool SetCaret(bool bVisible,
67                 const CFX_PointF& ptHead,
68                 const CFX_PointF& ptFoot);
69 
70  protected:
71   void CopyText();
72   void PasteText();
73   void CutText();
74   void InsertWord(uint16_t word, int32_t nCharset);
75   void InsertReturn();
76 
77   bool IsWndHorV();
78 
79   void Delete();
80   void Backspace();
81 
82   void GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const;
83 
84   void SetEditCaret(bool bVisible);
85 
86   std::unique_ptr<CPWL_EditImpl> m_pEdit;
87   CPWL_Caret* m_pEditCaret;
88   bool m_bMouseDown;
89 
90  private:
91   void CreateEditCaret(const CreateParams& cp);
92 
93   int32_t m_nCharSet;
94 };
95 
96 #endif  // FPDFSDK_PWL_CPWL_EDIT_CTRL_H_
97