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