blob: 15d20bf7cb9f47e6b2c9582b335a9905c9ced762 [file] [log] [blame]
Tom Sepez99ffdb02016-01-26 14:51:21 -08001// 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
dsinclair447b1f32016-12-08 10:06:32 -08007#ifndef XFA_FWL_CFWL_EDIT_H_
8#define XFA_FWL_CFWL_EDIT_H_
Tom Sepezab277682016-02-17 10:07:21 -08009
dsinclair2c489cc2016-11-23 16:17:20 -080010#include <deque>
11#include <memory>
Tom Sepezab277682016-02-17 10:07:21 -080012#include <vector>
13
dsinclair2c489cc2016-11-23 16:17:20 -080014#include "xfa/fde/cfde_txtedtengine.h"
15#include "xfa/fde/ifde_txtedtdorecord.h"
dsinclair447b1f32016-12-08 10:06:32 -080016#include "xfa/fwl/cfwl_event.h"
17#include "xfa/fwl/cfwl_scrollbar.h"
18#include "xfa/fwl/cfwl_widget.h"
Dan Sinclair2b918c82017-07-13 14:47:10 -040019#include "xfa/fxgraphics/cxfa_path.h"
dsinclair2c489cc2016-11-23 16:17:20 -080020
21#define FWL_STYLEEXT_EDT_ReadOnly (1L << 0)
22#define FWL_STYLEEXT_EDT_MultiLine (1L << 1)
23#define FWL_STYLEEXT_EDT_WantReturn (1L << 2)
dsinclair2c489cc2016-11-23 16:17:20 -080024#define FWL_STYLEEXT_EDT_AutoHScroll (1L << 4)
25#define FWL_STYLEEXT_EDT_AutoVScroll (1L << 5)
dsinclair2c489cc2016-11-23 16:17:20 -080026#define FWL_STYLEEXT_EDT_Validate (1L << 7)
27#define FWL_STYLEEXT_EDT_Password (1L << 8)
28#define FWL_STYLEEXT_EDT_Number (1L << 9)
dsinclair2c489cc2016-11-23 16:17:20 -080029#define FWL_STYLEEXT_EDT_CombText (1L << 17)
dsinclairaefbe4b2016-12-14 13:21:18 -080030#define FWL_STYLEEXT_EDT_HNear 0
dsinclair2c489cc2016-11-23 16:17:20 -080031#define FWL_STYLEEXT_EDT_HCenter (1L << 18)
32#define FWL_STYLEEXT_EDT_HFar (2L << 18)
dsinclairaefbe4b2016-12-14 13:21:18 -080033#define FWL_STYLEEXT_EDT_VNear 0
dsinclair2c489cc2016-11-23 16:17:20 -080034#define FWL_STYLEEXT_EDT_VCenter (1L << 20)
35#define FWL_STYLEEXT_EDT_VFar (2L << 20)
36#define FWL_STYLEEXT_EDT_Justified (1L << 22)
dsinclair2c489cc2016-11-23 16:17:20 -080037#define FWL_STYLEEXT_EDT_HAlignMask (3L << 18)
38#define FWL_STYLEEXT_EDT_VAlignMask (3L << 20)
39#define FWL_STYLEEXT_EDT_HAlignModeMask (3L << 22)
dsinclair2c489cc2016-11-23 16:17:20 -080040#define FWL_STYLEEXT_EDT_ShowScrollbarFocus (1L << 25)
41#define FWL_STYLEEXT_EDT_OuterScrollbar (1L << 26)
42#define FWL_STYLEEXT_EDT_LastLineHeight (1L << 27)
Tom Sepezab277682016-02-17 10:07:21 -080043
dsinclairbe9b8942016-05-18 06:09:33 -070044class IFDE_TxtEdtDoRecord;
dsinclair2c489cc2016-11-23 16:17:20 -080045class CFWL_Edit;
dsinclair447b1f32016-12-08 10:06:32 -080046class CFWL_MessageMouse;
dsinclair2c489cc2016-11-23 16:17:20 -080047class CFWL_WidgetProperties;
48class CFWL_Caret;
Tom Sepezab277682016-02-17 10:07:21 -080049
Tom Sepez99ffdb02016-01-26 14:51:21 -080050class CFWL_Edit : public CFWL_Widget {
51 public:
dsinclair2c489cc2016-11-23 16:17:20 -080052 CFWL_Edit(const CFWL_App* app,
53 std::unique_ptr<CFWL_WidgetProperties> properties,
54 CFWL_Widget* pOuter);
weili4ce94e12016-06-18 06:21:57 -070055 ~CFWL_Edit() override;
56
dsinclair2c489cc2016-11-23 16:17:20 -080057 // CFWL_Widget:
58 FWL_Type GetClassID() const override;
dsinclairda911bc2016-12-07 18:47:00 -080059 CFX_RectF GetAutosizedWidgetRect() override;
60 CFX_RectF GetWidgetRect() override;
dsinclair2c489cc2016-11-23 16:17:20 -080061 void Update() override;
Dan Sinclairb45ea1f2017-02-21 14:27:59 -050062 FWL_WidgetHit HitTest(const CFX_PointF& point) override;
dsinclair7fa190d2016-12-07 17:23:28 -080063 void SetStates(uint32_t dwStates) override;
Dan Sinclair2b918c82017-07-13 14:47:10 -040064 void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override;
dsinclair2c489cc2016-11-23 16:17:20 -080065 void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override;
66 void OnProcessMessage(CFWL_Message* pMessage) override;
67 void OnProcessEvent(CFWL_Event* pEvent) override;
Dan Sinclair2b918c82017-07-13 14:47:10 -040068 void OnDrawWidget(CXFA_Graphics* pGraphics,
dsinclair2c489cc2016-11-23 16:17:20 -080069 const CFX_Matrix* pMatrix) override;
dsinclair20855382016-10-31 07:29:34 -070070
dsinclair2c489cc2016-11-23 16:17:20 -080071 virtual void SetText(const CFX_WideString& wsText);
72
73 int32_t GetTextLength() const;
dsinclair442997c2016-12-07 17:58:41 -080074 CFX_WideString GetText() const;
dsinclair2c489cc2016-11-23 16:17:20 -080075 void ClearText();
dsinclair38eaf4b2016-11-15 12:33:06 -080076
dsinclair442997c2016-12-07 17:58:41 -080077 void AddSelRange(int32_t nStart);
dsinclair38eaf4b2016-11-15 12:33:06 -080078 int32_t CountSelRanges() const;
dsinclair442997c2016-12-07 17:58:41 -080079 int32_t GetSelRange(int32_t nIndex, int32_t* nStart) const;
dsinclair2c489cc2016-11-23 16:17:20 -080080 void ClearSelections();
dsinclair38eaf4b2016-11-15 12:33:06 -080081 int32_t GetLimit() const;
dsinclair522c3d42016-11-10 14:01:19 -080082 void SetLimit(int32_t nLimit);
Dan Sinclair812e96c2017-03-13 16:43:37 -040083 void SetAliasChar(wchar_t wAlias);
dsinclair2c489cc2016-11-23 16:17:20 -080084 bool Copy(CFX_WideString& wsCopy);
85 bool Cut(CFX_WideString& wsCut);
86 bool Paste(const CFX_WideString& wsPaste);
87 bool Redo(const IFDE_TxtEdtDoRecord* pRecord);
88 bool Undo(const IFDE_TxtEdtDoRecord* pRecord);
89 bool Undo();
90 bool Redo();
91 bool CanUndo();
92 bool CanRedo();
dsinclair38eaf4b2016-11-15 12:33:06 -080093
dsinclair2c489cc2016-11-23 16:17:20 -080094 void SetOuter(CFWL_Widget* pOuter);
95
dsinclair442997c2016-12-07 17:58:41 -080096 void OnCaretChanged();
97 void OnTextChanged(const FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo);
98 void OnSelChanged();
99 bool OnPageLoad(int32_t nPageIndex);
100 bool OnPageUnload(int32_t nPageIndex);
101 void OnAddDoRecord(std::unique_ptr<IFDE_TxtEdtDoRecord> pRecord);
102 bool OnValidate(const CFX_WideString& wsText);
Dan Sinclair05df0752017-03-14 14:43:42 -0400103 void SetScrollOffset(float fScrollOffset);
dsinclair2c489cc2016-11-23 16:17:20 -0800104
105 protected:
dsinclair919c0842016-12-07 17:12:59 -0800106 void ShowCaret(CFX_RectF* pRect);
107 void HideCaret(CFX_RectF* pRect);
dsinclair2c489cc2016-11-23 16:17:20 -0800108 const CFX_RectF& GetRTClient() const { return m_rtClient; }
109 CFDE_TxtEdtEngine* GetTxtEdtEngine() { return &m_EdtEngine; }
110
111 private:
Dan Sinclair2b918c82017-07-13 14:47:10 -0400112 void DrawTextBk(CXFA_Graphics* pGraphics,
dsinclair2c489cc2016-11-23 16:17:20 -0800113 IFWL_ThemeProvider* pTheme,
dsinclair442997c2016-12-07 17:58:41 -0800114 const CFX_Matrix* pMatrix);
Dan Sinclair2b918c82017-07-13 14:47:10 -0400115 void DrawContent(CXFA_Graphics* pGraphics,
dsinclair2c489cc2016-11-23 16:17:20 -0800116 IFWL_ThemeProvider* pTheme,
dsinclair442997c2016-12-07 17:58:41 -0800117 const CFX_Matrix* pMatrix);
Dan Sinclair2b918c82017-07-13 14:47:10 -0400118 void DrawSpellCheck(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix);
dsinclair442997c2016-12-07 17:58:41 -0800119
dsinclair2c489cc2016-11-23 16:17:20 -0800120 void UpdateEditEngine();
121 void UpdateEditParams();
122 void UpdateEditLayout();
123 bool UpdateOffset();
Dan Sinclair05df0752017-03-14 14:43:42 -0400124 bool UpdateOffset(CFWL_ScrollBar* pScrollBar, float fPosChanged);
dsinclair2c489cc2016-11-23 16:17:20 -0800125 void UpdateVAlignment();
126 void UpdateCaret();
127 CFWL_ScrollBar* UpdateScroll();
128 void Layout();
129 void LayoutScrollBar();
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500130 CFX_PointF DeviceToEngine(const CFX_PointF& pt);
dsinclair442997c2016-12-07 17:58:41 -0800131 void InitVerticalScrollBar();
132 void InitHorizontalScrollBar();
dsinclair2c489cc2016-11-23 16:17:20 -0800133 void InitEngine();
dsinclair2c489cc2016-11-23 16:17:20 -0800134 void InitCaret();
Dan Sinclair812e96c2017-03-13 16:43:37 -0400135 bool ValidateNumberChar(wchar_t cNum);
dsinclair2c489cc2016-11-23 16:17:20 -0800136 void ClearRecord();
137 bool IsShowScrollBar(bool bVert);
138 bool IsContentHeightOverflow();
dsinclair442997c2016-12-07 17:58:41 -0800139 int32_t AddDoRecord(std::unique_ptr<IFDE_TxtEdtDoRecord> pRecord);
dsinclair2c489cc2016-11-23 16:17:20 -0800140 void ProcessInsertError(int32_t iError);
Dan Sinclair2b918c82017-07-13 14:47:10 -0400141 void AddSpellCheckObj(CXFA_Path& PathData,
dsinclair2c489cc2016-11-23 16:17:20 -0800142 int32_t nStart,
143 int32_t nCount,
Dan Sinclair05df0752017-03-14 14:43:42 -0400144 float fOffSetX,
145 float fOffSetY);
dsinclair442997c2016-12-07 17:58:41 -0800146
dsinclair447b1f32016-12-08 10:06:32 -0800147 void DoButtonDown(CFWL_MessageMouse* pMsg);
dsinclair2c489cc2016-11-23 16:17:20 -0800148 void OnFocusChanged(CFWL_Message* pMsg, bool bSet);
dsinclair447b1f32016-12-08 10:06:32 -0800149 void OnLButtonDown(CFWL_MessageMouse* pMsg);
150 void OnLButtonUp(CFWL_MessageMouse* pMsg);
151 void OnButtonDblClk(CFWL_MessageMouse* pMsg);
152 void OnMouseMove(CFWL_MessageMouse* pMsg);
153 void OnKeyDown(CFWL_MessageKey* pMsg);
154 void OnChar(CFWL_MessageKey* pMsg);
dsinclair4614b452016-12-07 17:01:58 -0800155 bool OnScroll(CFWL_ScrollBar* pScrollBar,
dsinclair447b1f32016-12-08 10:06:32 -0800156 CFWL_EventScroll::Code dwCode,
Dan Sinclair05df0752017-03-14 14:43:42 -0400157 float fPos);
dsinclair2c489cc2016-11-23 16:17:20 -0800158
159 CFX_RectF m_rtClient;
160 CFX_RectF m_rtEngine;
161 CFX_RectF m_rtStatic;
Dan Sinclair05df0752017-03-14 14:43:42 -0400162 float m_fVAlignOffset;
163 float m_fScrollOffsetX;
164 float m_fScrollOffsetY;
dsinclair2c489cc2016-11-23 16:17:20 -0800165 CFDE_TxtEdtEngine m_EdtEngine;
166 bool m_bLButtonDown;
167 int32_t m_nSelStart;
168 int32_t m_nLimit;
Dan Sinclair05df0752017-03-14 14:43:42 -0400169 float m_fFontSize;
dsinclair2c489cc2016-11-23 16:17:20 -0800170 bool m_bSetRange;
171 int32_t m_iMax;
172 std::unique_ptr<CFWL_ScrollBar> m_pVertScrollBar;
173 std::unique_ptr<CFWL_ScrollBar> m_pHorzScrollBar;
174 std::unique_ptr<CFWL_Caret> m_pCaret;
175 CFX_WideString m_wsCache;
176 CFX_WideString m_wsFont;
177 std::deque<std::unique_ptr<IFDE_TxtEdtDoRecord>> m_DoRecords;
178 int32_t m_iCurRecord;
179 int32_t m_iMaxRecord;
Tom Sepez99ffdb02016-01-26 14:51:21 -0800180};
Tom Sepezab277682016-02-17 10:07:21 -0800181
dsinclair447b1f32016-12-08 10:06:32 -0800182#endif // XFA_FWL_CFWL_EDIT_H_