| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "fpdfsdk/include/pdfwindow/PWL_EditCtrl.h" | |
| 8 | |
| 9 #include "fpdfsdk/include/pdfwindow/PWL_Caret.h" | |
| 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" | |
| 14 #include "public/fpdf_fwlevent.h" | |
| 15 | |
| 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)) | |
| 20 | |
| 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(); | |
| 29 ASSERT(m_pEdit); | |
| 30 } | |
| 31 | |
| 32 CPWL_EditCtrl::~CPWL_EditCtrl() { | |
| 33 IFX_Edit::DelEdit(m_pEdit); | |
| 34 } | |
| 35 | |
| 36 void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM& cp) { | |
| 37 cp.eCursorType = FXCT_VBEAM; | |
| 38 } | |
| 39 | |
| 40 void CPWL_EditCtrl::OnCreated() { | |
| 41 SetFontSize(GetCreationParam().fFontSize); | |
| 42 | |
| 43 m_pEdit->SetFontMap(GetFontMap()); | |
| 44 m_pEdit->SetNotify(this); | |
| 45 m_pEdit->Initialize(); | |
| 46 } | |
| 47 | |
| 48 FX_BOOL CPWL_EditCtrl::IsWndHorV() { | |
| 49 CFX_Matrix mt = GetWindowMatrix(); | |
| 50 CFX_FloatPoint point1(0, 1); | |
| 51 CFX_FloatPoint point2(1, 1); | |
| 52 | |
| 53 mt.Transform(point1.x, point1.y); | |
| 54 mt.Transform(point2.x, point2.y); | |
| 55 | |
| 56 return point2.y == point1.y; | |
| 57 } | |
| 58 | |
| 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); | |
| 66 } | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 void CPWL_EditCtrl::RePosChildWnd() { | |
| 71 m_pEdit->SetPlateRect(GetClientRect()); | |
| 72 } | |
| 73 | |
| 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); | |
| 79 | |
| 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: | |
| 103 m_pEdit->SetScrollPos( | |
| 104 CFX_FloatPoint(m_pEdit->GetScrollPos().x, fPos)); | |
| 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 } | |
| 114 } | |
| 115 | |
| 116 void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) { | |
| 117 if (!IsReadOnly()) | |
| 118 CreateEditCaret(cp); | |
| 119 } | |
| 120 | |
| 121 void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) { | |
| 122 if (!m_pEditCaret) { | |
| 123 m_pEditCaret = new CPWL_Caret; | |
| 124 m_pEditCaret->SetInvalidRect(GetClientRect()); | |
| 125 | |
| 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; | |
| 131 ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); | |
| 132 | |
| 133 m_pEditCaret->Create(ecp); | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize) { | |
| 138 m_pEdit->SetFontSize(fFontSize); | |
| 139 } | |
| 140 | |
| 141 FX_FLOAT CPWL_EditCtrl::GetFontSize() const { | |
| 142 return m_pEdit->GetFontSize(); | |
| 143 } | |
| 144 | |
| 145 FX_BOOL CPWL_EditCtrl::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag) { | |
| 146 if (m_bMouseDown) | |
| 147 return TRUE; | |
| 148 | |
| 149 FX_BOOL bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag); | |
| 150 | |
| 151 // FILTER | |
| 152 switch (nChar) { | |
| 153 default: | |
| 154 return FALSE; | |
| 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': | |
| 173 break; | |
| 174 } | |
| 175 | |
| 176 if (nChar == FWL_VKEY_Delete) { | |
| 177 if (m_pEdit->IsSelected()) | |
| 178 nChar = FWL_VKEY_Unknown; | |
| 179 } | |
| 180 | |
| 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; | |
| 207 case FWL_VKEY_Unknown: | |
| 208 if (!IsSHIFTpressed(nFlag)) | |
| 209 Clear(); | |
| 210 else | |
| 211 CutText(); | |
| 212 return TRUE; | |
| 213 default: | |
| 214 break; | |
| 215 } | |
| 216 | |
| 217 return bRet; | |
| 218 } | |
| 219 | |
| 220 FX_BOOL CPWL_EditCtrl::OnChar(FX_WORD nChar, FX_DWORD nFlag) { | |
| 221 if (m_bMouseDown) | |
| 222 return TRUE; | |
| 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; | |
| 292 } | |
| 293 | |
| 294 FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CFX_FloatPoint& point, | |
| 295 FX_DWORD nFlag) { | |
| 296 CPWL_Wnd::OnLButtonDown(point, nFlag); | |
| 297 | |
| 298 if (ClientHitTest(point)) { | |
| 299 if (m_bMouseDown) | |
| 300 InvalidateRect(); | |
| 301 | |
| 302 m_bMouseDown = TRUE; | |
| 303 SetCapture(); | |
| 304 | |
| 305 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); | |
| 306 } | |
| 307 | |
| 308 return TRUE; | |
| 309 } | |
| 310 | |
| 311 FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CFX_FloatPoint& point, | |
| 312 FX_DWORD nFlag) { | |
| 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 | |
| 327 FX_BOOL CPWL_EditCtrl::OnMouseMove(const CFX_FloatPoint& point, | |
| 328 FX_DWORD nFlag) { | |
| 329 CPWL_Wnd::OnMouseMove(point, nFlag); | |
| 330 | |
| 331 if (m_bMouseDown) | |
| 332 m_pEdit->OnMouseMove(point, FALSE, FALSE); | |
| 333 | |
| 334 return TRUE; | |
| 335 } | |
| 336 | |
| 337 CFX_FloatRect CPWL_EditCtrl::GetContentRect() const { | |
| 338 return m_pEdit->GetContentRect(); | |
| 339 } | |
| 340 | |
| 341 void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible) { | |
| 342 CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0); | |
| 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 | |
| 352 void CPWL_EditCtrl::GetCaretInfo(CFX_FloatPoint& ptHead, | |
| 353 CFX_FloatPoint& ptFoot) const { | |
| 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; | |
| 368 } | |
| 369 } | |
| 370 } | |
| 371 | |
| 372 void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const { | |
| 373 CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0); | |
| 374 | |
| 375 GetCaretInfo(ptHead, ptFoot); | |
| 376 | |
| 377 PWLtoWnd(ptHead, x, y); | |
| 378 } | |
| 379 | |
| 380 void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible, | |
| 381 const CFX_FloatPoint& ptHead, | |
| 382 const CFX_FloatPoint& ptFoot) { | |
| 383 if (m_pEditCaret) { | |
| 384 if (!IsFocused() || m_pEdit->IsSelected()) | |
| 385 bVisible = FALSE; | |
| 386 | |
| 387 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot); | |
| 388 } | |
| 389 } | |
| 390 | |
| 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 | |
| 441 void CPWL_EditCtrl::SetScrollPos(const CFX_FloatPoint& point) { | |
| 442 if (m_pEdit) | |
| 443 m_pEdit->SetScrollPos(point); | |
| 444 } | |
| 445 | |
| 446 CFX_FloatPoint CPWL_EditCtrl::GetScrollPos() const { | |
| 447 if (m_pEdit) | |
| 448 return m_pEdit->GetScrollPos(); | |
| 449 | |
| 450 return CFX_FloatPoint(0.0f, 0.0f); | |
| 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 } | |
| 466 } | |
| 467 } | |
| 468 | |
| 469 if (IFX_Edit_FontMap* pFontMap = GetFontMap()) | |
| 470 return pFontMap->GetPDFFont(nFontIndex); | |
| 471 | |
| 472 return NULL; | |
| 473 } | |
| 474 | |
| 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 } | |
| 488 } | |
| 489 } | |
| 490 | |
| 491 return fFontSize; | |
| 492 } | |
| 493 | |
| 494 void CPWL_EditCtrl::SetText(const FX_WCHAR* csText) { | |
| 495 m_pEdit->SetText(csText); | |
| 496 } | |
| 497 | |
| 498 void CPWL_EditCtrl::CopyText() {} | |
| 499 | |
| 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, | |
| 578 const CFX_FloatPoint& ptHead, | |
| 579 const CFX_FloatPoint& ptFoot, | |
| 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 | |
| 592 void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) { | |
| 593 if (IsValid()) { | |
| 594 if (m_pEditNotify) { | |
| 595 m_pEditNotify->OnContentChange(rcContent); | |
| 596 } | |
| 597 } | |
| 598 } | |
| 599 | |
| 600 void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) { | |
| 601 InvalidateRect(pRect); | |
| 602 } | |
| 603 | |
| 604 int32_t CPWL_EditCtrl::GetCharSet() const { | |
| 605 return m_nCharSet < 0 ? DEFAULT_CHARSET : m_nCharSet; | |
| 606 } | |
| 607 | |
| 608 void CPWL_EditCtrl::GetTextRange(const CFX_FloatRect& rect, | |
| 609 int32_t& nStartChar, | |
| 610 int32_t& nEndChar) const { | |
| 611 nStartChar = m_pEdit->WordPlaceToWordIndex( | |
| 612 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.left, rect.top))); | |
| 613 nEndChar = m_pEdit->WordPlaceToWordIndex( | |
| 614 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.right, rect.bottom))); | |
| 615 } | |
| 616 | |
| 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)); | |
| 622 } | |
| 623 | |
| 624 void CPWL_EditCtrl::SetReadyToInput() { | |
| 625 if (m_bMouseDown) { | |
| 626 ReleaseCapture(); | |
| 627 m_bMouseDown = FALSE; | |
| 628 } | |
| 629 } | |
| OLD | NEW |