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