FX_BOOL considered harmful, part 2.
[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 FPDFSDK_INCLUDE_PDFWINDOW_PWL_EDITCTRL_H_
8 #define FPDFSDK_INCLUDE_PDFWINDOW_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(int32_t x1, int32_t y1, int32_t x2, int32_t 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 bool                                    OnKeyDown(FX_WORD nChar, FX_DWORD nFlag);
72         virtual bool                                    OnChar(FX_WORD nChar, FX_DWORD nFlag);
73         virtual bool                                    OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag);
74         virtual bool                                    OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag);
75         virtual bool                                    OnMouseMove(const CPDF_Point & point, FX_DWORD nFlag);
76         virtual void                                    OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, intptr_t wParam = 0, intptr_t 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(const FX_WCHAR* csText);
85
86         virtual void                                    CopyText();
87         virtual void                                    PasteText();
88         virtual void                                    CutText();
89
90         CPDF_Rect                                               GetContentRect() const;
91         void                                                    GetCaretPos(int32_t& x, int32_t& y) const;
92         bool                                                    IsModified() const;
93
94         CFX_WideString                                  GetText() const;
95         void                                                    SetSel(int32_t nStartChar,int32_t nEndChar);
96         void                                                    GetSel(int32_t & nStartChar, int32_t & nEndChar ) const;
97         void                                                    GetTextRange(const CPDF_Rect& rect, int32_t & nStartChar, int32_t & nEndChar) const;
98         CFX_WideString                                  GetText(int32_t & nStartChar, int32_t & nEndChar) const;
99         void                                                    Clear();
100         void                                                    SelectAll();
101
102         int32_t                                         GetCaret() const;
103         void                                                    SetCaret(int32_t nPos);
104         int32_t                                         GetTotalWords() const;
105
106         void                                                    Paint();
107
108         void                                                    EnableRefresh(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(uint8_t nCharSet){m_nCharSet = nCharSet;}
115         int32_t                                         GetCharSet() const;
116
117         void                                                    SetCodePage(int32_t nCodePage){m_nCodePage = nCodePage;}
118         int32_t                                         GetCodePage() const {return m_nCodePage;}
119
120         CPDF_Font *                                             GetCaretFont() const;
121         FX_FLOAT                                                GetCaretFontSize() const;
122
123         bool                                                    CanUndo() const;
124         bool                                                    CanRedo() const;
125         void                                                    Redo();
126         void                                                    Undo();
127
128         void                                                    SetReadyToInput();
129 protected:
130         virtual void                                    ShowVScrollBar(bool bShow);
131
132         virtual void                                    InsertWord(FX_WORD word, int32_t nCharset);
133         virtual void                                    InsertReturn();
134         virtual void                                    InsertText(const FX_WCHAR* csText);
135
136         virtual void                                    SetCursor();
137         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(bool bVisible, const CPDF_Point & ptHead, const CPDF_Point & ptFoot);
145
146         void                                                    SetEditCaret(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(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         bool                                                    m_bMouseDown;
169         IPWL_Edit_Notify*                               m_pEditNotify;
170
171 private:
172         int32_t                                         m_nCharSet;
173         int32_t                                         m_nCodePage;
174 };
175
176 #endif  // FPDFSDK_INCLUDE_PDFWINDOW_PWL_EDITCTRL_H_