OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fde/cfde_txtedtengine.h" | 7 #include "xfa/fde/cfde_txtedtengine.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 m_nCaret = nIndex; | 199 m_nCaret = nIndex; |
200 MovePage2Char(m_nCaret); | 200 MovePage2Char(m_nCaret); |
201 GetCaretRect(m_rtCaret, m_nCaretPage, m_nCaret, m_bBefore); | 201 GetCaretRect(m_rtCaret, m_nCaretPage, m_nCaret, m_bBefore); |
202 if (!m_bBefore) { | 202 if (!m_bBefore) { |
203 m_nCaret++; | 203 m_nCaret++; |
204 m_bBefore = true; | 204 m_bBefore = true; |
205 } | 205 } |
206 m_fCaretPosReserve = (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) | 206 m_fCaretPosReserve = (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) |
207 ? m_rtCaret.top | 207 ? m_rtCaret.top |
208 : m_rtCaret.left; | 208 : m_rtCaret.left; |
209 m_Param.pEventSink->On_CaretChanged(this, m_nCaretPage, 0); | 209 m_Param.pEventSink->On_CaretChanged(); |
210 m_nAnchorPos = -1; | 210 m_nAnchorPos = -1; |
211 return m_nCaret; | 211 return m_nCaret; |
212 } | 212 } |
213 | 213 |
214 int32_t CFDE_TxtEdtEngine::MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret, | 214 int32_t CFDE_TxtEdtEngine::MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret, |
215 bool bShift, | 215 bool bShift, |
216 bool bCtrl) { | 216 bool bCtrl) { |
217 if (IsLocked()) { | 217 if (IsLocked()) { |
218 return 0; | 218 return 0; |
219 } | 219 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 break; | 315 break; |
316 case MC_End: | 316 case MC_End: |
317 MoveEnd(); | 317 MoveEnd(); |
318 break; | 318 break; |
319 default: | 319 default: |
320 break; | 320 break; |
321 } | 321 } |
322 if (bShift && m_nAnchorPos != -1 && (m_nAnchorPos != m_nCaret)) { | 322 if (bShift && m_nAnchorPos != -1 && (m_nAnchorPos != m_nCaret)) { |
323 AddSelRange(std::min(m_nAnchorPos, m_nCaret), | 323 AddSelRange(std::min(m_nAnchorPos, m_nCaret), |
324 FXSYS_abs(m_nAnchorPos - m_nCaret)); | 324 FXSYS_abs(m_nAnchorPos - m_nCaret)); |
325 m_Param.pEventSink->On_SelChanged(this); | 325 m_Param.pEventSink->On_SelChanged(); |
326 } | 326 } |
327 if (bSelChange) { | 327 if (bSelChange) |
328 m_Param.pEventSink->On_SelChanged(this); | 328 m_Param.pEventSink->On_SelChanged(); |
329 } | 329 |
330 return m_nCaret; | 330 return m_nCaret; |
331 } | 331 } |
332 | 332 |
333 void CFDE_TxtEdtEngine::Lock() { | 333 void CFDE_TxtEdtEngine::Lock() { |
334 m_bLock = true; | 334 m_bLock = true; |
335 } | 335 } |
336 | 336 |
337 void CFDE_TxtEdtEngine::Unlock() { | 337 void CFDE_TxtEdtEngine::Unlock() { |
338 m_bLock = false; | 338 m_bLock = false; |
339 } | 339 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 } | 398 } |
399 if (nLength == 0) { | 399 if (nLength == 0) { |
400 return FDE_TXTEDT_MODIFY_RET_F_Full; | 400 return FDE_TXTEDT_MODIFY_RET_F_Full; |
401 } | 401 } |
402 if (nLength < nTemp) { | 402 if (nLength < nTemp) { |
403 bPart = true; | 403 bPart = true; |
404 } | 404 } |
405 } | 405 } |
406 if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { | 406 if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { |
407 CFX_WideString wsText = GetPreInsertText(m_nCaret, lpBuffer, nLength); | 407 CFX_WideString wsText = GetPreInsertText(m_nCaret, lpBuffer, nLength); |
408 if (!m_Param.pEventSink->On_Validate(this, wsText)) { | 408 if (!m_Param.pEventSink->On_Validate(wsText)) |
409 return FDE_TXTEDT_MODIFY_RET_F_Invalidate; | 409 return FDE_TXTEDT_MODIFY_RET_F_Invalidate; |
410 } | |
411 } | 410 } |
412 if (IsSelect()) { | 411 if (IsSelect()) { |
413 DeleteSelect(); | 412 DeleteSelect(); |
414 } | 413 } |
415 if (!(m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo)) | 414 if (!(m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo)) |
416 m_Param.pEventSink->On_AddDoRecord( | 415 m_Param.pEventSink->On_AddDoRecord( |
417 this, | |
418 new CFDE_TxtEdtDoRecord_Insert(this, m_nCaret, lpBuffer, nLength)); | 416 new CFDE_TxtEdtDoRecord_Insert(this, m_nCaret, lpBuffer, nLength)); |
419 | 417 |
420 m_ChangeInfo.wsPrevText = GetText(0); | 418 m_ChangeInfo.wsPrevText = GetText(0, -1); |
421 Inner_Insert(m_nCaret, lpBuffer, nLength); | 419 Inner_Insert(m_nCaret, lpBuffer, nLength); |
422 m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Insert; | 420 m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Insert; |
423 m_ChangeInfo.wsInsert = CFX_WideString(lpBuffer, nLength); | 421 m_ChangeInfo.wsInsert = CFX_WideString(lpBuffer, nLength); |
424 nStart = m_nCaret; | 422 nStart = m_nCaret; |
425 nStart += nLength; | 423 nStart += nLength; |
426 FX_WCHAR wChar = m_pTxtBuf->GetCharByIndex(nStart - 1); | 424 FX_WCHAR wChar = m_pTxtBuf->GetCharByIndex(nStart - 1); |
427 bool bBefore = true; | 425 bool bBefore = true; |
428 if (wChar != L'\n' && wChar != L'\r') { | 426 if (wChar != L'\n' && wChar != L'\r') { |
429 nStart--; | 427 nStart--; |
430 bBefore = false; | 428 bBefore = false; |
431 } | 429 } |
432 SetCaretPos(nStart, bBefore); | 430 SetCaretPos(nStart, bBefore); |
433 m_Param.pEventSink->On_TextChanged(this, m_ChangeInfo); | 431 m_Param.pEventSink->On_TextChanged(m_ChangeInfo); |
434 return bPart ? FDE_TXTEDT_MODIFY_RET_S_Part : FDE_TXTEDT_MODIFY_RET_S_Normal; | 432 return bPart ? FDE_TXTEDT_MODIFY_RET_S_Part : FDE_TXTEDT_MODIFY_RET_S_Normal; |
435 } | 433 } |
436 | 434 |
437 int32_t CFDE_TxtEdtEngine::Delete(int32_t nStart, bool bBackspace) { | 435 int32_t CFDE_TxtEdtEngine::Delete(int32_t nStart, bool bBackspace) { |
438 if (IsLocked()) { | 436 if (IsLocked()) { |
439 return FDE_TXTEDT_MODIFY_RET_F_Locked; | 437 return FDE_TXTEDT_MODIFY_RET_F_Locked; |
440 } | 438 } |
441 if (IsSelect()) { | 439 if (IsSelect()) { |
442 DeleteSelect(); | 440 DeleteSelect(); |
443 return FDE_TXTEDT_MODIFY_RET_S_Normal; | 441 return FDE_TXTEDT_MODIFY_RET_S_Normal; |
(...skipping 15 matching lines...) Expand all Loading... |
459 return FDE_TXTEDT_MODIFY_RET_F_Full; | 457 return FDE_TXTEDT_MODIFY_RET_F_Full; |
460 } | 458 } |
461 if ((nStart + 1 < GetTextBufLength()) && | 459 if ((nStart + 1 < GetTextBufLength()) && |
462 (m_pTxtBuf->GetCharByIndex(nStart) == L'\r') && | 460 (m_pTxtBuf->GetCharByIndex(nStart) == L'\r') && |
463 (m_pTxtBuf->GetCharByIndex(nStart + 1) == L'\n')) { | 461 (m_pTxtBuf->GetCharByIndex(nStart + 1) == L'\n')) { |
464 nCount++; | 462 nCount++; |
465 } | 463 } |
466 } | 464 } |
467 if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { | 465 if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { |
468 CFX_WideString wsText = GetPreDeleteText(nStart, nCount); | 466 CFX_WideString wsText = GetPreDeleteText(nStart, nCount); |
469 if (!m_Param.pEventSink->On_Validate(this, wsText)) { | 467 if (!m_Param.pEventSink->On_Validate(wsText)) |
470 return FDE_TXTEDT_MODIFY_RET_F_Invalidate; | 468 return FDE_TXTEDT_MODIFY_RET_F_Invalidate; |
471 } | |
472 } | 469 } |
473 if (!(m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo)) { | 470 if (!(m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo)) { |
474 CFX_WideString wsRange = m_pTxtBuf->GetRange(nStart, nCount); | 471 CFX_WideString wsRange = m_pTxtBuf->GetRange(nStart, nCount); |
475 m_Param.pEventSink->On_AddDoRecord( | 472 m_Param.pEventSink->On_AddDoRecord( |
476 this, | |
477 new CFDE_TxtEdtDoRecord_DeleteRange(this, nStart, m_nCaret, wsRange)); | 473 new CFDE_TxtEdtDoRecord_DeleteRange(this, nStart, m_nCaret, wsRange)); |
478 } | 474 } |
479 m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Delete; | 475 m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Delete; |
480 m_ChangeInfo.wsDelete = GetText(nStart, nCount); | 476 m_ChangeInfo.wsDelete = GetText(nStart, nCount); |
481 Inner_DeleteRange(nStart, nCount); | 477 Inner_DeleteRange(nStart, nCount); |
482 SetCaretPos(nStart + ((!bBackspace && nStart > 0) ? -1 : 0), | 478 SetCaretPos(nStart + ((!bBackspace && nStart > 0) ? -1 : 0), |
483 (bBackspace || nStart == 0)); | 479 (bBackspace || nStart == 0)); |
484 m_Param.pEventSink->On_TextChanged(this, m_ChangeInfo); | 480 m_Param.pEventSink->On_TextChanged(m_ChangeInfo); |
485 return FDE_TXTEDT_MODIFY_RET_S_Normal; | 481 return FDE_TXTEDT_MODIFY_RET_S_Normal; |
486 } | 482 } |
487 | 483 |
488 int32_t CFDE_TxtEdtEngine::DeleteRange(int32_t nStart, int32_t nCount) { | 484 int32_t CFDE_TxtEdtEngine::DeleteRange(int32_t nStart, int32_t nCount) { |
489 if (IsLocked()) { | 485 if (IsLocked()) |
490 return FDE_TXTEDT_MODIFY_RET_F_Locked; | 486 return FDE_TXTEDT_MODIFY_RET_F_Locked; |
491 } | 487 if (nCount == -1) |
492 if (nCount == -1) { | |
493 nCount = GetTextBufLength(); | 488 nCount = GetTextBufLength(); |
494 } | 489 if (nCount == 0) |
495 if (nCount == 0) { | |
496 return FDE_TXTEDT_MODIFY_RET_S_Normal; | 490 return FDE_TXTEDT_MODIFY_RET_S_Normal; |
497 } | |
498 if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { | 491 if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { |
499 CFX_WideString wsText = GetPreDeleteText(nStart, nCount); | 492 CFX_WideString wsText = GetPreDeleteText(nStart, nCount); |
500 if (!m_Param.pEventSink->On_Validate(this, wsText)) { | 493 if (!m_Param.pEventSink->On_Validate(wsText)) |
501 return FDE_TXTEDT_MODIFY_RET_F_Invalidate; | 494 return FDE_TXTEDT_MODIFY_RET_F_Invalidate; |
502 } | |
503 } | 495 } |
504 DeleteRange_DoRecord(nStart, nCount); | 496 DeleteRange_DoRecord(nStart, nCount); |
505 m_Param.pEventSink->On_TextChanged(this, m_ChangeInfo); | 497 m_Param.pEventSink->On_TextChanged(m_ChangeInfo); |
506 SetCaretPos(nStart, true); | 498 SetCaretPos(nStart, true); |
507 return FDE_TXTEDT_MODIFY_RET_S_Normal; | 499 return FDE_TXTEDT_MODIFY_RET_S_Normal; |
508 } | 500 } |
509 | 501 |
510 int32_t CFDE_TxtEdtEngine::Replace(int32_t nStart, | 502 int32_t CFDE_TxtEdtEngine::Replace(int32_t nStart, |
511 int32_t nLength, | 503 int32_t nLength, |
512 const CFX_WideString& wsReplace) { | 504 const CFX_WideString& wsReplace) { |
513 if (IsLocked()) { | 505 if (IsLocked()) |
514 return FDE_TXTEDT_MODIFY_RET_F_Locked; | 506 return FDE_TXTEDT_MODIFY_RET_F_Locked; |
515 } | 507 if (nStart < 0 || (nStart + nLength > GetTextBufLength())) |
516 if (nStart < 0 || (nStart + nLength > GetTextBufLength())) { | |
517 return FDE_TXTEDT_MODIFY_RET_F_Boundary; | 508 return FDE_TXTEDT_MODIFY_RET_F_Boundary; |
518 } | |
519 if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { | 509 if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { |
520 CFX_WideString wsText = GetPreReplaceText( | 510 CFX_WideString wsText = GetPreReplaceText( |
521 nStart, nLength, wsReplace.c_str(), wsReplace.GetLength()); | 511 nStart, nLength, wsReplace.c_str(), wsReplace.GetLength()); |
522 if (!m_Param.pEventSink->On_Validate(this, wsText)) { | 512 if (!m_Param.pEventSink->On_Validate(wsText)) |
523 return FDE_TXTEDT_MODIFY_RET_F_Invalidate; | 513 return FDE_TXTEDT_MODIFY_RET_F_Invalidate; |
524 } | |
525 } | 514 } |
526 if (IsSelect()) { | 515 if (IsSelect()) |
527 ClearSelection(); | 516 ClearSelection(); |
528 } | 517 |
529 m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Replace; | 518 m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Replace; |
530 m_ChangeInfo.wsDelete = GetText(nStart, nLength); | 519 m_ChangeInfo.wsDelete = GetText(nStart, nLength); |
531 if (nLength > 0) { | 520 if (nLength > 0) |
532 Inner_DeleteRange(nStart, nLength); | 521 Inner_DeleteRange(nStart, nLength); |
533 } | 522 |
534 int32_t nTextLength = wsReplace.GetLength(); | 523 int32_t nTextLength = wsReplace.GetLength(); |
535 if (nTextLength > 0) { | 524 if (nTextLength > 0) |
536 Inner_Insert(nStart, wsReplace.c_str(), nTextLength); | 525 Inner_Insert(nStart, wsReplace.c_str(), nTextLength); |
537 } | 526 |
538 m_ChangeInfo.wsInsert = CFX_WideString(wsReplace.c_str(), nTextLength); | 527 m_ChangeInfo.wsInsert = CFX_WideString(wsReplace.c_str(), nTextLength); |
539 nStart += nTextLength; | 528 nStart += nTextLength; |
540 FX_WCHAR wChar = m_pTxtBuf->GetCharByIndex(nStart - 1); | 529 FX_WCHAR wChar = m_pTxtBuf->GetCharByIndex(nStart - 1); |
541 bool bBefore = true; | 530 bool bBefore = true; |
542 if (wChar != L'\n' && wChar != L'\r') { | 531 if (wChar != L'\n' && wChar != L'\r') { |
543 nStart--; | 532 nStart--; |
544 bBefore = false; | 533 bBefore = false; |
545 } | 534 } |
546 SetCaretPos(nStart, bBefore); | 535 SetCaretPos(nStart, bBefore); |
547 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); | 536 m_Param.pEventSink->On_PageUnload(m_nCaretPage); |
548 m_Param.pEventSink->On_PageLoad(this, m_nCaretPage, 0); | 537 m_Param.pEventSink->On_PageLoad(m_nCaretPage); |
549 m_Param.pEventSink->On_TextChanged(this, m_ChangeInfo); | 538 m_Param.pEventSink->On_TextChanged(m_ChangeInfo); |
550 return FDE_TXTEDT_MODIFY_RET_S_Normal; | 539 return FDE_TXTEDT_MODIFY_RET_S_Normal; |
551 } | 540 } |
552 | 541 |
553 void CFDE_TxtEdtEngine::SetLimit(int32_t nLimit) { | 542 void CFDE_TxtEdtEngine::SetLimit(int32_t nLimit) { |
554 m_nLimit = nLimit; | 543 m_nLimit = nLimit; |
555 } | 544 } |
556 | 545 |
557 void CFDE_TxtEdtEngine::SetAliasChar(FX_WCHAR wcAlias) { | 546 void CFDE_TxtEdtEngine::SetAliasChar(FX_WCHAR wcAlias) { |
558 m_wcAliasChar = wcAlias; | 547 m_wcAliasChar = wcAlias; |
559 } | 548 } |
(...skipping 15 matching lines...) Expand all Loading... |
575 void CFDE_TxtEdtEngine::AddSelRange(int32_t nStart, int32_t nCount) { | 564 void CFDE_TxtEdtEngine::AddSelRange(int32_t nStart, int32_t nCount) { |
576 if (nCount == -1) { | 565 if (nCount == -1) { |
577 nCount = GetTextLength() - nStart; | 566 nCount = GetTextLength() - nStart; |
578 } | 567 } |
579 int32_t nSize = m_SelRangePtrArr.GetSize(); | 568 int32_t nSize = m_SelRangePtrArr.GetSize(); |
580 if (nSize <= 0) { | 569 if (nSize <= 0) { |
581 FDE_TXTEDTSELRANGE* lpSelRange = new FDE_TXTEDTSELRANGE; | 570 FDE_TXTEDTSELRANGE* lpSelRange = new FDE_TXTEDTSELRANGE; |
582 lpSelRange->nStart = nStart; | 571 lpSelRange->nStart = nStart; |
583 lpSelRange->nCount = nCount; | 572 lpSelRange->nCount = nCount; |
584 m_SelRangePtrArr.Add(lpSelRange); | 573 m_SelRangePtrArr.Add(lpSelRange); |
585 m_Param.pEventSink->On_SelChanged(this); | 574 m_Param.pEventSink->On_SelChanged(); |
586 return; | 575 return; |
587 } | 576 } |
588 FDE_TXTEDTSELRANGE* lpTemp = nullptr; | 577 FDE_TXTEDTSELRANGE* lpTemp = nullptr; |
589 lpTemp = m_SelRangePtrArr[nSize - 1]; | 578 lpTemp = m_SelRangePtrArr[nSize - 1]; |
590 if (nStart >= lpTemp->nStart + lpTemp->nCount) { | 579 if (nStart >= lpTemp->nStart + lpTemp->nCount) { |
591 FDE_TXTEDTSELRANGE* lpSelRange = new FDE_TXTEDTSELRANGE; | 580 FDE_TXTEDTSELRANGE* lpSelRange = new FDE_TXTEDTSELRANGE; |
592 lpSelRange->nStart = nStart; | 581 lpSelRange->nStart = nStart; |
593 lpSelRange->nCount = nCount; | 582 lpSelRange->nCount = nCount; |
594 m_SelRangePtrArr.Add(lpSelRange); | 583 m_SelRangePtrArr.Add(lpSelRange); |
595 m_Param.pEventSink->On_SelChanged(this); | 584 m_Param.pEventSink->On_SelChanged(); |
596 return; | 585 return; |
597 } | 586 } |
598 int32_t nEnd = nStart + nCount - 1; | 587 int32_t nEnd = nStart + nCount - 1; |
599 bool bBegin = false; | 588 bool bBegin = false; |
600 int32_t nRangeBgn = 0; | 589 int32_t nRangeBgn = 0; |
601 int32_t nRangeCnt = 0; | 590 int32_t nRangeCnt = 0; |
602 for (int32_t i = 0; i < nSize; i++) { | 591 for (int32_t i = 0; i < nSize; i++) { |
603 lpTemp = m_SelRangePtrArr[i]; | 592 lpTemp = m_SelRangePtrArr[i]; |
604 int32_t nTempBgn = lpTemp->nStart; | 593 int32_t nTempBgn = lpTemp->nStart; |
605 int32_t nTempEnd = nTempBgn + lpTemp->nCount - 1; | 594 int32_t nTempEnd = nTempBgn + lpTemp->nCount - 1; |
(...skipping 25 matching lines...) Expand all Loading... |
631 lpTemp = m_SelRangePtrArr[nRangeBgn]; | 620 lpTemp = m_SelRangePtrArr[nRangeBgn]; |
632 lpTemp->nStart = nStart; | 621 lpTemp->nStart = nStart; |
633 lpTemp->nCount = nCount; | 622 lpTemp->nCount = nCount; |
634 nRangeCnt--; | 623 nRangeCnt--; |
635 nRangeBgn++; | 624 nRangeBgn++; |
636 while (nRangeCnt--) { | 625 while (nRangeCnt--) { |
637 delete m_SelRangePtrArr[nRangeBgn]; | 626 delete m_SelRangePtrArr[nRangeBgn]; |
638 m_SelRangePtrArr.RemoveAt(nRangeBgn); | 627 m_SelRangePtrArr.RemoveAt(nRangeBgn); |
639 } | 628 } |
640 } | 629 } |
641 m_Param.pEventSink->On_SelChanged(this); | 630 m_Param.pEventSink->On_SelChanged(); |
642 } | 631 } |
643 | 632 |
644 int32_t CFDE_TxtEdtEngine::CountSelRanges() const { | 633 int32_t CFDE_TxtEdtEngine::CountSelRanges() const { |
645 return m_SelRangePtrArr.GetSize(); | 634 return m_SelRangePtrArr.GetSize(); |
646 } | 635 } |
647 | 636 |
648 int32_t CFDE_TxtEdtEngine::GetSelRange(int32_t nIndex, int32_t& nStart) const { | 637 int32_t CFDE_TxtEdtEngine::GetSelRange(int32_t nIndex, int32_t& nStart) const { |
649 nStart = m_SelRangePtrArr[nIndex]->nStart; | 638 nStart = m_SelRangePtrArr[nIndex]->nStart; |
650 return m_SelRangePtrArr[nIndex]->nCount; | 639 return m_SelRangePtrArr[nIndex]->nCount; |
651 } | 640 } |
652 | 641 |
653 void CFDE_TxtEdtEngine::ClearSelection() { | 642 void CFDE_TxtEdtEngine::ClearSelection() { |
654 int32_t nCount = m_SelRangePtrArr.GetSize(); | 643 int32_t nCount = m_SelRangePtrArr.GetSize(); |
655 for (int i = 0; i < nCount; ++i) | 644 for (int i = 0; i < nCount; ++i) |
656 delete m_SelRangePtrArr[i]; | 645 delete m_SelRangePtrArr[i]; |
657 m_SelRangePtrArr.RemoveAll(); | 646 m_SelRangePtrArr.RemoveAll(); |
658 if (nCount && m_Param.pEventSink) | 647 if (nCount && m_Param.pEventSink) |
659 m_Param.pEventSink->On_SelChanged(this); | 648 m_Param.pEventSink->On_SelChanged(); |
660 } | 649 } |
661 | 650 |
662 bool CFDE_TxtEdtEngine::Redo(const IFDE_TxtEdtDoRecord* pDoRecord) { | 651 bool CFDE_TxtEdtEngine::Redo(const IFDE_TxtEdtDoRecord* pDoRecord) { |
663 if (IsLocked()) | 652 if (IsLocked()) |
664 return false; | 653 return false; |
665 if (m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo) | 654 if (m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo) |
666 return false; | 655 return false; |
667 return pDoRecord->Redo(); | 656 return pDoRecord->Redo(); |
668 } | 657 } |
669 | 658 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 | 811 |
823 return wsText; | 812 return wsText; |
824 } | 813 } |
825 | 814 |
826 void CFDE_TxtEdtEngine::Inner_Insert(int32_t nStart, | 815 void CFDE_TxtEdtEngine::Inner_Insert(int32_t nStart, |
827 const FX_WCHAR* lpText, | 816 const FX_WCHAR* lpText, |
828 int32_t nLength) { | 817 int32_t nLength) { |
829 ASSERT(nLength > 0); | 818 ASSERT(nLength > 0); |
830 FDE_TXTEDTPARAGPOS ParagPos; | 819 FDE_TXTEDTPARAGPOS ParagPos; |
831 TextPos2ParagPos(nStart, ParagPos); | 820 TextPos2ParagPos(nStart, ParagPos); |
832 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); | 821 m_Param.pEventSink->On_PageUnload(m_nCaretPage); |
833 int32_t nParagCount = m_ParagPtrArray.GetSize(); | 822 int32_t nParagCount = m_ParagPtrArray.GetSize(); |
834 int32_t i = 0; | 823 int32_t i = 0; |
835 for (i = ParagPos.nParagIndex + 1; i < nParagCount; i++) | 824 for (i = ParagPos.nParagIndex + 1; i < nParagCount; i++) |
836 m_ParagPtrArray[i]->IncrementStartIndex(nLength); | 825 m_ParagPtrArray[i]->IncrementStartIndex(nLength); |
837 | 826 |
838 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex]; | 827 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex]; |
839 int32_t nReserveLineCount = pParag->GetLineCount(); | 828 int32_t nReserveLineCount = pParag->GetLineCount(); |
840 int32_t nReserveCharStart = pParag->GetStartIndex(); | 829 int32_t nReserveCharStart = pParag->GetStartIndex(); |
841 int32_t nLeavePart = ParagPos.nCharIndex; | 830 int32_t nLeavePart = ParagPos.nCharIndex; |
842 int32_t nCutPart = pParag->GetTextLength() - ParagPos.nCharIndex; | 831 int32_t nCutPart = pParag->GetTextLength() - ParagPos.nCharIndex; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 m_ParagPtrArray.InsertAt(++nParagIndex, pParag); | 865 m_ParagPtrArray.InsertAt(++nParagIndex, pParag); |
877 } | 866 } |
878 m_pTxtBuf->Insert(nStart, lpText, nLength); | 867 m_pTxtBuf->Insert(nStart, lpText, nLength); |
879 int32_t nTotalLineCount = 0; | 868 int32_t nTotalLineCount = 0; |
880 for (i = ParagPos.nParagIndex; i <= nParagIndex; i++) { | 869 for (i = ParagPos.nParagIndex; i <= nParagIndex; i++) { |
881 pParag = m_ParagPtrArray[i]; | 870 pParag = m_ParagPtrArray[i]; |
882 pParag->CalcLines(); | 871 pParag->CalcLines(); |
883 nTotalLineCount += pParag->GetLineCount(); | 872 nTotalLineCount += pParag->GetLineCount(); |
884 } | 873 } |
885 m_nLineCount += nTotalLineCount - nReserveLineCount; | 874 m_nLineCount += nTotalLineCount - nReserveLineCount; |
886 m_Param.pEventSink->On_PageLoad(this, m_nCaretPage, 0); | 875 m_Param.pEventSink->On_PageLoad(m_nCaretPage); |
887 UpdatePages(); | 876 UpdatePages(); |
888 } | 877 } |
889 | 878 |
890 void CFDE_TxtEdtEngine::Inner_DeleteRange(int32_t nStart, int32_t nCount) { | 879 void CFDE_TxtEdtEngine::Inner_DeleteRange(int32_t nStart, int32_t nCount) { |
891 if (nCount == -1) { | 880 if (nCount == -1) { |
892 nCount = m_pTxtBuf->GetTextLength() - nStart; | 881 nCount = m_pTxtBuf->GetTextLength() - nStart; |
893 } | 882 } |
894 int32_t nEnd = nStart + nCount - 1; | 883 int32_t nEnd = nStart + nCount - 1; |
895 ASSERT(nStart >= 0 && nEnd < m_pTxtBuf->GetTextLength()); | 884 ASSERT(nStart >= 0 && nEnd < m_pTxtBuf->GetTextLength()); |
896 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); | 885 m_Param.pEventSink->On_PageUnload(m_nCaretPage); |
897 FDE_TXTEDTPARAGPOS ParagPosBgn, ParagPosEnd; | 886 FDE_TXTEDTPARAGPOS ParagPosBgn, ParagPosEnd; |
898 TextPos2ParagPos(nStart, ParagPosBgn); | 887 TextPos2ParagPos(nStart, ParagPosBgn); |
899 TextPos2ParagPos(nEnd, ParagPosEnd); | 888 TextPos2ParagPos(nEnd, ParagPosEnd); |
900 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPosEnd.nParagIndex]; | 889 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPosEnd.nParagIndex]; |
901 bool bLastParag = false; | 890 bool bLastParag = false; |
902 if (ParagPosEnd.nCharIndex == pParag->GetTextLength() - 1) { | 891 if (ParagPosEnd.nCharIndex == pParag->GetTextLength() - 1) { |
903 if (ParagPosEnd.nParagIndex < m_ParagPtrArray.GetSize() - 1) { | 892 if (ParagPosEnd.nParagIndex < m_ParagPtrArray.GetSize() - 1) { |
904 ParagPosEnd.nParagIndex++; | 893 ParagPosEnd.nParagIndex++; |
905 } else { | 894 } else { |
906 bLastParag = true; | 895 bLastParag = true; |
(...skipping 25 matching lines...) Expand all Loading... |
932 int32_t nParagCount = m_ParagPtrArray.GetSize(); | 921 int32_t nParagCount = m_ParagPtrArray.GetSize(); |
933 for (i = nNextParagIndex; i < nParagCount; i++) | 922 for (i = nNextParagIndex; i < nParagCount; i++) |
934 m_ParagPtrArray[i]->DecrementStartIndex(nCount); | 923 m_ParagPtrArray[i]->DecrementStartIndex(nCount); |
935 | 924 |
936 m_nLineCount -= nTotalLineCount; | 925 m_nLineCount -= nTotalLineCount; |
937 UpdatePages(); | 926 UpdatePages(); |
938 int32_t nPageCount = CountPages(); | 927 int32_t nPageCount = CountPages(); |
939 if (m_nCaretPage >= nPageCount) { | 928 if (m_nCaretPage >= nPageCount) { |
940 m_nCaretPage = nPageCount - 1; | 929 m_nCaretPage = nPageCount - 1; |
941 } | 930 } |
942 m_Param.pEventSink->On_PageLoad(this, m_nCaretPage, 0); | 931 m_Param.pEventSink->On_PageLoad(m_nCaretPage); |
943 } | 932 } |
944 | 933 |
945 void CFDE_TxtEdtEngine::DeleteRange_DoRecord(int32_t nStart, | 934 void CFDE_TxtEdtEngine::DeleteRange_DoRecord(int32_t nStart, |
946 int32_t nCount, | 935 int32_t nCount, |
947 bool bSel) { | 936 bool bSel) { |
948 ASSERT(nStart >= 0); | 937 ASSERT(nStart >= 0); |
949 if (nCount == -1) { | 938 if (nCount == -1) { |
950 nCount = GetTextLength() - nStart; | 939 nCount = GetTextLength() - nStart; |
951 } | 940 } |
952 ASSERT((nStart + nCount) <= m_pTxtBuf->GetTextLength()); | 941 ASSERT((nStart + nCount) <= m_pTxtBuf->GetTextLength()); |
953 | 942 |
954 if (!(m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo)) { | 943 if (!(m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo)) { |
955 CFX_WideString wsRange = m_pTxtBuf->GetRange(nStart, nCount); | 944 CFX_WideString wsRange = m_pTxtBuf->GetRange(nStart, nCount); |
956 m_Param.pEventSink->On_AddDoRecord( | 945 m_Param.pEventSink->On_AddDoRecord(new CFDE_TxtEdtDoRecord_DeleteRange( |
957 this, new CFDE_TxtEdtDoRecord_DeleteRange(this, nStart, m_nCaret, | 946 this, nStart, m_nCaret, wsRange, bSel)); |
958 wsRange, bSel)); | |
959 } | 947 } |
960 m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Delete; | 948 m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Delete; |
961 m_ChangeInfo.wsDelete = GetText(nStart, nCount); | 949 m_ChangeInfo.wsDelete = GetText(nStart, nCount); |
962 Inner_DeleteRange(nStart, nCount); | 950 Inner_DeleteRange(nStart, nCount); |
963 } | 951 } |
964 | 952 |
965 void CFDE_TxtEdtEngine::ResetEngine() { | 953 void CFDE_TxtEdtEngine::ResetEngine() { |
966 RemoveAllPages(); | 954 RemoveAllPages(); |
967 RemoveAllParags(); | 955 RemoveAllParags(); |
968 ClearSelection(); | 956 ClearSelection(); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 *lpBuf = wc; | 1215 *lpBuf = wc; |
1228 } | 1216 } |
1229 } | 1217 } |
1230 } | 1218 } |
1231 | 1219 |
1232 int32_t CFDE_TxtEdtEngine::MovePage2Char(int32_t nIndex) { | 1220 int32_t CFDE_TxtEdtEngine::MovePage2Char(int32_t nIndex) { |
1233 ASSERT(nIndex >= 0); | 1221 ASSERT(nIndex >= 0); |
1234 ASSERT(nIndex <= m_pTxtBuf->GetTextLength()); | 1222 ASSERT(nIndex <= m_pTxtBuf->GetTextLength()); |
1235 if (m_nCaretPage >= 0) { | 1223 if (m_nCaretPage >= 0) { |
1236 IFDE_TxtEdtPage* pPage = m_PagePtrArray[m_nCaretPage]; | 1224 IFDE_TxtEdtPage* pPage = m_PagePtrArray[m_nCaretPage]; |
1237 m_Param.pEventSink->On_PageLoad(this, m_nCaretPage, 0); | 1225 m_Param.pEventSink->On_PageLoad(m_nCaretPage); |
1238 int32_t nPageCharStart = pPage->GetCharStart(); | 1226 int32_t nPageCharStart = pPage->GetCharStart(); |
1239 int32_t nPageCharCount = pPage->GetCharCount(); | 1227 int32_t nPageCharCount = pPage->GetCharCount(); |
1240 if (nIndex >= nPageCharStart && nIndex < nPageCharStart + nPageCharCount) { | 1228 if (nIndex >= nPageCharStart && nIndex < nPageCharStart + nPageCharCount) { |
1241 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); | 1229 m_Param.pEventSink->On_PageUnload(m_nCaretPage); |
1242 return m_nCaretPage; | 1230 return m_nCaretPage; |
1243 } | 1231 } |
1244 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); | 1232 m_Param.pEventSink->On_PageUnload(m_nCaretPage); |
1245 } | 1233 } |
1246 CFDE_TxtEdtParag* pParag = nullptr; | 1234 CFDE_TxtEdtParag* pParag = nullptr; |
1247 int32_t nLineCount = 0; | 1235 int32_t nLineCount = 0; |
1248 int32_t nParagCount = m_ParagPtrArray.GetSize(); | 1236 int32_t nParagCount = m_ParagPtrArray.GetSize(); |
1249 int32_t i = 0; | 1237 int32_t i = 0; |
1250 for (i = 0; i < nParagCount; i++) { | 1238 for (i = 0; i < nParagCount; i++) { |
1251 pParag = m_ParagPtrArray[i]; | 1239 pParag = m_ParagPtrArray[i]; |
1252 if (pParag->GetStartIndex() <= nIndex && | 1240 if (pParag->GetStartIndex() <= nIndex && |
1253 nIndex < (pParag->GetStartIndex() + pParag->GetTextLength())) { | 1241 nIndex < (pParag->GetStartIndex() + pParag->GetTextLength())) { |
1254 break; | 1242 break; |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 GetCaretRect(m_rtCaret, m_nCaretPage, nIndex, bBefore); | 1532 GetCaretRect(m_rtCaret, m_nCaretPage, nIndex, bBefore); |
1545 m_nCaret = nIndex; | 1533 m_nCaret = nIndex; |
1546 m_bBefore = bBefore; | 1534 m_bBefore = bBefore; |
1547 if (!m_bBefore) { | 1535 if (!m_bBefore) { |
1548 m_nCaret++; | 1536 m_nCaret++; |
1549 m_bBefore = true; | 1537 m_bBefore = true; |
1550 } | 1538 } |
1551 m_fCaretPosReserve = (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) | 1539 m_fCaretPosReserve = (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) |
1552 ? m_rtCaret.top | 1540 ? m_rtCaret.top |
1553 : m_rtCaret.left; | 1541 : m_rtCaret.left; |
1554 m_Param.pEventSink->On_CaretChanged(this, m_nCaretPage, 0); | 1542 m_Param.pEventSink->On_CaretChanged(); |
1555 } | 1543 } |
1556 | 1544 |
1557 void CFDE_TxtEdtEngine::GetCaretRect(CFX_RectF& rtCaret, | 1545 void CFDE_TxtEdtEngine::GetCaretRect(CFX_RectF& rtCaret, |
1558 int32_t nPageIndex, | 1546 int32_t nPageIndex, |
1559 int32_t nCaret, | 1547 int32_t nCaret, |
1560 bool bBefore) { | 1548 bool bBefore) { |
1561 IFDE_TxtEdtPage* pPage = m_PagePtrArray[m_nCaretPage]; | 1549 IFDE_TxtEdtPage* pPage = m_PagePtrArray[m_nCaretPage]; |
1562 m_Param.pEventSink->On_PageLoad(this, m_nCaretPage, 0); | 1550 m_Param.pEventSink->On_PageLoad(m_nCaretPage); |
1563 bool bCombText = !!(m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_CombText); | 1551 bool bCombText = !!(m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_CombText); |
1564 int32_t nIndexInpage = nCaret - pPage->GetCharStart(); | 1552 int32_t nIndexInpage = nCaret - pPage->GetCharStart(); |
1565 if (bBefore && bCombText && nIndexInpage > 0) { | 1553 if (bBefore && bCombText && nIndexInpage > 0) { |
1566 nIndexInpage--; | 1554 nIndexInpage--; |
1567 bBefore = false; | 1555 bBefore = false; |
1568 } | 1556 } |
1569 int32_t nBIDILevel = pPage->GetCharRect(nIndexInpage, rtCaret, bCombText); | 1557 int32_t nBIDILevel = pPage->GetCharRect(nIndexInpage, rtCaret, bCombText); |
1570 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) { | 1558 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) { |
1571 if ((!FX_IsOdd(nBIDILevel) && !bBefore) || | 1559 if ((!FX_IsOdd(nBIDILevel) && !bBefore) || |
1572 (FX_IsOdd(nBIDILevel) && bBefore)) { | 1560 (FX_IsOdd(nBIDILevel) && bBefore)) { |
1573 rtCaret.Offset(0, rtCaret.height - 1.0f); | 1561 rtCaret.Offset(0, rtCaret.height - 1.0f); |
1574 } | 1562 } |
1575 if (rtCaret.height == 0 && rtCaret.top > 1.0f) | 1563 if (rtCaret.height == 0 && rtCaret.top > 1.0f) |
1576 rtCaret.top -= 1.0f; | 1564 rtCaret.top -= 1.0f; |
1577 | 1565 |
1578 rtCaret.height = 1.0f; | 1566 rtCaret.height = 1.0f; |
1579 } else { | 1567 } else { |
1580 if ((!FX_IsOdd(nBIDILevel) && !bBefore) || | 1568 if ((!FX_IsOdd(nBIDILevel) && !bBefore) || |
1581 (FX_IsOdd(nBIDILevel) && bBefore)) { | 1569 (FX_IsOdd(nBIDILevel) && bBefore)) { |
1582 rtCaret.Offset(rtCaret.width - 1.0f, 0); | 1570 rtCaret.Offset(rtCaret.width - 1.0f, 0); |
1583 } | 1571 } |
1584 if (rtCaret.width == 0 && rtCaret.left > 1.0f) | 1572 if (rtCaret.width == 0 && rtCaret.left > 1.0f) |
1585 rtCaret.left -= 1.0f; | 1573 rtCaret.left -= 1.0f; |
1586 | 1574 |
1587 rtCaret.width = 1.0f; | 1575 rtCaret.width = 1.0f; |
1588 } | 1576 } |
1589 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); | 1577 m_Param.pEventSink->On_PageUnload(m_nCaretPage); |
1590 } | 1578 } |
1591 | 1579 |
1592 void CFDE_TxtEdtEngine::UpdateCaretIndex(const CFX_PointF& ptCaret) { | 1580 void CFDE_TxtEdtEngine::UpdateCaretIndex(const CFX_PointF& ptCaret) { |
1593 IFDE_TxtEdtPage* pPage = m_PagePtrArray[m_nCaretPage]; | 1581 IFDE_TxtEdtPage* pPage = m_PagePtrArray[m_nCaretPage]; |
1594 m_Param.pEventSink->On_PageLoad(this, m_nCaretPage, 0); | 1582 m_Param.pEventSink->On_PageLoad(m_nCaretPage); |
1595 m_nCaret = pPage->GetCharIndex(ptCaret, m_bBefore); | 1583 m_nCaret = pPage->GetCharIndex(ptCaret, m_bBefore); |
1596 GetCaretRect(m_rtCaret, m_nCaretPage, m_nCaret, m_bBefore); | 1584 GetCaretRect(m_rtCaret, m_nCaretPage, m_nCaret, m_bBefore); |
1597 if (!m_bBefore) { | 1585 if (!m_bBefore) { |
1598 m_nCaret++; | 1586 m_nCaret++; |
1599 m_bBefore = true; | 1587 m_bBefore = true; |
1600 } | 1588 } |
1601 m_Param.pEventSink->On_CaretChanged(this, m_nCaretPage); | 1589 m_Param.pEventSink->On_CaretChanged(); |
1602 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); | 1590 m_Param.pEventSink->On_PageUnload(m_nCaretPage); |
1603 } | 1591 } |
1604 | 1592 |
1605 bool CFDE_TxtEdtEngine::IsSelect() { | 1593 bool CFDE_TxtEdtEngine::IsSelect() { |
1606 return m_SelRangePtrArr.GetSize() > 0; | 1594 return m_SelRangePtrArr.GetSize() > 0; |
1607 } | 1595 } |
1608 | 1596 |
1609 void CFDE_TxtEdtEngine::DeleteSelect() { | 1597 void CFDE_TxtEdtEngine::DeleteSelect() { |
1610 int32_t nCountRange = CountSelRanges(); | 1598 int32_t nCountRange = CountSelRanges(); |
1611 if (nCountRange > 0) { | 1599 if (nCountRange > 0) { |
1612 int32_t nSelStart = 0; | 1600 int32_t nSelStart = 0; |
1613 while (nCountRange > 0) { | 1601 while (nCountRange > 0) { |
1614 int32_t nSelCount = GetSelRange(--nCountRange, nSelStart); | 1602 int32_t nSelCount = GetSelRange(--nCountRange, nSelStart); |
1615 delete m_SelRangePtrArr[nCountRange]; | 1603 delete m_SelRangePtrArr[nCountRange]; |
1616 m_SelRangePtrArr.RemoveAt(nCountRange); | 1604 m_SelRangePtrArr.RemoveAt(nCountRange); |
1617 DeleteRange_DoRecord(nSelStart, nSelCount, true); | 1605 DeleteRange_DoRecord(nSelStart, nSelCount, true); |
1618 } | 1606 } |
1619 ClearSelection(); | 1607 ClearSelection(); |
1620 m_Param.pEventSink->On_TextChanged(this, m_ChangeInfo); | 1608 m_Param.pEventSink->On_TextChanged(m_ChangeInfo); |
1621 m_Param.pEventSink->On_SelChanged(this); | 1609 m_Param.pEventSink->On_SelChanged(); |
1622 SetCaretPos(nSelStart, true); | 1610 SetCaretPos(nSelStart, true); |
1623 return; | 1611 return; |
1624 } | 1612 } |
1625 } | 1613 } |
OLD | NEW |