• 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 XFA_FWL_CFWL_EDIT_H_
8 #define XFA_FWL_CFWL_EDIT_H_
9 
10 #include <memory>
11 #include <utility>
12 #include <vector>
13 
14 #include "xfa/fde/cfde_texteditengine.h"
15 #include "xfa/fwl/cfwl_event.h"
16 #include "xfa/fwl/cfwl_scrollbar.h"
17 #include "xfa/fwl/cfwl_widget.h"
18 #include "xfa/fxgraphics/cxfa_gepath.h"
19 
20 #define FWL_STYLEEXT_EDT_ReadOnly (1L << 0)
21 #define FWL_STYLEEXT_EDT_MultiLine (1L << 1)
22 #define FWL_STYLEEXT_EDT_WantReturn (1L << 2)
23 #define FWL_STYLEEXT_EDT_AutoHScroll (1L << 4)
24 #define FWL_STYLEEXT_EDT_AutoVScroll (1L << 5)
25 #define FWL_STYLEEXT_EDT_Validate (1L << 7)
26 #define FWL_STYLEEXT_EDT_Password (1L << 8)
27 #define FWL_STYLEEXT_EDT_Number (1L << 9)
28 #define FWL_STYLEEXT_EDT_CombText (1L << 17)
29 #define FWL_STYLEEXT_EDT_HNear 0
30 #define FWL_STYLEEXT_EDT_HCenter (1L << 18)
31 #define FWL_STYLEEXT_EDT_HFar (2L << 18)
32 #define FWL_STYLEEXT_EDT_VNear 0
33 #define FWL_STYLEEXT_EDT_VCenter (1L << 20)
34 #define FWL_STYLEEXT_EDT_VFar (2L << 20)
35 #define FWL_STYLEEXT_EDT_Justified (1L << 22)
36 #define FWL_STYLEEXT_EDT_HAlignMask (3L << 18)
37 #define FWL_STYLEEXT_EDT_VAlignMask (3L << 20)
38 #define FWL_STYLEEXT_EDT_HAlignModeMask (3L << 22)
39 #define FWL_STYLEEXT_EDT_ShowScrollbarFocus (1L << 25)
40 #define FWL_STYLEEXT_EDT_OuterScrollbar (1L << 26)
41 
42 class CFWL_Edit;
43 class CFWL_MessageMouse;
44 class CFWL_WidgetProperties;
45 class CFWL_Caret;
46 
47 class CFWL_Edit : public CFWL_Widget, public CFDE_TextEditEngine::Delegate {
48  public:
49   CFWL_Edit(const CFWL_App* app,
50             std::unique_ptr<CFWL_WidgetProperties> properties,
51             CFWL_Widget* pOuter);
52   ~CFWL_Edit() override;
53 
54   // CFWL_Widget:
55   FWL_Type GetClassID() const override;
56   CFX_RectF GetAutosizedWidgetRect() override;
57   CFX_RectF GetWidgetRect() override;
58   void Update() override;
59   FWL_WidgetHit HitTest(const CFX_PointF& point) override;
60   void SetStates(uint32_t dwStates) override;
61   void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
62   void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override;
63   void OnProcessMessage(CFWL_Message* pMessage) override;
64   void OnProcessEvent(CFWL_Event* pEvent) override;
65   void OnDrawWidget(CXFA_Graphics* pGraphics,
66                     const CFX_Matrix& matrix) override;
67 
68   virtual void SetText(const WideString& wsText);
69 
70   int32_t GetTextLength() const;
71   WideString GetText() const;
72   void ClearText();
73 
74   void SelectAll();
75   void ClearSelection();
76   bool HasSelection() const;
77   // Returns <start, count> of the selection.
78   std::pair<size_t, size_t> GetSelection() const;
79 
80   int32_t GetLimit() const;
81   void SetLimit(int32_t nLimit);
82   void SetAliasChar(wchar_t wAlias);
83   Optional<WideString> Copy();
84   Optional<WideString> Cut();
85   bool Paste(const WideString& wsPaste);
86   bool Undo();
87   bool Redo();
88   bool CanUndo();
89   bool CanRedo();
90 
91   void SetOuter(CFWL_Widget* pOuter);
92 
93   // CFDE_TextEditEngine::Delegate
94   void NotifyTextFull() override;
95   void OnCaretChanged() override;
96   void OnTextChanged(const WideString& prevText) override;
97   void OnSelChanged() override;
98   bool OnValidate(const WideString& wsText) override;
99   void SetScrollOffset(float fScrollOffset) override;
100 
101  protected:
102   void ShowCaret(CFX_RectF* pRect);
103   void HideCaret(CFX_RectF* pRect);
GetRTClient()104   const CFX_RectF& GetRTClient() const { return m_rtClient; }
GetTxtEdtEngine()105   CFDE_TextEditEngine* GetTxtEdtEngine() { return &m_EdtEngine; }
106 
107  private:
108   void RenderText(CFX_RenderDevice* pRenderDev,
109                   const CFX_RectF& clipRect,
110                   const CFX_Matrix& mt);
111   void DrawTextBk(CXFA_Graphics* pGraphics,
112                   IFWL_ThemeProvider* pTheme,
113                   const CFX_Matrix* pMatrix);
114   void DrawContent(CXFA_Graphics* pGraphics,
115                    IFWL_ThemeProvider* pTheme,
116                    const CFX_Matrix* pMatrix);
117   void DrawSpellCheck(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix);
118 
119   void UpdateEditEngine();
120   void UpdateEditParams();
121   void UpdateEditLayout();
122   bool UpdateOffset();
123   bool UpdateOffset(CFWL_ScrollBar* pScrollBar, float fPosChanged);
124   void UpdateVAlignment();
125   void UpdateCaret();
126   CFWL_ScrollBar* UpdateScroll();
127   void Layout();
128   void LayoutScrollBar();
129   CFX_PointF DeviceToEngine(const CFX_PointF& pt);
130   void InitVerticalScrollBar();
131   void InitHorizontalScrollBar();
132   void InitEngine();
133   void InitCaret();
134   bool ValidateNumberChar(wchar_t cNum);
135   bool IsShowScrollBar(bool bVert);
136   bool IsContentHeightOverflow();
137   void AddSpellCheckObj(CXFA_GEPath& PathData,
138                         int32_t nStart,
139                         int32_t nCount,
140                         float fOffSetX,
141                         float fOffSetY);
142   void SetCursorPosition(size_t position);
143   void UpdateCursorRect();
144 
145   void DoRButtonDown(CFWL_MessageMouse* pMsg);
146   void OnFocusChanged(CFWL_Message* pMsg, bool bSet);
147   void OnLButtonDown(CFWL_MessageMouse* pMsg);
148   void OnLButtonUp(CFWL_MessageMouse* pMsg);
149   void OnButtonDoubleClick(CFWL_MessageMouse* pMsg);
150   void OnMouseMove(CFWL_MessageMouse* pMsg);
151   void OnKeyDown(CFWL_MessageKey* pMsg);
152   void OnChar(CFWL_MessageKey* pMsg);
153   bool OnScroll(CFWL_ScrollBar* pScrollBar,
154                 CFWL_EventScroll::Code dwCode,
155                 float fPos);
156 
157   CFX_RectF m_rtClient;
158   CFX_RectF m_rtEngine;
159   CFX_RectF m_rtStatic;
160   CFX_RectF m_rtCaret;
161   float m_fVAlignOffset;
162   float m_fScrollOffsetX;
163   float m_fScrollOffsetY;
164   CFDE_TextEditEngine m_EdtEngine;
165   bool m_bLButtonDown;
166   size_t m_CursorPosition;
167   int32_t m_nLimit;
168   float m_fFontSize;
169   bool m_bSetRange;
170   int32_t m_iMax;
171   std::unique_ptr<CFWL_ScrollBar> m_pVertScrollBar;
172   std::unique_ptr<CFWL_ScrollBar> m_pHorzScrollBar;
173   std::unique_ptr<CFWL_Caret> m_pCaret;
174   WideString m_wsCache;
175   WideString m_wsFont;
176 };
177 
178 #endif  // XFA_FWL_CFWL_EDIT_H_
179