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