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