• 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_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/unowned_ptr.h"
15 #include "fpdfsdk/pwl/cpwl_edit_ctrl.h"
16 #include "fpdfsdk/pwl/ipwl_systemhandler.h"
17 
18 class CPDF_Font;
19 
20 class IPWL_Filler_Notify {
21  public:
22   virtual ~IPWL_Filler_Notify() = default;
23 
24   // Must write to |bBottom| and |fPopupRet|.
25   virtual void QueryWherePopup(
26       const IPWL_SystemHandler::PerWindowData* pAttached,
27       float fPopupMin,
28       float fPopupMax,
29       bool* bBottom,
30       float* fPopupRet) = 0;
31 
32   virtual std::pair<bool, bool> OnBeforeKeyStroke(
33       const IPWL_SystemHandler::PerWindowData* pAttached,
34       WideString& strChange,
35       const WideString& strChangeEx,
36       int nSelStart,
37       int nSelEnd,
38       bool bKeyDown,
39       uint32_t nFlag) = 0;
40 
41   virtual bool OnPopupPreOpen(
42       const IPWL_SystemHandler::PerWindowData* pAttached,
43       uint32_t nFlag) = 0;
44 
45   virtual bool OnPopupPostOpen(
46       const IPWL_SystemHandler::PerWindowData* pAttached,
47       uint32_t nFlag) = 0;
48 };
49 
50 class CPWL_Edit final : public CPWL_EditCtrl {
51  public:
52   CPWL_Edit(const CreateParams& cp,
53             std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData);
54   ~CPWL_Edit() override;
55 
56   // CPWL_EditCtrl
57   void OnCreated() override;
58   bool RePosChildWnd() override;
59   CFX_FloatRect GetClientRect() const override;
60   void DrawThisAppearance(CFX_RenderDevice* pDevice,
61                           const CFX_Matrix& mtUser2Device) override;
62   bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override;
63   bool OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag) override;
64   bool OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) override;
65   bool OnMouseWheel(short zDelta,
66                     const CFX_PointF& point,
67                     uint32_t nFlag) override;
68   bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override;
69   bool OnChar(uint16_t nChar, uint32_t nFlag) override;
70   CFX_FloatRect GetFocusRect() const override;
71   void OnSetFocus() override;
72   void OnKillFocus() override;
73 
74   void SetAlignFormatVerticalCenter();
75   void SetCharArray(int32_t nCharArray);
76   void SetLimitChar(int32_t nLimitChar);
77   void SetCharSpace(float fCharSpace);
78 
79   bool CanSelectAll() const;
80   bool CanCopy() const;
81   bool CanCut() const;
82 
83   void CutText();
84 
85   void SetText(const WideString& csText);
86 
87   bool IsTextFull() const;
88 
89   static float GetCharArrayAutoFontSize(const CPDF_Font* pFont,
90                                         const CFX_FloatRect& rcPlate,
91                                         int32_t nCharArray);
92 
SetFillerNotify(IPWL_Filler_Notify * pNotify)93   void SetFillerNotify(IPWL_Filler_Notify* pNotify) {
94     m_pFillerNotify = pNotify;
95   }
96 
AttachFFLData(CFFL_FormFiller * pData)97   void AttachFFLData(CFFL_FormFiller* pData) { m_pFormFiller = pData; }
98 
99   void OnInsertWord(const CPVT_WordPlace& place,
100                     const CPVT_WordPlace& oldplace);
101   void OnInsertReturn(const CPVT_WordPlace& place,
102                       const CPVT_WordPlace& oldplace);
103   void OnBackSpace(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
104   void OnDelete(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
105   void OnClear(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
106   void OnInsertText(const CPVT_WordPlace& place,
107                     const CPVT_WordPlace& oldplace);
108 
109  private:
110   // In case of implementation swallow the OnKeyDown event. If the event is
111   // swallowed, implementation may do other unexpected things, which is not the
112   // control means to do.
113   static bool IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag);
114 
115   CPVT_WordRange GetSelectWordRange() const;
116   bool IsVScrollBarVisible() const;
117   void SetParamByFlag();
118 
119   CFX_PointF GetWordRightBottomPoint(const CPVT_WordPlace& wpWord);
120 
121   CPVT_WordRange CombineWordRange(const CPVT_WordRange& wr1,
122                                   const CPVT_WordRange& wr2);
123   CPVT_WordRange GetLatinWordsRange(const CFX_PointF& point) const;
124   CPVT_WordRange GetLatinWordsRange(const CPVT_WordPlace& place) const;
125   CPVT_WordRange GetSameWordsRange(const CPVT_WordPlace& place,
126                                    bool bLatin,
127                                    bool bArabic) const;
128 
129   bool m_bFocus = false;
130   CFX_FloatRect m_rcOldWindow;
131   UnownedPtr<IPWL_Filler_Notify> m_pFillerNotify;
132   UnownedPtr<CFFL_FormFiller> m_pFormFiller;
133 };
134 
135 #endif  // FPDFSDK_PWL_CPWL_EDIT_H_
136