• 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 _PWL_EDITCTRL_H_
8 #define _PWL_EDITCTRL_H_
9 
10 enum PWL_EDIT_ALIGNFORMAT_H
11 {
12 	PEAH_LEFT = 0,
13 	PEAH_MIDDLE,
14 	PEAH_RIGHT
15 };
16 
17 enum PWL_EDIT_ALIGNFORMAT_V
18 {
19 	PEAV_TOP = 0,
20 	PEAV_CENTER,
21 	PEAV_BOTTOM
22 };
23 
24 class IPWL_Edit_Notify;
25 class CPWL_EditCtrl;
26 class CPWL_Caret;
27 class IFX_Edit;
28 class CPWL_Edit;
29 
30 class IPWL_Edit_Notify
31 {
32 public:
33 	//when the position of caret is changed in edit
OnCaretMove(FX_INT32 x1,FX_INT32 y1,FX_INT32 x2,FX_INT32 y2)34 	virtual void					OnCaretMove(FX_INT32 x1, FX_INT32 y1, FX_INT32 x2, FX_INT32 y2) {}
OnContentChange(const CPDF_Rect & rcContent)35 	virtual void					OnContentChange(const CPDF_Rect& rcContent){}
36 	//OprType: 0 InsertWord
37 	//1 InsertReturn
38 	//2 BackSpace
39 	//3 Delete
40 	//4 Clear
41 	//5 InsertText
42 	//6 SetText
OnInsertWord(const CPVT_WordPlace & place,const CPVT_WordPlace & oldplace)43 	virtual void					OnInsertWord(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace){}
OnInsertReturn(const CPVT_WordPlace & place,const CPVT_WordPlace & oldplace)44 	virtual void					OnInsertReturn(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace){}
OnBackSpace(const CPVT_WordPlace & place,const CPVT_WordPlace & oldplace)45 	virtual void					OnBackSpace(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace){}
OnDelete(const CPVT_WordPlace & place,const CPVT_WordPlace & oldplace)46 	virtual void					OnDelete(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace){}
OnClear(const CPVT_WordPlace & place,const CPVT_WordPlace & oldplace)47 	virtual void					OnClear(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace){}
OnInsertText(const CPVT_WordPlace & place,const CPVT_WordPlace & oldplace)48 	virtual void					OnInsertText(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace){}
OnSetText(const CPVT_WordPlace & place,const CPVT_WordPlace & oldplace)49 	virtual void					OnSetText(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace){}
OnAddUndo(CPWL_Edit * pEdit)50 	virtual void					OnAddUndo(CPWL_Edit* pEdit) {}
51 };
52 
53 class PWL_CLASS CPWL_EditCtrl : public CPWL_Wnd, public IFX_Edit_Notify
54 {
55 	friend class CPWL_Edit_Notify;
56 
57 public:
58 	CPWL_EditCtrl();
59 	virtual ~CPWL_EditCtrl();
60 
61 public:
62 	virtual void					OnCreate(PWL_CREATEPARAM & cp);
63 	virtual void					OnCreated();
64 
65 	virtual FX_BOOL					OnKeyDown(FX_WORD nChar, FX_DWORD nFlag);
66 	virtual FX_BOOL					OnChar(FX_WORD nChar, FX_DWORD nFlag);
67 	virtual FX_BOOL					OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag);
68 	virtual FX_BOOL					OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag);
69 	virtual FX_BOOL					OnMouseMove(const CPDF_Point & point, FX_DWORD nFlag);
70 	virtual void					OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam = 0, FX_INTPTR lParam = 0);
71 
72 	virtual void					CreateChildWnd(const PWL_CREATEPARAM & cp);
73 	virtual void					RePosChildWnd();
74 	virtual void					SetFontSize(FX_FLOAT fFontSize);
75 	virtual FX_FLOAT				GetFontSize() const;
76 
77 public:
78 	virtual void					SetText(FX_LPCWSTR csText);
79 
80 	virtual void					CopyText();
81 	virtual void					PasteText();
82 	virtual void 					CutText();
83 
84 	CPDF_Rect						GetContentRect() const;
85 	void							GetCaretPos(FX_INT32& x, FX_INT32& y) const;
86 	FX_BOOL							IsModified() const;
87 
88 	CFX_WideString					GetText() const;
89 	void							SetSel(FX_INT32 nStartChar,FX_INT32 nEndChar);
90 	void							GetSel(FX_INT32 & nStartChar, FX_INT32 & nEndChar ) const;
91 	void							GetTextRange(const CPDF_Rect& rect, FX_INT32 & nStartChar, FX_INT32 & nEndChar) const;
92 	CFX_WideString					GetText(FX_INT32 & nStartChar, FX_INT32 & nEndChar) const;
93 	void							Clear();
94 	void							SelectAll();
95 
96 	FX_INT32						GetCaret() const;
97 	void							SetCaret(FX_INT32 nPos);
98 	FX_INT32						GetTotalWords() const;
99 
100 	void							Paint();
101 
102 	void							EnableRefresh(FX_BOOL bRefresh);
103 	CPDF_Point						GetScrollPos() const;
104 	void							SetScrollPos(const CPDF_Point& point);
105 
SetEditNotify(IPWL_Edit_Notify * pNotify)106 	void							SetEditNotify(IPWL_Edit_Notify* pNotify) {m_pEditNotify = pNotify;}
107 
SetCharSet(FX_BYTE nCharSet)108 	void							SetCharSet(FX_BYTE nCharSet){m_nCharSet = nCharSet;}
109 	FX_INT32						GetCharSet() const;
110 
SetCodePage(FX_INT32 nCodePage)111 	void							SetCodePage(FX_INT32 nCodePage){m_nCodePage = nCodePage;}
GetCodePage()112 	FX_INT32						GetCodePage() const {return m_nCodePage;}
113 
114 	CPDF_Font *						GetCaretFont() const;
115 	FX_FLOAT						GetCaretFontSize() const;
116 
117 	FX_BOOL							CanUndo() const;
118 	FX_BOOL							CanRedo() const;
119 	void							Redo();
120 	void							Undo();
121 
122 	void							SetReadyToInput();
123 protected:
124 	virtual void					ShowVScrollBar(FX_BOOL bShow);
125 
126 	virtual void					InsertWord(FX_WORD word, FX_INT32 nCharset);
127 	virtual void					InsertReturn();
128 	virtual void					InsertText(FX_LPCWSTR csText);
129 
130 	virtual void					SetCursor();
131 	FX_BOOL							IsWndHorV();
132 
133 	void							Delete();
134 	void							Backspace();
135 
136 protected:
137 	void							GetCaretInfo(CPDF_Point & ptHead, CPDF_Point & ptFoot) const;
138 	void							SetCaret(FX_BOOL bVisible, const CPDF_Point & ptHead, const CPDF_Point & ptFoot);
139 
140 	void							SetEditCaret(FX_BOOL bVisible);
141 
142 protected:
IOnSetScrollInfoX(FX_FLOAT fPlateMin,FX_FLOAT fPlateMax,FX_FLOAT fContentMin,FX_FLOAT fContentMax,FX_FLOAT fSmallStep,FX_FLOAT fBigStep)143 	virtual void					IOnSetScrollInfoX(FX_FLOAT fPlateMin, FX_FLOAT fPlateMax,
144 												FX_FLOAT fContentMin, FX_FLOAT fContentMax,
145 												FX_FLOAT fSmallStep, FX_FLOAT fBigStep){}
146 	virtual void					IOnSetScrollInfoY(FX_FLOAT fPlateMin, FX_FLOAT fPlateMax,
147 												FX_FLOAT fContentMin, FX_FLOAT fContentMax,
148 												FX_FLOAT fSmallStep, FX_FLOAT fBigStep);
IOnSetScrollPosX(FX_FLOAT fx)149 	virtual void					IOnSetScrollPosX(FX_FLOAT fx){}
150 	virtual void					IOnSetScrollPosY(FX_FLOAT fy);
151 	virtual void					IOnSetCaret(FX_BOOL bVisible,const CPDF_Point & ptHead,const CPDF_Point & ptFoot, const CPVT_WordPlace& place);
152 	virtual void					IOnCaretChange(const CPVT_SecProps & secProps, const CPVT_WordProps & wordProps);
153 	virtual void					IOnContentChange(const CPDF_Rect& rcContent);
154 	virtual void					IOnInvalidateRect(CPDF_Rect * pRect);
155 
156 private:
157 	void							CreateEditCaret(const PWL_CREATEPARAM & cp);
158 
159 protected:
160 	IFX_Edit*						m_pEdit;
161 	CPWL_Caret*						m_pEditCaret;
162 	FX_BOOL							m_bMouseDown;
163 	IPWL_Edit_Notify*				m_pEditNotify;
164 
165 private:
166 	FX_INT32						m_nCharSet;
167 	FX_INT32						m_nCodePage;
168 };
169 
170 #endif
171 
172