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 | 60f507b | 2015-06-13 00:41:00 -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 | |
Lei Zhang | 633a3b7 | 2017-06-02 15:27:22 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 8 | |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 9 | #include "core/fpdfdoc/cpvt_section.h" |
| 10 | #include "core/fpdfdoc/cpvt_word.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 11 | #include "core/fxge/fx_font.h" |
dsinclair | 0bb385b | 2016-09-29 17:03:59 -0700 | [diff] [blame] | 12 | #include "fpdfsdk/fxedit/fxet_edit.h" |
Lei Zhang | 633a3b7 | 2017-06-02 15:27:22 -0700 | [diff] [blame] | 13 | #include "fpdfsdk/pdfwindow/cpwl_caret.h" |
| 14 | #include "fpdfsdk/pdfwindow/cpwl_font_map.h" |
| 15 | #include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h" |
| 16 | #include "fpdfsdk/pdfwindow/cpwl_utils.h" |
| 17 | #include "fpdfsdk/pdfwindow/cpwl_wnd.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 18 | #include "public/fpdf_fwlevent.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 19 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 20 | CPWL_EditCtrl::CPWL_EditCtrl() |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 21 | : m_pEdit(new CFX_Edit), |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 22 | m_pEditCaret(nullptr), |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 23 | m_bMouseDown(false), |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 24 | m_nCharSet(FX_CHARSET_Default) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 25 | |
dsinclair | dbc7716 | 2016-07-13 11:34:23 -0700 | [diff] [blame] | 26 | CPWL_EditCtrl::~CPWL_EditCtrl() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 27 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 28 | void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM& cp) { |
| 29 | cp.eCursorType = FXCT_VBEAM; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 32 | void CPWL_EditCtrl::OnCreated() { |
| 33 | SetFontSize(GetCreationParam().fFontSize); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 35 | m_pEdit->SetFontMap(GetFontMap()); |
| 36 | m_pEdit->SetNotify(this); |
| 37 | m_pEdit->Initialize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 38 | } |
| 39 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 40 | bool CPWL_EditCtrl::IsWndHorV() { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 41 | CFX_Matrix mt = GetWindowMatrix(); |
Dan Sinclair | 1f403ce | 2017-02-21 12:56:24 -0500 | [diff] [blame] | 42 | return mt.Transform(CFX_PointF(1, 1)).y == mt.Transform(CFX_PointF(0, 1)).y; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 45 | void CPWL_EditCtrl::SetCursor() { |
| 46 | if (IsValid()) { |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 47 | if (CFX_SystemHandler* pSH = GetSystemHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | if (IsWndHorV()) |
| 49 | pSH->SetCursor(FXCT_VBEAM); |
| 50 | else |
| 51 | pSH->SetCursor(FXCT_HBEAM); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 52 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 53 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 56 | void CPWL_EditCtrl::RePosChildWnd() { |
| 57 | m_pEdit->SetPlateRect(GetClientRect()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 60 | void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 61 | uint32_t msg, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 62 | intptr_t wParam, |
| 63 | intptr_t lParam) { |
| 64 | CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 65 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 66 | switch (msg) { |
| 67 | case PNM_SETSCROLLINFO: |
| 68 | switch (wParam) { |
| 69 | case SBT_VSCROLL: |
| 70 | if (CPWL_Wnd* pChild = GetVScrollBar()) { |
| 71 | pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam); |
| 72 | } |
| 73 | break; |
| 74 | } |
| 75 | break; |
| 76 | case PNM_SETSCROLLPOS: |
| 77 | switch (wParam) { |
| 78 | case SBT_VSCROLL: |
| 79 | if (CPWL_Wnd* pChild = GetVScrollBar()) { |
| 80 | pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam); |
| 81 | } |
| 82 | break; |
| 83 | } |
| 84 | break; |
| 85 | case PNM_SCROLLWINDOW: { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 86 | float fPos = *(float*)lParam; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | switch (wParam) { |
| 88 | case SBT_VSCROLL: |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 89 | m_pEdit->SetScrollPos(CFX_PointF(m_pEdit->GetScrollPos().x, fPos)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 90 | break; |
| 91 | } |
| 92 | } break; |
| 93 | case PNM_SETCARETINFO: { |
| 94 | if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) { |
| 95 | SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot); |
| 96 | } |
| 97 | } break; |
| 98 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 101 | void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) { |
| 102 | if (!IsReadOnly()) |
| 103 | CreateEditCaret(cp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 106 | void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 107 | if (m_pEditCaret) |
| 108 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 109 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 110 | m_pEditCaret = new CPWL_Caret; |
| 111 | m_pEditCaret->SetInvalidRect(GetClientRect()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 112 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 113 | PWL_CREATEPARAM ecp = cp; |
| 114 | ecp.pParentWnd = this; |
| 115 | ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP; |
| 116 | ecp.dwBorderWidth = 0; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 117 | ecp.nBorderStyle = BorderStyle::SOLID; |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 118 | ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); |
| 119 | |
| 120 | m_pEditCaret->Create(ecp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 123 | void CPWL_EditCtrl::SetFontSize(float fFontSize) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 124 | m_pEdit->SetFontSize(fFontSize); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 127 | float CPWL_EditCtrl::GetFontSize() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 128 | return m_pEdit->GetFontSize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 129 | } |
| 130 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 131 | bool CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 132 | if (m_bMouseDown) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 133 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 134 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 135 | bool bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 136 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 137 | // FILTER |
| 138 | switch (nChar) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 139 | default: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 140 | return false; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 141 | case FWL_VKEY_Delete: |
| 142 | case FWL_VKEY_Up: |
| 143 | case FWL_VKEY_Down: |
| 144 | case FWL_VKEY_Left: |
| 145 | case FWL_VKEY_Right: |
| 146 | case FWL_VKEY_Home: |
| 147 | case FWL_VKEY_End: |
| 148 | case FWL_VKEY_Insert: |
| 149 | case 'C': |
| 150 | case 'V': |
| 151 | case 'X': |
| 152 | case 'A': |
| 153 | case 'Z': |
| 154 | case 'c': |
| 155 | case 'v': |
| 156 | case 'x': |
| 157 | case 'a': |
| 158 | case 'z': |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 159 | break; |
| 160 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 161 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 162 | if (nChar == FWL_VKEY_Delete && m_pEdit->IsSelected()) |
| 163 | nChar = FWL_VKEY_Unknown; |
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 | switch (nChar) { |
| 166 | case FWL_VKEY_Delete: |
| 167 | Delete(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 168 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 169 | case FWL_VKEY_Insert: |
| 170 | if (IsSHIFTpressed(nFlag)) |
| 171 | PasteText(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 172 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 173 | case FWL_VKEY_Up: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 174 | m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), false); |
| 175 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 176 | case FWL_VKEY_Down: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 177 | m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), false); |
| 178 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 179 | case FWL_VKEY_Left: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 180 | m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), false); |
| 181 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 182 | case FWL_VKEY_Right: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 183 | m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), false); |
| 184 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 185 | case FWL_VKEY_Home: |
| 186 | m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 187 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 188 | case FWL_VKEY_End: |
| 189 | m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 190 | return true; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 191 | case FWL_VKEY_Unknown: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 192 | if (!IsSHIFTpressed(nFlag)) |
| 193 | Clear(); |
| 194 | else |
| 195 | CutText(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 196 | return true; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 197 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 198 | break; |
| 199 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 200 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 201 | return bRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 202 | } |
| 203 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 204 | bool CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 205 | if (m_bMouseDown) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 206 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 207 | |
| 208 | CPWL_Wnd::OnChar(nChar, nFlag); |
| 209 | |
| 210 | // FILTER |
| 211 | switch (nChar) { |
| 212 | case 0x0A: |
| 213 | case 0x1B: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 214 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 215 | default: |
| 216 | break; |
| 217 | } |
| 218 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 219 | bool bCtrl = IsCTRLpressed(nFlag); |
| 220 | bool bAlt = IsALTpressed(nFlag); |
| 221 | bool bShift = IsSHIFTpressed(nFlag); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 222 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 223 | uint16_t word = nChar; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 224 | |
| 225 | if (bCtrl && !bAlt) { |
| 226 | switch (nChar) { |
| 227 | case 'C' - 'A' + 1: |
| 228 | CopyText(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 229 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 230 | case 'V' - 'A' + 1: |
| 231 | PasteText(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 232 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 233 | case 'X' - 'A' + 1: |
| 234 | CutText(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 235 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 236 | case 'A' - 'A' + 1: |
| 237 | SelectAll(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 238 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 239 | case 'Z' - 'A' + 1: |
| 240 | if (bShift) |
| 241 | Redo(); |
| 242 | else |
| 243 | Undo(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 244 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 245 | default: |
| 246 | if (nChar < 32) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 247 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
| 251 | if (IsReadOnly()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 252 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 253 | |
| 254 | if (m_pEdit->IsSelected() && word == FWL_VKEY_Back) |
| 255 | word = FWL_VKEY_Unknown; |
| 256 | |
| 257 | Clear(); |
| 258 | |
| 259 | switch (word) { |
| 260 | case FWL_VKEY_Back: |
| 261 | Backspace(); |
| 262 | break; |
| 263 | case FWL_VKEY_Return: |
| 264 | InsertReturn(); |
| 265 | break; |
| 266 | case FWL_VKEY_Unknown: |
| 267 | break; |
| 268 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 269 | InsertWord(word, GetCharSet()); |
| 270 | break; |
| 271 | } |
| 272 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 273 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 276 | bool CPWL_EditCtrl::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 277 | CPWL_Wnd::OnLButtonDown(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 278 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 279 | if (ClientHitTest(point)) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 280 | if (m_bMouseDown) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 281 | InvalidateRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 282 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 283 | m_bMouseDown = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 284 | SetCapture(); |
| 285 | |
| 286 | m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 287 | } |
| 288 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 289 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 292 | bool CPWL_EditCtrl::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 293 | CPWL_Wnd::OnLButtonUp(point, nFlag); |
| 294 | |
| 295 | if (m_bMouseDown) { |
| 296 | // can receive keybord message |
| 297 | if (ClientHitTest(point) && !IsFocused()) |
| 298 | SetFocus(); |
| 299 | |
| 300 | ReleaseCapture(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 301 | m_bMouseDown = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 302 | } |
| 303 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 304 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 307 | bool CPWL_EditCtrl::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 308 | CPWL_Wnd::OnMouseMove(point, nFlag); |
| 309 | |
| 310 | if (m_bMouseDown) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 311 | m_pEdit->OnMouseMove(point, false, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 312 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 313 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 314 | } |
| 315 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 316 | void CPWL_EditCtrl::SetEditCaret(bool bVisible) { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 317 | CFX_PointF ptHead; |
| 318 | CFX_PointF ptFoot; |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 319 | if (bVisible) |
Dan Sinclair | 1f403ce | 2017-02-21 12:56:24 -0500 | [diff] [blame] | 320 | GetCaretInfo(&ptHead, &ptFoot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 321 | |
| 322 | CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace(); |
| 323 | IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp); |
| 324 | } |
| 325 | |
Dan Sinclair | 1f403ce | 2017-02-21 12:56:24 -0500 | [diff] [blame] | 326 | void CPWL_EditCtrl::GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const { |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 327 | CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 328 | pIterator->SetAt(m_pEdit->GetCaret()); |
| 329 | CPVT_Word word; |
| 330 | CPVT_Line line; |
| 331 | if (pIterator->GetWord(word)) { |
Dan Sinclair | 1f403ce | 2017-02-21 12:56:24 -0500 | [diff] [blame] | 332 | ptHead->x = word.ptWord.x + word.fWidth; |
| 333 | ptHead->y = word.ptWord.y + word.fAscent; |
| 334 | ptFoot->x = word.ptWord.x + word.fWidth; |
| 335 | ptFoot->y = word.ptWord.y + word.fDescent; |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 336 | } else if (pIterator->GetLine(line)) { |
Dan Sinclair | 1f403ce | 2017-02-21 12:56:24 -0500 | [diff] [blame] | 337 | ptHead->x = line.ptLine.x; |
| 338 | ptHead->y = line.ptLine.y + line.fLineAscent; |
| 339 | ptFoot->x = line.ptLine.x; |
| 340 | ptFoot->y = line.ptLine.y + line.fLineDescent; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 341 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 342 | } |
| 343 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 344 | void CPWL_EditCtrl::SetCaret(bool bVisible, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 345 | const CFX_PointF& ptHead, |
| 346 | const CFX_PointF& ptFoot) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 347 | if (m_pEditCaret) { |
| 348 | if (!IsFocused() || m_pEdit->IsSelected()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 349 | bVisible = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 350 | |
| 351 | m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot); |
| 352 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 355 | CFX_WideString CPWL_EditCtrl::GetText() const { |
| 356 | return m_pEdit->GetText(); |
| 357 | } |
| 358 | |
| 359 | void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) { |
| 360 | m_pEdit->SetSel(nStartChar, nEndChar); |
| 361 | } |
| 362 | |
| 363 | void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const { |
| 364 | m_pEdit->GetSel(nStartChar, nEndChar); |
| 365 | } |
| 366 | |
| 367 | void CPWL_EditCtrl::Clear() { |
| 368 | if (!IsReadOnly()) |
| 369 | m_pEdit->Clear(); |
| 370 | } |
| 371 | |
| 372 | void CPWL_EditCtrl::SelectAll() { |
| 373 | m_pEdit->SelectAll(); |
| 374 | } |
| 375 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 376 | void CPWL_EditCtrl::SetScrollPos(const CFX_PointF& point) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 377 | m_pEdit->SetScrollPos(point); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 380 | CFX_PointF CPWL_EditCtrl::GetScrollPos() const { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 381 | return m_pEdit->GetScrollPos(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 384 | void CPWL_EditCtrl::CopyText() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 385 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 386 | void CPWL_EditCtrl::PasteText() {} |
| 387 | |
| 388 | void CPWL_EditCtrl::CutText() {} |
| 389 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 390 | void CPWL_EditCtrl::ShowVScrollBar(bool bShow) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 391 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 392 | void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 393 | if (!IsReadOnly()) |
| 394 | m_pEdit->InsertWord(word, nCharset); |
| 395 | } |
| 396 | |
| 397 | void CPWL_EditCtrl::InsertReturn() { |
| 398 | if (!IsReadOnly()) |
| 399 | m_pEdit->InsertReturn(); |
| 400 | } |
| 401 | |
| 402 | void CPWL_EditCtrl::Delete() { |
| 403 | if (!IsReadOnly()) |
| 404 | m_pEdit->Delete(); |
| 405 | } |
| 406 | |
| 407 | void CPWL_EditCtrl::Backspace() { |
| 408 | if (!IsReadOnly()) |
| 409 | m_pEdit->Backspace(); |
| 410 | } |
| 411 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 412 | bool CPWL_EditCtrl::CanUndo() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 413 | return !IsReadOnly() && m_pEdit->CanUndo(); |
| 414 | } |
| 415 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 416 | bool CPWL_EditCtrl::CanRedo() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 417 | return !IsReadOnly() && m_pEdit->CanRedo(); |
| 418 | } |
| 419 | |
| 420 | void CPWL_EditCtrl::Redo() { |
| 421 | if (CanRedo()) |
| 422 | m_pEdit->Redo(); |
| 423 | } |
| 424 | |
| 425 | void CPWL_EditCtrl::Undo() { |
| 426 | if (CanUndo()) |
| 427 | m_pEdit->Undo(); |
| 428 | } |
| 429 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 430 | void CPWL_EditCtrl::IOnSetScrollInfoY(float fPlateMin, |
| 431 | float fPlateMax, |
| 432 | float fContentMin, |
| 433 | float fContentMax, |
| 434 | float fSmallStep, |
| 435 | float fBigStep) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 436 | PWL_SCROLL_INFO Info; |
| 437 | |
| 438 | Info.fPlateWidth = fPlateMax - fPlateMin; |
| 439 | Info.fContentMin = fContentMin; |
| 440 | Info.fContentMax = fContentMax; |
| 441 | Info.fSmallStep = fSmallStep; |
| 442 | Info.fBigStep = fBigStep; |
| 443 | |
| 444 | OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info); |
| 445 | |
| 446 | if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) || |
| 447 | IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 448 | ShowVScrollBar(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 449 | } else { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 450 | ShowVScrollBar(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 454 | void CPWL_EditCtrl::IOnSetScrollPosY(float fy) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 455 | OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy); |
| 456 | } |
| 457 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 458 | void CPWL_EditCtrl::IOnSetCaret(bool bVisible, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 459 | const CFX_PointF& ptHead, |
| 460 | const CFX_PointF& ptFoot, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 461 | const CPVT_WordPlace& place) { |
| 462 | PWL_CARET_INFO cInfo; |
| 463 | cInfo.bVisible = bVisible; |
| 464 | cInfo.ptHead = ptHead; |
| 465 | cInfo.ptFoot = ptFoot; |
| 466 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 467 | OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 470 | void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 471 | InvalidateRect(pRect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 474 | int32_t CPWL_EditCtrl::GetCharSet() const { |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 475 | return m_nCharSet < 0 ? FX_CHARSET_Default : m_nCharSet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 478 | void CPWL_EditCtrl::SetReadyToInput() { |
| 479 | if (m_bMouseDown) { |
| 480 | ReleaseCapture(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 481 | m_bMouseDown = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 482 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 483 | } |