John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 7 | #ifndef FPDFSDK_PDFWINDOW_PWL_EDITCTRL_H_ |
| 8 | #define FPDFSDK_PDFWINDOW_PWL_EDITCTRL_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Dan Sinclair | a8a28e0 | 2016-03-23 15:41:39 -0400 | [diff] [blame] | 10 | #include "core/fxcrt/include/fx_string.h" |
dsinclair | 89bdd08 | 2016-04-06 10:47:54 -0700 | [diff] [blame] | 11 | #include "fpdfsdk/fxedit/include/fx_edit.h" |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 12 | #include "fpdfsdk/pdfwindow/PWL_Wnd.h" |
Tom Sepez | 870292c | 2015-04-07 16:12:46 -0700 | [diff] [blame] | 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 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 21 | enum PWL_EDIT_ALIGNFORMAT_H { PEAH_LEFT = 0, PEAH_MIDDLE, PEAH_RIGHT }; |
| 22 | |
| 23 | enum PWL_EDIT_ALIGNFORMAT_V { PEAV_TOP = 0, PEAV_CENTER, PEAV_BOTTOM }; |
| 24 | |
| 25 | class 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 Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 30 | virtual void OnContentChange(const CFX_FloatRect& rcContent) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | // 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | class CPWL_EditCtrl : public CPWL_Wnd, public IFX_Edit_Notify { |
| 56 | friend class CPWL_Edit_Notify; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 57 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 58 | public: |
| 59 | CPWL_EditCtrl(); |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 60 | ~CPWL_EditCtrl() override; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 61 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 62 | CFX_FloatRect GetContentRect() const; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | void GetCaretPos(int32_t& x, int32_t& y) const; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 64 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | CFX_WideString GetText() const; |
| 66 | void SetSel(int32_t nStartChar, int32_t nEndChar); |
| 67 | void GetSel(int32_t& nStartChar, int32_t& nEndChar) const; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 68 | void GetTextRange(const CFX_FloatRect& rect, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 69 | 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 74 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | int32_t GetCaret() const; |
| 76 | void SetCaret(int32_t nPos); |
| 77 | int32_t GetTotalWords() const; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 78 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 79 | void Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 80 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 81 | void EnableRefresh(FX_BOOL bRefresh); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 82 | CFX_FloatPoint GetScrollPos() const; |
| 83 | void SetScrollPos(const CFX_FloatPoint& point); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 84 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 85 | void SetEditNotify(IPWL_Edit_Notify* pNotify) { m_pEditNotify = pNotify; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 86 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | void SetCharSet(uint8_t nCharSet) { m_nCharSet = nCharSet; } |
| 88 | int32_t GetCharSet() const; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 89 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 90 | void SetCodePage(int32_t nCodePage) { m_nCodePage = nCodePage; } |
| 91 | int32_t GetCodePage() const { return m_nCodePage; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 92 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 93 | CPDF_Font* GetCaretFont() const; |
| 94 | FX_FLOAT GetCaretFontSize() const; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 95 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | FX_BOOL CanUndo() const; |
| 97 | FX_BOOL CanRedo() const; |
| 98 | void Redo(); |
| 99 | void Undo(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 100 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 101 | void SetReadyToInput(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 102 | |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 103 | // CPWL_Wnd |
| 104 | void OnCreate(PWL_CREATEPARAM& cp) override; |
| 105 | void OnCreated() override; |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 106 | 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 Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 111 | void OnNotify(CPWL_Wnd* pWnd, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 112 | uint32_t msg, |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 113 | 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 Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 120 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 121 | protected: |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 122 | // 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 Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 138 | const CFX_FloatPoint& ptHead, |
| 139 | const CFX_FloatPoint& ptFoot, |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 140 | const CPVT_WordPlace& place) override; |
| 141 | void IOnCaretChange(const CPVT_SecProps& secProps, |
| 142 | const CPVT_WordProps& wordProps) override; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 143 | void IOnContentChange(const CFX_FloatRect& rcContent) override; |
| 144 | void IOnInvalidateRect(CFX_FloatRect* pRect) override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 145 | |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 146 | 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 Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 152 | void InsertWord(uint16_t word, int32_t nCharset); |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 153 | void InsertReturn(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 154 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 155 | FX_BOOL IsWndHorV(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 156 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 157 | void Delete(); |
| 158 | void Backspace(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 159 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 160 | void GetCaretInfo(CFX_FloatPoint& ptHead, CFX_FloatPoint& ptFoot) const; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 161 | void SetCaret(FX_BOOL bVisible, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 162 | const CFX_FloatPoint& ptHead, |
| 163 | const CFX_FloatPoint& ptFoot); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 164 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | void SetEditCaret(FX_BOOL bVisible); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 166 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 167 | private: |
| 168 | void CreateEditCaret(const PWL_CREATEPARAM& cp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 169 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 170 | 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 175 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 176 | private: |
| 177 | int32_t m_nCharSet; |
| 178 | int32_t m_nCodePage; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 179 | }; |
| 180 | |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 181 | #endif // FPDFSDK_PDFWINDOW_PWL_EDITCTRL_H_ |