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