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