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