blob: a8de08aaa69a5a288766ba5035f9a6522391b588 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
dan sinclair89e904b2016-03-23 19:29:15 -04007#ifndef FPDFSDK_PDFWINDOW_PWL_EDITCTRL_H_
8#define FPDFSDK_PDFWINDOW_PWL_EDITCTRL_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Dan Sinclaira8a28e02016-03-23 15:41:39 -040010#include "core/fxcrt/include/fx_string.h"
dsinclair89bdd082016-04-06 10:47:54 -070011#include "fpdfsdk/fxedit/include/fx_edit.h"
dan sinclair89e904b2016-03-23 19:29:15 -040012#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
Tom Sepez870292c2015-04-07 16:12:46 -070013
14class CPWL_Caret;
15class CPWL_Edit;
16class CPWL_EditCtrl;
17class IFX_Edit;
18class IPWL_Edit_Notify;
19struct CPVT_WordPlace;
20
Nico Weber9d8ec5a2015-08-04 13:00:21 -070021enum PWL_EDIT_ALIGNFORMAT_H { PEAH_LEFT = 0, PEAH_MIDDLE, PEAH_RIGHT };
22
23enum PWL_EDIT_ALIGNFORMAT_V { PEAV_TOP = 0, PEAV_CENTER, PEAV_BOTTOM };
24
25class IPWL_Edit_Notify {
26 public:
27 virtual ~IPWL_Edit_Notify() {}
28 // when the position of caret is changed in edit
29 virtual void OnCaretMove(int32_t x1, int32_t y1, int32_t x2, int32_t y2) {}
Tom Sepez281a9ea2016-02-26 14:24:28 -080030 virtual void OnContentChange(const CFX_FloatRect& rcContent) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -070031 // OprType: 0 InsertWord
32 // 1 InsertReturn
33 // 2 BackSpace
34 // 3 Delete
35 // 4 Clear
36 // 5 InsertText
37 // 6 SetText
38 virtual void OnInsertWord(const CPVT_WordPlace& place,
39 const CPVT_WordPlace& oldplace) {}
40 virtual void OnInsertReturn(const CPVT_WordPlace& place,
41 const CPVT_WordPlace& oldplace) {}
42 virtual void OnBackSpace(const CPVT_WordPlace& place,
43 const CPVT_WordPlace& oldplace) {}
44 virtual void OnDelete(const CPVT_WordPlace& place,
45 const CPVT_WordPlace& oldplace) {}
46 virtual void OnClear(const CPVT_WordPlace& place,
47 const CPVT_WordPlace& oldplace) {}
48 virtual void OnInsertText(const CPVT_WordPlace& place,
49 const CPVT_WordPlace& oldplace) {}
50 virtual void OnSetText(const CPVT_WordPlace& place,
51 const CPVT_WordPlace& oldplace) {}
52 virtual void OnAddUndo(CPWL_Edit* pEdit) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070053};
54
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055class CPWL_EditCtrl : public CPWL_Wnd, public IFX_Edit_Notify {
56 friend class CPWL_Edit_Notify;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070057
Nico Weber9d8ec5a2015-08-04 13:00:21 -070058 public:
59 CPWL_EditCtrl();
Lei Zhang2b1a2d52015-08-14 22:16:22 -070060 ~CPWL_EditCtrl() override;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070061
Tom Sepez281a9ea2016-02-26 14:24:28 -080062 CFX_FloatRect GetContentRect() const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070063 void GetCaretPos(int32_t& x, int32_t& y) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070064
Nico Weber9d8ec5a2015-08-04 13:00:21 -070065 CFX_WideString GetText() const;
66 void SetSel(int32_t nStartChar, int32_t nEndChar);
67 void GetSel(int32_t& nStartChar, int32_t& nEndChar) const;
Tom Sepez281a9ea2016-02-26 14:24:28 -080068 void GetTextRange(const CFX_FloatRect& rect,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069 int32_t& nStartChar,
70 int32_t& nEndChar) const;
71 CFX_WideString GetText(int32_t& nStartChar, int32_t& nEndChar) const;
72 void Clear();
73 void SelectAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070074
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075 int32_t GetCaret() const;
76 void SetCaret(int32_t nPos);
77 int32_t GetTotalWords() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070078
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079 void Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070080
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081 void EnableRefresh(FX_BOOL bRefresh);
Tom Sepez281a9ea2016-02-26 14:24:28 -080082 CFX_FloatPoint GetScrollPos() const;
83 void SetScrollPos(const CFX_FloatPoint& point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070084
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085 void SetEditNotify(IPWL_Edit_Notify* pNotify) { m_pEditNotify = pNotify; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 void SetCharSet(uint8_t nCharSet) { m_nCharSet = nCharSet; }
88 int32_t GetCharSet() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070089
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 void SetCodePage(int32_t nCodePage) { m_nCodePage = nCodePage; }
91 int32_t GetCodePage() const { return m_nCodePage; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070092
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093 CPDF_Font* GetCaretFont() const;
94 FX_FLOAT GetCaretFontSize() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095
Nico Weber9d8ec5a2015-08-04 13:00:21 -070096 FX_BOOL CanUndo() const;
97 FX_BOOL CanRedo() const;
98 void Redo();
99 void Undo();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101 void SetReadyToInput();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700102
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700103 // CPWL_Wnd
104 void OnCreate(PWL_CREATEPARAM& cp) override;
105 void OnCreated() override;
tsepezc3255f52016-03-25 14:52:27 -0700106 FX_BOOL OnKeyDown(uint16_t nChar, uint32_t nFlag) override;
107 FX_BOOL OnChar(uint16_t nChar, uint32_t nFlag) override;
108 FX_BOOL OnLButtonDown(const CFX_FloatPoint& point, uint32_t nFlag) override;
109 FX_BOOL OnLButtonUp(const CFX_FloatPoint& point, uint32_t nFlag) override;
110 FX_BOOL OnMouseMove(const CFX_FloatPoint& point, uint32_t nFlag) override;
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700111 void OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -0700112 uint32_t msg,
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700113 intptr_t wParam = 0,
114 intptr_t lParam = 0) override;
115 void CreateChildWnd(const PWL_CREATEPARAM& cp) override;
116 void RePosChildWnd() override;
117 void SetFontSize(FX_FLOAT fFontSize) override;
118 FX_FLOAT GetFontSize() const override;
119 void SetCursor() override;
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700120
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121 protected:
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700122 // IFX_Edit_Notify
123 void IOnSetScrollInfoX(FX_FLOAT fPlateMin,
124 FX_FLOAT fPlateMax,
125 FX_FLOAT fContentMin,
126 FX_FLOAT fContentMax,
127 FX_FLOAT fSmallStep,
128 FX_FLOAT fBigStep) override {}
129 void IOnSetScrollInfoY(FX_FLOAT fPlateMin,
130 FX_FLOAT fPlateMax,
131 FX_FLOAT fContentMin,
132 FX_FLOAT fContentMax,
133 FX_FLOAT fSmallStep,
134 FX_FLOAT fBigStep) override;
135 void IOnSetScrollPosX(FX_FLOAT fx) override {}
136 void IOnSetScrollPosY(FX_FLOAT fy) override;
137 void IOnSetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800138 const CFX_FloatPoint& ptHead,
139 const CFX_FloatPoint& ptFoot,
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700140 const CPVT_WordPlace& place) override;
141 void IOnCaretChange(const CPVT_SecProps& secProps,
142 const CPVT_WordProps& wordProps) override;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800143 void IOnContentChange(const CFX_FloatRect& rcContent) override;
144 void IOnInvalidateRect(CFX_FloatRect* pRect) override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700145
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700146 void InsertText(const FX_WCHAR* csText);
147 void SetText(const FX_WCHAR* csText);
148 void CopyText();
149 void PasteText();
150 void CutText();
151 void ShowVScrollBar(FX_BOOL bShow);
Tom Sepez62a70f92016-03-21 15:00:20 -0700152 void InsertWord(uint16_t word, int32_t nCharset);
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700153 void InsertReturn();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700154
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155 FX_BOOL IsWndHorV();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700156
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 void Delete();
158 void Backspace();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700159
Tom Sepez281a9ea2016-02-26 14:24:28 -0800160 void GetCaretInfo(CFX_FloatPoint& ptHead, CFX_FloatPoint& ptFoot) const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161 void SetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800162 const CFX_FloatPoint& ptHead,
163 const CFX_FloatPoint& ptFoot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700164
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 void SetEditCaret(FX_BOOL bVisible);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700166
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167 private:
168 void CreateEditCaret(const PWL_CREATEPARAM& cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700169
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 protected:
171 IFX_Edit* m_pEdit;
172 CPWL_Caret* m_pEditCaret;
173 FX_BOOL m_bMouseDown;
174 IPWL_Edit_Notify* m_pEditNotify;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700175
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 private:
177 int32_t m_nCharSet;
178 int32_t m_nCodePage;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700179};
180
dan sinclair89e904b2016-03-23 19:29:15 -0400181#endif // FPDFSDK_PDFWINDOW_PWL_EDITCTRL_H_