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