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 | |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/pdfwindow/PWL_EditCtrl.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 | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 12 | #include "fpdfsdk/fxedit/include/fxet_edit.h" |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 13 | #include "fpdfsdk/pdfwindow/PWL_Caret.h" |
| 14 | #include "fpdfsdk/pdfwindow/PWL_FontMap.h" |
| 15 | #include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" |
| 16 | #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
| 17 | #include "fpdfsdk/pdfwindow/PWL_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), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 23 | m_bMouseDown(FALSE), |
npm | ea3c3be | 2016-09-19 07:24:33 -0700 | [diff] [blame] | 24 | m_nCharSet(FXFONT_DEFAULT_CHARSET), |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 25 | m_nCodePage(0) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 26 | |
dsinclair | dbc7716 | 2016-07-13 11:34:23 -0700 | [diff] [blame] | 27 | CPWL_EditCtrl::~CPWL_EditCtrl() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 28 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 29 | void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM& cp) { |
| 30 | cp.eCursorType = FXCT_VBEAM; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | void CPWL_EditCtrl::OnCreated() { |
| 34 | SetFontSize(GetCreationParam().fFontSize); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 35 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 36 | m_pEdit->SetFontMap(GetFontMap()); |
| 37 | m_pEdit->SetNotify(this); |
| 38 | m_pEdit->Initialize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 41 | FX_BOOL CPWL_EditCtrl::IsWndHorV() { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 42 | CFX_Matrix mt = GetWindowMatrix(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 43 | CFX_FloatPoint point1(0, 1); |
| 44 | CFX_FloatPoint point2(1, 1); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 45 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 46 | mt.Transform(point1.x, point1.y); |
| 47 | mt.Transform(point2.x, point2.y); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 48 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 49 | return point2.y == point1.y; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | void CPWL_EditCtrl::SetCursor() { |
| 53 | if (IsValid()) { |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 54 | if (CFX_SystemHandler* pSH = GetSystemHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | if (IsWndHorV()) |
| 56 | pSH->SetCursor(FXCT_VBEAM); |
| 57 | else |
| 58 | pSH->SetCursor(FXCT_HBEAM); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 59 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 60 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | void CPWL_EditCtrl::RePosChildWnd() { |
| 64 | m_pEdit->SetPlateRect(GetClientRect()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 68 | uint32_t msg, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 69 | intptr_t wParam, |
| 70 | intptr_t lParam) { |
| 71 | CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 72 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 73 | switch (msg) { |
| 74 | case PNM_SETSCROLLINFO: |
| 75 | switch (wParam) { |
| 76 | case SBT_VSCROLL: |
| 77 | if (CPWL_Wnd* pChild = GetVScrollBar()) { |
| 78 | pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam); |
| 79 | } |
| 80 | break; |
| 81 | } |
| 82 | break; |
| 83 | case PNM_SETSCROLLPOS: |
| 84 | switch (wParam) { |
| 85 | case SBT_VSCROLL: |
| 86 | if (CPWL_Wnd* pChild = GetVScrollBar()) { |
| 87 | pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam); |
| 88 | } |
| 89 | break; |
| 90 | } |
| 91 | break; |
| 92 | case PNM_SCROLLWINDOW: { |
| 93 | FX_FLOAT fPos = *(FX_FLOAT*)lParam; |
| 94 | switch (wParam) { |
| 95 | case SBT_VSCROLL: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 96 | m_pEdit->SetScrollPos( |
| 97 | CFX_FloatPoint(m_pEdit->GetScrollPos().x, fPos)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 98 | break; |
| 99 | } |
| 100 | } break; |
| 101 | case PNM_SETCARETINFO: { |
| 102 | if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) { |
| 103 | SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot); |
| 104 | } |
| 105 | } break; |
| 106 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 109 | void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) { |
| 110 | if (!IsReadOnly()) |
| 111 | CreateEditCaret(cp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 114 | void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 115 | if (m_pEditCaret) |
| 116 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 117 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 118 | m_pEditCaret = new CPWL_Caret; |
| 119 | m_pEditCaret->SetInvalidRect(GetClientRect()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 120 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 121 | PWL_CREATEPARAM ecp = cp; |
| 122 | ecp.pParentWnd = this; |
| 123 | ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP; |
| 124 | ecp.dwBorderWidth = 0; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 125 | ecp.nBorderStyle = BorderStyle::SOLID; |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 126 | ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); |
| 127 | |
| 128 | m_pEditCaret->Create(ecp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 131 | void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize) { |
| 132 | m_pEdit->SetFontSize(fFontSize); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 135 | FX_FLOAT CPWL_EditCtrl::GetFontSize() const { |
| 136 | return m_pEdit->GetFontSize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 137 | } |
| 138 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 139 | FX_BOOL CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 140 | if (m_bMouseDown) |
| 141 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 142 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 143 | FX_BOOL bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 144 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 145 | // FILTER |
| 146 | switch (nChar) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 147 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 148 | return FALSE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 149 | case FWL_VKEY_Delete: |
| 150 | case FWL_VKEY_Up: |
| 151 | case FWL_VKEY_Down: |
| 152 | case FWL_VKEY_Left: |
| 153 | case FWL_VKEY_Right: |
| 154 | case FWL_VKEY_Home: |
| 155 | case FWL_VKEY_End: |
| 156 | case FWL_VKEY_Insert: |
| 157 | case 'C': |
| 158 | case 'V': |
| 159 | case 'X': |
| 160 | case 'A': |
| 161 | case 'Z': |
| 162 | case 'c': |
| 163 | case 'v': |
| 164 | case 'x': |
| 165 | case 'a': |
| 166 | case 'z': |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 167 | break; |
| 168 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 169 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 170 | if (nChar == FWL_VKEY_Delete && m_pEdit->IsSelected()) |
| 171 | nChar = FWL_VKEY_Unknown; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 172 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 173 | switch (nChar) { |
| 174 | case FWL_VKEY_Delete: |
| 175 | Delete(); |
| 176 | return TRUE; |
| 177 | case FWL_VKEY_Insert: |
| 178 | if (IsSHIFTpressed(nFlag)) |
| 179 | PasteText(); |
| 180 | return TRUE; |
| 181 | case FWL_VKEY_Up: |
| 182 | m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), FALSE); |
| 183 | return TRUE; |
| 184 | case FWL_VKEY_Down: |
| 185 | m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), FALSE); |
| 186 | return TRUE; |
| 187 | case FWL_VKEY_Left: |
| 188 | m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), FALSE); |
| 189 | return TRUE; |
| 190 | case FWL_VKEY_Right: |
| 191 | m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), FALSE); |
| 192 | return TRUE; |
| 193 | case FWL_VKEY_Home: |
| 194 | m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 195 | return TRUE; |
| 196 | case FWL_VKEY_End: |
| 197 | m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 198 | return TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 199 | case FWL_VKEY_Unknown: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 200 | if (!IsSHIFTpressed(nFlag)) |
| 201 | Clear(); |
| 202 | else |
| 203 | CutText(); |
| 204 | return TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 205 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 206 | break; |
| 207 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 208 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 209 | return bRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 210 | } |
| 211 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 212 | FX_BOOL CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 213 | if (m_bMouseDown) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 214 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 215 | |
| 216 | CPWL_Wnd::OnChar(nChar, nFlag); |
| 217 | |
| 218 | // FILTER |
| 219 | switch (nChar) { |
| 220 | case 0x0A: |
| 221 | case 0x1B: |
| 222 | return FALSE; |
| 223 | default: |
| 224 | break; |
| 225 | } |
| 226 | |
| 227 | FX_BOOL bCtrl = IsCTRLpressed(nFlag); |
| 228 | FX_BOOL bAlt = IsALTpressed(nFlag); |
| 229 | FX_BOOL bShift = IsSHIFTpressed(nFlag); |
| 230 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 231 | uint16_t word = nChar; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | |
| 233 | if (bCtrl && !bAlt) { |
| 234 | switch (nChar) { |
| 235 | case 'C' - 'A' + 1: |
| 236 | CopyText(); |
| 237 | return TRUE; |
| 238 | case 'V' - 'A' + 1: |
| 239 | PasteText(); |
| 240 | return TRUE; |
| 241 | case 'X' - 'A' + 1: |
| 242 | CutText(); |
| 243 | return TRUE; |
| 244 | case 'A' - 'A' + 1: |
| 245 | SelectAll(); |
| 246 | return TRUE; |
| 247 | case 'Z' - 'A' + 1: |
| 248 | if (bShift) |
| 249 | Redo(); |
| 250 | else |
| 251 | Undo(); |
| 252 | return TRUE; |
| 253 | default: |
| 254 | if (nChar < 32) |
| 255 | return FALSE; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | if (IsReadOnly()) |
| 260 | return TRUE; |
| 261 | |
| 262 | if (m_pEdit->IsSelected() && word == FWL_VKEY_Back) |
| 263 | word = FWL_VKEY_Unknown; |
| 264 | |
| 265 | Clear(); |
| 266 | |
| 267 | switch (word) { |
| 268 | case FWL_VKEY_Back: |
| 269 | Backspace(); |
| 270 | break; |
| 271 | case FWL_VKEY_Return: |
| 272 | InsertReturn(); |
| 273 | break; |
| 274 | case FWL_VKEY_Unknown: |
| 275 | break; |
| 276 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 277 | InsertWord(word, GetCharSet()); |
| 278 | break; |
| 279 | } |
| 280 | |
| 281 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 284 | FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CFX_FloatPoint& point, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 285 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 286 | CPWL_Wnd::OnLButtonDown(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 287 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 288 | if (ClientHitTest(point)) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 289 | if (m_bMouseDown) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 290 | InvalidateRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 291 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 292 | m_bMouseDown = TRUE; |
| 293 | SetCapture(); |
| 294 | |
| 295 | m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 296 | } |
| 297 | |
| 298 | return TRUE; |
| 299 | } |
| 300 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 301 | FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CFX_FloatPoint& point, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 302 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 303 | CPWL_Wnd::OnLButtonUp(point, nFlag); |
| 304 | |
| 305 | if (m_bMouseDown) { |
| 306 | // can receive keybord message |
| 307 | if (ClientHitTest(point) && !IsFocused()) |
| 308 | SetFocus(); |
| 309 | |
| 310 | ReleaseCapture(); |
| 311 | m_bMouseDown = FALSE; |
| 312 | } |
| 313 | |
| 314 | return TRUE; |
| 315 | } |
| 316 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 317 | FX_BOOL CPWL_EditCtrl::OnMouseMove(const CFX_FloatPoint& point, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 318 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 319 | CPWL_Wnd::OnMouseMove(point, nFlag); |
| 320 | |
| 321 | if (m_bMouseDown) |
| 322 | m_pEdit->OnMouseMove(point, FALSE, FALSE); |
| 323 | |
| 324 | return TRUE; |
| 325 | } |
| 326 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 327 | CFX_FloatRect CPWL_EditCtrl::GetContentRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 328 | return m_pEdit->GetContentRect(); |
| 329 | } |
| 330 | |
| 331 | void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible) { |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 332 | CFX_FloatPoint ptHead; |
| 333 | CFX_FloatPoint ptFoot; |
| 334 | if (bVisible) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 335 | GetCaretInfo(ptHead, ptFoot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 336 | |
| 337 | CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace(); |
| 338 | IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp); |
| 339 | } |
| 340 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 341 | void CPWL_EditCtrl::GetCaretInfo(CFX_FloatPoint& ptHead, |
| 342 | CFX_FloatPoint& ptFoot) const { |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 343 | CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 344 | pIterator->SetAt(m_pEdit->GetCaret()); |
| 345 | CPVT_Word word; |
| 346 | CPVT_Line line; |
| 347 | if (pIterator->GetWord(word)) { |
| 348 | ptHead.x = word.ptWord.x + word.fWidth; |
| 349 | ptHead.y = word.ptWord.y + word.fAscent; |
| 350 | ptFoot.x = word.ptWord.x + word.fWidth; |
| 351 | ptFoot.y = word.ptWord.y + word.fDescent; |
| 352 | } else if (pIterator->GetLine(line)) { |
| 353 | ptHead.x = line.ptLine.x; |
| 354 | ptHead.y = line.ptLine.y + line.fLineAscent; |
| 355 | ptFoot.x = line.ptLine.x; |
| 356 | ptFoot.y = line.ptLine.y + line.fLineDescent; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 357 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 360 | void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const { |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 361 | CFX_FloatPoint ptHead; |
| 362 | CFX_FloatPoint ptFoot; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 363 | GetCaretInfo(ptHead, ptFoot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 364 | PWLtoWnd(ptHead, x, y); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 367 | void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 368 | const CFX_FloatPoint& ptHead, |
| 369 | const CFX_FloatPoint& ptFoot) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 370 | if (m_pEditCaret) { |
| 371 | if (!IsFocused() || m_pEdit->IsSelected()) |
| 372 | bVisible = FALSE; |
| 373 | |
| 374 | m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot); |
| 375 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 378 | CFX_WideString CPWL_EditCtrl::GetText() const { |
| 379 | return m_pEdit->GetText(); |
| 380 | } |
| 381 | |
| 382 | void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) { |
| 383 | m_pEdit->SetSel(nStartChar, nEndChar); |
| 384 | } |
| 385 | |
| 386 | void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const { |
| 387 | m_pEdit->GetSel(nStartChar, nEndChar); |
| 388 | } |
| 389 | |
| 390 | void CPWL_EditCtrl::Clear() { |
| 391 | if (!IsReadOnly()) |
| 392 | m_pEdit->Clear(); |
| 393 | } |
| 394 | |
| 395 | void CPWL_EditCtrl::SelectAll() { |
| 396 | m_pEdit->SelectAll(); |
| 397 | } |
| 398 | |
| 399 | void CPWL_EditCtrl::Paint() { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 400 | m_pEdit->Paint(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 404 | m_pEdit->EnableRefresh(bRefresh); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | int32_t CPWL_EditCtrl::GetCaret() const { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 408 | return m_pEdit->GetCaret(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | void CPWL_EditCtrl::SetCaret(int32_t nPos) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 412 | m_pEdit->SetCaret(nPos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | int32_t CPWL_EditCtrl::GetTotalWords() const { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 416 | return m_pEdit->GetTotalWords(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 419 | void CPWL_EditCtrl::SetScrollPos(const CFX_FloatPoint& point) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 420 | m_pEdit->SetScrollPos(point); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 423 | CFX_FloatPoint CPWL_EditCtrl::GetScrollPos() const { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 424 | return m_pEdit->GetScrollPos(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | CPDF_Font* CPWL_EditCtrl::GetCaretFont() const { |
| 428 | int32_t nFontIndex = 0; |
| 429 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 430 | CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 431 | pIterator->SetAt(m_pEdit->GetCaret()); |
| 432 | CPVT_Word word; |
| 433 | CPVT_Section section; |
| 434 | if (pIterator->GetWord(word)) { |
| 435 | nFontIndex = word.nFontIndex; |
| 436 | } else if (HasFlag(PES_RICH)) { |
| 437 | if (pIterator->GetSection(section)) { |
| 438 | nFontIndex = section.WordProps.nFontIndex; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 439 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 440 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 441 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 442 | if (IPVT_FontMap* pFontMap = GetFontMap()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 443 | return pFontMap->GetPDFFont(nFontIndex); |
| 444 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 445 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 448 | FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const { |
| 449 | FX_FLOAT fFontSize = GetFontSize(); |
| 450 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 451 | CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 452 | pIterator->SetAt(m_pEdit->GetCaret()); |
| 453 | CPVT_Word word; |
| 454 | CPVT_Section section; |
| 455 | if (pIterator->GetWord(word)) { |
| 456 | fFontSize = word.fFontSize; |
| 457 | } else if (HasFlag(PES_RICH)) { |
| 458 | if (pIterator->GetSection(section)) { |
| 459 | fFontSize = section.WordProps.fFontSize; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 460 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | return fFontSize; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 464 | } |
| 465 | |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 466 | void CPWL_EditCtrl::SetText(const CFX_WideString& wsText) { |
| 467 | m_pEdit->SetText(wsText); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 470 | void CPWL_EditCtrl::CopyText() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 471 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 472 | void CPWL_EditCtrl::PasteText() {} |
| 473 | |
| 474 | void CPWL_EditCtrl::CutText() {} |
| 475 | |
| 476 | void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow) {} |
| 477 | |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 478 | void CPWL_EditCtrl::InsertText(const CFX_WideString& wsText) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 479 | if (!IsReadOnly()) |
npm | ea3c3be | 2016-09-19 07:24:33 -0700 | [diff] [blame] | 480 | m_pEdit->InsertText(wsText, FXFONT_DEFAULT_CHARSET); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 483 | void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 484 | if (!IsReadOnly()) |
| 485 | m_pEdit->InsertWord(word, nCharset); |
| 486 | } |
| 487 | |
| 488 | void CPWL_EditCtrl::InsertReturn() { |
| 489 | if (!IsReadOnly()) |
| 490 | m_pEdit->InsertReturn(); |
| 491 | } |
| 492 | |
| 493 | void CPWL_EditCtrl::Delete() { |
| 494 | if (!IsReadOnly()) |
| 495 | m_pEdit->Delete(); |
| 496 | } |
| 497 | |
| 498 | void CPWL_EditCtrl::Backspace() { |
| 499 | if (!IsReadOnly()) |
| 500 | m_pEdit->Backspace(); |
| 501 | } |
| 502 | |
| 503 | FX_BOOL CPWL_EditCtrl::CanUndo() const { |
| 504 | return !IsReadOnly() && m_pEdit->CanUndo(); |
| 505 | } |
| 506 | |
| 507 | FX_BOOL CPWL_EditCtrl::CanRedo() const { |
| 508 | return !IsReadOnly() && m_pEdit->CanRedo(); |
| 509 | } |
| 510 | |
| 511 | void CPWL_EditCtrl::Redo() { |
| 512 | if (CanRedo()) |
| 513 | m_pEdit->Redo(); |
| 514 | } |
| 515 | |
| 516 | void CPWL_EditCtrl::Undo() { |
| 517 | if (CanUndo()) |
| 518 | m_pEdit->Undo(); |
| 519 | } |
| 520 | |
| 521 | void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin, |
| 522 | FX_FLOAT fPlateMax, |
| 523 | FX_FLOAT fContentMin, |
| 524 | FX_FLOAT fContentMax, |
| 525 | FX_FLOAT fSmallStep, |
| 526 | FX_FLOAT fBigStep) { |
| 527 | PWL_SCROLL_INFO Info; |
| 528 | |
| 529 | Info.fPlateWidth = fPlateMax - fPlateMin; |
| 530 | Info.fContentMin = fContentMin; |
| 531 | Info.fContentMax = fContentMax; |
| 532 | Info.fSmallStep = fSmallStep; |
| 533 | Info.fBigStep = fBigStep; |
| 534 | |
| 535 | OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info); |
| 536 | |
| 537 | if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) || |
| 538 | IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) { |
| 539 | ShowVScrollBar(FALSE); |
| 540 | } else { |
| 541 | ShowVScrollBar(TRUE); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy) { |
| 546 | OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy); |
| 547 | } |
| 548 | |
| 549 | void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 550 | const CFX_FloatPoint& ptHead, |
| 551 | const CFX_FloatPoint& ptFoot, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 552 | const CPVT_WordPlace& place) { |
| 553 | PWL_CARET_INFO cInfo; |
| 554 | cInfo.bVisible = bVisible; |
| 555 | cInfo.ptHead = ptHead; |
| 556 | cInfo.ptFoot = ptFoot; |
| 557 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 558 | OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 559 | } |
| 560 | |
dsinclair | dbc7716 | 2016-07-13 11:34:23 -0700 | [diff] [blame] | 561 | void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps, |
| 562 | const CPVT_WordProps& wordProps) {} |
| 563 | |
| 564 | void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 565 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 566 | void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 567 | InvalidateRect(pRect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 568 | } |
| 569 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 570 | int32_t CPWL_EditCtrl::GetCharSet() const { |
npm | ea3c3be | 2016-09-19 07:24:33 -0700 | [diff] [blame] | 571 | return m_nCharSet < 0 ? FXFONT_DEFAULT_CHARSET : m_nCharSet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 574 | void CPWL_EditCtrl::GetTextRange(const CFX_FloatRect& rect, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 575 | int32_t& nStartChar, |
| 576 | int32_t& nEndChar) const { |
| 577 | nStartChar = m_pEdit->WordPlaceToWordIndex( |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 578 | m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.left, rect.top))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 579 | nEndChar = m_pEdit->WordPlaceToWordIndex( |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 580 | m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.right, rect.bottom))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 581 | } |
| 582 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 583 | CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar, |
| 584 | int32_t& nEndChar) const { |
| 585 | CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar); |
| 586 | CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar); |
| 587 | return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 590 | void CPWL_EditCtrl::SetReadyToInput() { |
| 591 | if (m_bMouseDown) { |
| 592 | ReleaseCapture(); |
| 593 | m_bMouseDown = FALSE; |
| 594 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 595 | } |