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