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