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/fee/fde_txtedtengine.h" | 7 #include "xfa/fee/fde_txtedtengine.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "xfa/fde/tto/fde_textout.h" | 11 #include "xfa/fde/tto/fde_textout.h" |
12 #include "xfa/fee/fde_txtedtbuf.h" | |
13 #include "xfa/fee/fde_txtedtparag.h" | 12 #include "xfa/fee/fde_txtedtparag.h" |
14 #include "xfa/fee/ifde_txtedtbuf.h" | |
15 #include "xfa/fee/ifde_txtedtengine.h" | 13 #include "xfa/fee/ifde_txtedtengine.h" |
16 #include "xfa/fee/ifde_txtedtpage.h" | 14 #include "xfa/fee/ifde_txtedtpage.h" |
| 15 #include "xfa/fwl/basewidget/fwl_editimp.h" |
17 | 16 |
18 #define FDE_PAGEWIDTH_MAX 0xFFFF | 17 #define FDE_PAGEWIDTH_MAX 0xFFFF |
19 #define FDE_TXTPLATESIZE (1024 * 12) | 18 #define FDE_TXTPLATESIZE (1024 * 12) |
20 #define FDE_UNICODE_PARAGRAPH_SPERATOR (0x2029) | 19 #define FDE_UNICODE_PARAGRAPH_SPERATOR (0x2029) |
21 #define FDE_TXTEDT_DORECORD_INS 0 | 20 #define FDE_TXTEDT_DORECORD_INS 0 |
22 #define FDE_TXTEDT_DORECORD_DEL 1 | 21 #define FDE_TXTEDT_DORECORD_DEL 1 |
23 | 22 |
24 IFDE_TxtEdtEngine* IFDE_TxtEdtEngine::Create() { | |
25 return new CFDE_TxtEdtEngine(); | |
26 } | |
27 CFDE_TxtEdtEngine::CFDE_TxtEdtEngine() | 23 CFDE_TxtEdtEngine::CFDE_TxtEdtEngine() |
28 : m_pTextBreak(nullptr), | 24 : m_pTextBreak(nullptr), |
29 m_nPageLineCount(20), | 25 m_nPageLineCount(20), |
30 m_nLineCount(0), | 26 m_nLineCount(0), |
31 m_nAnchorPos(-1), | 27 m_nAnchorPos(-1), |
32 m_nLayoutPos(0), | 28 m_nLayoutPos(0), |
33 m_fCaretPosReserve(0.0), | 29 m_fCaretPosReserve(0.0), |
34 m_nCaret(0), | 30 m_nCaret(0), |
35 m_bBefore(TRUE), | 31 m_bBefore(TRUE), |
36 m_nCaretPage(0), | 32 m_nCaretPage(0), |
(...skipping 27 matching lines...) Expand all Loading... |
64 } | 60 } |
65 void CFDE_TxtEdtEngine::SetEditParams(const FDE_TXTEDTPARAMS& params) { | 61 void CFDE_TxtEdtEngine::SetEditParams(const FDE_TXTEDTPARAMS& params) { |
66 if (!m_pTextBreak) | 62 if (!m_pTextBreak) |
67 m_pTextBreak = new CFX_TxtBreak(FX_TXTBREAKPOLICY_None); | 63 m_pTextBreak = new CFX_TxtBreak(FX_TXTBREAKPOLICY_None); |
68 | 64 |
69 FXSYS_memcpy(&m_Param, ¶ms, sizeof(FDE_TXTEDTPARAMS)); | 65 FXSYS_memcpy(&m_Param, ¶ms, sizeof(FDE_TXTEDTPARAMS)); |
70 m_wLineEnd = params.wLineBreakChar; | 66 m_wLineEnd = params.wLineBreakChar; |
71 m_bAutoLineEnd = (m_Param.nLineEnd == FDE_TXTEDIT_LINEEND_Auto); | 67 m_bAutoLineEnd = (m_Param.nLineEnd == FDE_TXTEDIT_LINEEND_Auto); |
72 UpdateTxtBreak(); | 68 UpdateTxtBreak(); |
73 } | 69 } |
74 const FDE_TXTEDTPARAMS* CFDE_TxtEdtEngine::GetEditParams() const { | 70 FDE_TXTEDTPARAMS* CFDE_TxtEdtEngine::GetEditParams() { |
75 return &m_Param; | 71 return &m_Param; |
76 } | 72 } |
77 int32_t CFDE_TxtEdtEngine::CountPages() const { | 73 int32_t CFDE_TxtEdtEngine::CountPages() const { |
78 if (m_nLineCount == 0) { | 74 if (m_nLineCount == 0) { |
79 return 0; | 75 return 0; |
80 } | 76 } |
81 return ((m_nLineCount - 1) / m_nPageLineCount) + 1; | 77 return ((m_nLineCount - 1) / m_nPageLineCount) + 1; |
82 } | 78 } |
83 IFDE_TxtEdtPage* CFDE_TxtEdtEngine::GetPage(int32_t nIndex) { | 79 IFDE_TxtEdtPage* CFDE_TxtEdtEngine::GetPage(int32_t nIndex) { |
84 if (m_PagePtrArray.GetSize() <= nIndex) { | 80 if (m_PagePtrArray.GetSize() <= nIndex) { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 CFX_WideString wsTemp; | 318 CFX_WideString wsTemp; |
323 FX_WCHAR* lpBuffer = wsTemp.GetBuffer(nLength); | 319 FX_WCHAR* lpBuffer = wsTemp.GetBuffer(nLength); |
324 FXSYS_memcpy(lpBuffer, lpText, nLength * sizeof(FX_WCHAR)); | 320 FXSYS_memcpy(lpBuffer, lpText, nLength * sizeof(FX_WCHAR)); |
325 ReplaceParagEnd(lpBuffer, nLength, FALSE); | 321 ReplaceParagEnd(lpBuffer, nLength, FALSE); |
326 wsTemp.ReleaseBuffer(nLength); | 322 wsTemp.ReleaseBuffer(nLength); |
327 FX_BOOL bPart = FALSE; | 323 FX_BOOL bPart = FALSE; |
328 if (m_nLimit > 0) { | 324 if (m_nLimit > 0) { |
329 int32_t nTotalLength = GetTextBufLength(); | 325 int32_t nTotalLength = GetTextBufLength(); |
330 int32_t nCount = m_SelRangePtrArr.GetSize(); | 326 int32_t nCount = m_SelRangePtrArr.GetSize(); |
331 for (int32_t i = 0; i < nCount; i++) { | 327 for (int32_t i = 0; i < nCount; i++) { |
332 FDE_LPTXTEDTSELRANGE lpSelRange = m_SelRangePtrArr.GetAt(i); | 328 FDE_TXTEDTSELRANGE* lpSelRange = m_SelRangePtrArr.GetAt(i); |
333 nTotalLength -= lpSelRange->nCount; | 329 nTotalLength -= lpSelRange->nCount; |
334 } | 330 } |
335 int32_t nExpectLength = nTotalLength + nLength; | 331 int32_t nExpectLength = nTotalLength + nLength; |
336 if (nTotalLength == m_nLimit) { | 332 if (nTotalLength == m_nLimit) { |
337 return FDE_TXTEDT_MODIFY_RET_F_Full; | 333 return FDE_TXTEDT_MODIFY_RET_F_Full; |
338 } | 334 } |
339 if (nExpectLength > m_nLimit) { | 335 if (nExpectLength > m_nLimit) { |
340 nLength -= (nExpectLength - m_nLimit); | 336 nLength -= (nExpectLength - m_nLimit); |
341 bPart = TRUE; | 337 bPart = TRUE; |
342 } | 338 } |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 return FDE_TXTEDT_MODIFY_RET_S_Normal; | 527 return FDE_TXTEDT_MODIFY_RET_S_Normal; |
532 } | 528 } |
533 void CFDE_TxtEdtEngine::SetLimit(int32_t nLimit) { | 529 void CFDE_TxtEdtEngine::SetLimit(int32_t nLimit) { |
534 m_nLimit = nLimit; | 530 m_nLimit = nLimit; |
535 } | 531 } |
536 void CFDE_TxtEdtEngine::SetAliasChar(FX_WCHAR wcAlias) { | 532 void CFDE_TxtEdtEngine::SetAliasChar(FX_WCHAR wcAlias) { |
537 m_wcAliasChar = wcAlias; | 533 m_wcAliasChar = wcAlias; |
538 } | 534 } |
539 | 535 |
540 void CFDE_TxtEdtEngine::RemoveSelRange(int32_t nStart, int32_t nCount) { | 536 void CFDE_TxtEdtEngine::RemoveSelRange(int32_t nStart, int32_t nCount) { |
541 FDE_LPTXTEDTSELRANGE lpTemp = NULL; | 537 FDE_TXTEDTSELRANGE* lpTemp = nullptr; |
542 int32_t nRangeCount = m_SelRangePtrArr.GetSize(); | 538 int32_t nRangeCount = m_SelRangePtrArr.GetSize(); |
543 int32_t i = 0; | 539 int32_t i = 0; |
544 for (i = 0; i < nRangeCount; i++) { | 540 for (i = 0; i < nRangeCount; i++) { |
545 lpTemp = m_SelRangePtrArr[i]; | 541 lpTemp = m_SelRangePtrArr[i]; |
546 if (lpTemp->nStart == nStart && lpTemp->nCount == nCount) { | 542 if (lpTemp->nStart == nStart && lpTemp->nCount == nCount) { |
547 delete lpTemp; | 543 delete lpTemp; |
548 m_SelRangePtrArr.RemoveAt(i); | 544 m_SelRangePtrArr.RemoveAt(i); |
549 return; | 545 return; |
550 } | 546 } |
551 } | 547 } |
552 } | 548 } |
553 | 549 |
554 void CFDE_TxtEdtEngine::AddSelRange(int32_t nStart, int32_t nCount) { | 550 void CFDE_TxtEdtEngine::AddSelRange(int32_t nStart, int32_t nCount) { |
555 if (nCount == -1) { | 551 if (nCount == -1) { |
556 nCount = GetTextLength() - nStart; | 552 nCount = GetTextLength() - nStart; |
557 } | 553 } |
558 int32_t nSize = m_SelRangePtrArr.GetSize(); | 554 int32_t nSize = m_SelRangePtrArr.GetSize(); |
559 if (nSize <= 0) { | 555 if (nSize <= 0) { |
560 FDE_LPTXTEDTSELRANGE lpSelRange = new FDE_TXTEDTSELRANGE; | 556 FDE_TXTEDTSELRANGE* lpSelRange = new FDE_TXTEDTSELRANGE; |
561 lpSelRange->nStart = nStart; | 557 lpSelRange->nStart = nStart; |
562 lpSelRange->nCount = nCount; | 558 lpSelRange->nCount = nCount; |
563 m_SelRangePtrArr.Add(lpSelRange); | 559 m_SelRangePtrArr.Add(lpSelRange); |
564 m_Param.pEventSink->On_SelChanged(this); | 560 m_Param.pEventSink->On_SelChanged(this); |
565 return; | 561 return; |
566 } | 562 } |
567 FDE_LPTXTEDTSELRANGE lpTemp = NULL; | 563 FDE_TXTEDTSELRANGE* lpTemp = nullptr; |
568 lpTemp = m_SelRangePtrArr[nSize - 1]; | 564 lpTemp = m_SelRangePtrArr[nSize - 1]; |
569 if (nStart >= lpTemp->nStart + lpTemp->nCount) { | 565 if (nStart >= lpTemp->nStart + lpTemp->nCount) { |
570 FDE_LPTXTEDTSELRANGE lpSelRange = new FDE_TXTEDTSELRANGE; | 566 FDE_TXTEDTSELRANGE* lpSelRange = new FDE_TXTEDTSELRANGE; |
571 lpSelRange->nStart = nStart; | 567 lpSelRange->nStart = nStart; |
572 lpSelRange->nCount = nCount; | 568 lpSelRange->nCount = nCount; |
573 m_SelRangePtrArr.Add(lpSelRange); | 569 m_SelRangePtrArr.Add(lpSelRange); |
574 m_Param.pEventSink->On_SelChanged(this); | 570 m_Param.pEventSink->On_SelChanged(this); |
575 return; | 571 return; |
576 } | 572 } |
577 int32_t nEnd = nStart + nCount - 1; | 573 int32_t nEnd = nStart + nCount - 1; |
578 FX_BOOL bBegin = FALSE; | 574 FX_BOOL bBegin = FALSE; |
579 int32_t nRangeBgn = 0; | 575 int32_t nRangeBgn = 0; |
580 int32_t nRangeCnt = 0; | 576 int32_t nRangeCnt = 0; |
(...skipping 14 matching lines...) Expand all Loading... |
595 nRangeBgn = i; | 591 nRangeBgn = i; |
596 if (nEnd < nTempBgn) { | 592 if (nEnd < nTempBgn) { |
597 break; | 593 break; |
598 } | 594 } |
599 nRangeCnt = 1; | 595 nRangeCnt = 1; |
600 bBegin = TRUE; | 596 bBegin = TRUE; |
601 } | 597 } |
602 } | 598 } |
603 } | 599 } |
604 if (nRangeCnt == 0) { | 600 if (nRangeCnt == 0) { |
605 FDE_LPTXTEDTSELRANGE lpSelRange = new FDE_TXTEDTSELRANGE; | 601 FDE_TXTEDTSELRANGE* lpSelRange = new FDE_TXTEDTSELRANGE; |
606 lpSelRange->nStart = nStart; | 602 lpSelRange->nStart = nStart; |
607 lpSelRange->nCount = nCount; | 603 lpSelRange->nCount = nCount; |
608 m_SelRangePtrArr.InsertAt(nRangeBgn, lpSelRange); | 604 m_SelRangePtrArr.InsertAt(nRangeBgn, lpSelRange); |
609 } else { | 605 } else { |
610 lpTemp = m_SelRangePtrArr[nRangeBgn]; | 606 lpTemp = m_SelRangePtrArr[nRangeBgn]; |
611 lpTemp->nStart = nStart; | 607 lpTemp->nStart = nStart; |
612 lpTemp->nCount = nCount; | 608 lpTemp->nCount = nCount; |
613 nRangeCnt--; | 609 nRangeCnt--; |
614 nRangeBgn++; | 610 nRangeBgn++; |
615 while (nRangeCnt--) { | 611 while (nRangeCnt--) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 m_nLineCount = 0; | 672 m_nLineCount = 0; |
677 return 0; | 673 return 0; |
678 } | 674 } |
679 int32_t CFDE_TxtEdtEngine::DoLayout(IFX_Pause* pPause) { | 675 int32_t CFDE_TxtEdtEngine::DoLayout(IFX_Pause* pPause) { |
680 int32_t nCount = m_ParagPtrArray.GetSize(); | 676 int32_t nCount = m_ParagPtrArray.GetSize(); |
681 CFDE_TxtEdtParag* pParag = NULL; | 677 CFDE_TxtEdtParag* pParag = NULL; |
682 int32_t nLineCount = 0; | 678 int32_t nLineCount = 0; |
683 for (; m_nLayoutPos < nCount; m_nLayoutPos++) { | 679 for (; m_nLayoutPos < nCount; m_nLayoutPos++) { |
684 pParag = m_ParagPtrArray[m_nLayoutPos]; | 680 pParag = m_ParagPtrArray[m_nLayoutPos]; |
685 pParag->CalcLines(); | 681 pParag->CalcLines(); |
686 nLineCount += pParag->m_nLineCount; | 682 nLineCount += pParag->GetLineCount(); |
687 if ((pPause != NULL) && (nLineCount > m_nPageLineCount) && | 683 if ((pPause != NULL) && (nLineCount > m_nPageLineCount) && |
688 pPause->NeedToPauseNow()) { | 684 pPause->NeedToPauseNow()) { |
689 m_nLineCount += nLineCount; | 685 m_nLineCount += nLineCount; |
690 return (++m_nLayoutPos * 100) / nCount; | 686 return (++m_nLayoutPos * 100) / nCount; |
691 } | 687 } |
692 } | 688 } |
693 m_nLineCount += nLineCount; | 689 m_nLineCount += nLineCount; |
694 return 100; | 690 return 100; |
695 } | 691 } |
696 void CFDE_TxtEdtEngine::EndLayout() { | 692 void CFDE_TxtEdtEngine::EndLayout() { |
697 UpdatePages(); | 693 UpdatePages(); |
698 int32_t nLength = GetTextLength(); | 694 int32_t nLength = GetTextLength(); |
699 if (m_nCaret > nLength) { | 695 if (m_nCaret > nLength) { |
700 m_nCaret = nLength; | 696 m_nCaret = nLength; |
701 } | 697 } |
702 int32_t nIndex = m_nCaret; | 698 int32_t nIndex = m_nCaret; |
703 if (!m_bBefore) { | 699 if (!m_bBefore) { |
704 nIndex--; | 700 nIndex--; |
705 } | 701 } |
706 m_rtCaret.Set(0, 0, 1, m_Param.fFontSize); | 702 m_rtCaret.Set(0, 0, 1, m_Param.fFontSize); |
707 Unlock(); | 703 Unlock(); |
708 } | 704 } |
709 FX_BOOL CFDE_TxtEdtEngine::Optimize(IFX_Pause* pPause) { | 705 FX_BOOL CFDE_TxtEdtEngine::Optimize(IFX_Pause* pPause) { |
710 return m_pTxtBuf->Optimize(pPause); | 706 return m_pTxtBuf->Optimize(pPause); |
711 } | 707 } |
712 IFDE_TxtEdtBuf* CFDE_TxtEdtEngine::GetTextBuf() const { | 708 CFDE_TxtEdtBuf* CFDE_TxtEdtEngine::GetTextBuf() const { |
713 return (IFDE_TxtEdtBuf*)m_pTxtBuf; | 709 return m_pTxtBuf; |
714 } | 710 } |
715 int32_t CFDE_TxtEdtEngine::GetTextBufLength() const { | 711 int32_t CFDE_TxtEdtEngine::GetTextBufLength() const { |
716 return m_pTxtBuf->GetTextLength() - 1; | 712 return m_pTxtBuf->GetTextLength() - 1; |
717 } | 713 } |
718 CFX_TxtBreak* CFDE_TxtEdtEngine::GetTextBreak() const { | 714 CFX_TxtBreak* CFDE_TxtEdtEngine::GetTextBreak() const { |
719 return m_pTextBreak; | 715 return m_pTextBreak; |
720 } | 716 } |
721 int32_t CFDE_TxtEdtEngine::GetLineCount() const { | 717 int32_t CFDE_TxtEdtEngine::GetLineCount() const { |
722 return m_nLineCount; | 718 return m_nLineCount; |
723 } | 719 } |
724 int32_t CFDE_TxtEdtEngine::GetPageLineCount() const { | 720 int32_t CFDE_TxtEdtEngine::GetPageLineCount() const { |
725 return m_nPageLineCount; | 721 return m_nPageLineCount; |
726 } | 722 } |
727 int32_t CFDE_TxtEdtEngine::CountParags() const { | 723 int32_t CFDE_TxtEdtEngine::CountParags() const { |
728 return m_ParagPtrArray.GetSize(); | 724 return m_ParagPtrArray.GetSize(); |
729 } | 725 } |
730 IFDE_TxtEdtParag* CFDE_TxtEdtEngine::GetParag(int32_t nParagIndex) const { | 726 CFDE_TxtEdtParag* CFDE_TxtEdtEngine::GetParag(int32_t nParagIndex) const { |
731 return m_ParagPtrArray[nParagIndex]; | 727 return m_ParagPtrArray[nParagIndex]; |
732 } | 728 } |
733 IFX_CharIter* CFDE_TxtEdtEngine::CreateCharIter() { | 729 IFX_CharIter* CFDE_TxtEdtEngine::CreateCharIter() { |
734 if (!m_pTxtBuf) { | 730 if (!m_pTxtBuf) { |
735 return NULL; | 731 return NULL; |
736 } | 732 } |
737 return new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)m_pTxtBuf); | 733 return new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)m_pTxtBuf); |
738 } | 734 } |
739 int32_t CFDE_TxtEdtEngine::Line2Parag(int32_t nStartParag, | 735 int32_t CFDE_TxtEdtEngine::Line2Parag(int32_t nStartParag, |
740 int32_t nStartLineofParag, | 736 int32_t nStartLineofParag, |
741 int32_t nLineIndex, | 737 int32_t nLineIndex, |
742 int32_t& nStartLine) const { | 738 int32_t& nStartLine) const { |
743 int32_t nLineTotal = nStartLineofParag; | 739 int32_t nLineTotal = nStartLineofParag; |
744 int32_t nCount = m_ParagPtrArray.GetSize(); | 740 int32_t nCount = m_ParagPtrArray.GetSize(); |
745 CFDE_TxtEdtParag* pParag = NULL; | 741 CFDE_TxtEdtParag* pParag = NULL; |
746 int32_t i = nStartParag; | 742 int32_t i = nStartParag; |
747 for (; i < nCount; i++) { | 743 for (; i < nCount; i++) { |
748 pParag = m_ParagPtrArray[i]; | 744 pParag = m_ParagPtrArray[i]; |
749 nLineTotal += pParag->m_nLineCount; | 745 nLineTotal += pParag->GetLineCount(); |
750 if (nLineTotal > nLineIndex) { | 746 if (nLineTotal > nLineIndex) { |
751 break; | 747 break; |
752 } | 748 } |
753 } | 749 } |
754 nStartLine = nLineTotal - pParag->m_nLineCount; | 750 nStartLine = nLineTotal - pParag->GetLineCount(); |
755 return i; | 751 return i; |
756 } | 752 } |
757 void CFDE_TxtEdtEngine::GetPreDeleteText(CFX_WideString& wsText, | 753 void CFDE_TxtEdtEngine::GetPreDeleteText(CFX_WideString& wsText, |
758 int32_t nIndex, | 754 int32_t nIndex, |
759 int32_t nLength) { | 755 int32_t nLength) { |
760 GetText(wsText, 0, GetTextBufLength()); | 756 GetText(wsText, 0, GetTextBufLength()); |
761 wsText.Delete(nIndex, nLength); | 757 wsText.Delete(nIndex, nLength); |
762 } | 758 } |
763 void CFDE_TxtEdtEngine::GetPreInsertText(CFX_WideString& wsText, | 759 void CFDE_TxtEdtEngine::GetPreInsertText(CFX_WideString& wsText, |
764 int32_t nIndex, | 760 int32_t nIndex, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 } | 801 } |
806 void CFDE_TxtEdtEngine::Inner_Insert(int32_t nStart, | 802 void CFDE_TxtEdtEngine::Inner_Insert(int32_t nStart, |
807 const FX_WCHAR* lpText, | 803 const FX_WCHAR* lpText, |
808 int32_t nLength) { | 804 int32_t nLength) { |
809 ASSERT(nLength > 0); | 805 ASSERT(nLength > 0); |
810 FDE_TXTEDTPARAGPOS ParagPos; | 806 FDE_TXTEDTPARAGPOS ParagPos; |
811 TextPos2ParagPos(nStart, ParagPos); | 807 TextPos2ParagPos(nStart, ParagPos); |
812 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); | 808 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); |
813 int32_t nParagCount = m_ParagPtrArray.GetSize(); | 809 int32_t nParagCount = m_ParagPtrArray.GetSize(); |
814 int32_t i = 0; | 810 int32_t i = 0; |
815 for (i = ParagPos.nParagIndex + 1; i < nParagCount; i++) { | 811 for (i = ParagPos.nParagIndex + 1; i < nParagCount; i++) |
816 m_ParagPtrArray[i]->m_nCharStart += nLength; | 812 m_ParagPtrArray[i]->IncrementStartIndex(nLength); |
817 } | 813 |
818 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex]; | 814 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex]; |
819 int32_t nReserveLineCount = pParag->m_nLineCount; | 815 int32_t nReserveLineCount = pParag->GetLineCount(); |
820 int32_t nReserveCharStart = pParag->m_nCharStart; | 816 int32_t nReserveCharStart = pParag->GetStartIndex(); |
821 int32_t nLeavePart = ParagPos.nCharIndex; | 817 int32_t nLeavePart = ParagPos.nCharIndex; |
822 int32_t nCutPart = pParag->m_nCharCount - ParagPos.nCharIndex; | 818 int32_t nCutPart = pParag->GetTextLength() - ParagPos.nCharIndex; |
823 int32_t nTextStart = 0; | 819 int32_t nTextStart = 0; |
824 FX_WCHAR wCurChar = L' '; | 820 FX_WCHAR wCurChar = L' '; |
825 const FX_WCHAR* lpPos = lpText; | 821 const FX_WCHAR* lpPos = lpText; |
826 FX_BOOL bFirst = TRUE; | 822 FX_BOOL bFirst = TRUE; |
827 int32_t nParagIndex = ParagPos.nParagIndex; | 823 int32_t nParagIndex = ParagPos.nParagIndex; |
828 for (i = 0; i < nLength; i++, lpPos++) { | 824 for (i = 0; i < nLength; i++, lpPos++) { |
829 wCurChar = *lpPos; | 825 wCurChar = *lpPos; |
830 if (wCurChar == m_wLineEnd) { | 826 if (wCurChar == m_wLineEnd) { |
831 if (bFirst) { | 827 if (bFirst) { |
832 pParag->m_nCharCount = nLeavePart + (i - nTextStart + 1); | 828 pParag->SetTextLength(nLeavePart + (i - nTextStart + 1)); |
833 pParag->m_nLineCount = -1; | 829 pParag->SetLineCount(-1); |
834 nReserveCharStart += pParag->m_nCharCount; | 830 nReserveCharStart += pParag->GetTextLength(); |
835 bFirst = FALSE; | 831 bFirst = FALSE; |
836 } else { | 832 } else { |
837 pParag = new CFDE_TxtEdtParag(this); | 833 pParag = new CFDE_TxtEdtParag(this); |
838 pParag->m_nLineCount = -1; | 834 pParag->SetLineCount(-1); |
839 pParag->m_nCharCount = i - nTextStart + 1; | 835 pParag->SetTextLength(i - nTextStart + 1); |
840 pParag->m_nCharStart = nReserveCharStart; | 836 pParag->SetStartIndex(nReserveCharStart); |
841 m_ParagPtrArray.InsertAt(++nParagIndex, pParag); | 837 m_ParagPtrArray.InsertAt(++nParagIndex, pParag); |
842 nReserveCharStart += pParag->m_nCharCount; | 838 nReserveCharStart += pParag->GetTextLength(); |
843 } | 839 } |
844 nTextStart = i + 1; | 840 nTextStart = i + 1; |
845 } | 841 } |
846 } | 842 } |
847 if (bFirst) { | 843 if (bFirst) { |
848 pParag->m_nCharCount += nLength; | 844 pParag->IncrementTextLength(nLength); |
849 pParag->m_nLineCount = -1; | 845 pParag->SetLineCount(-1); |
850 bFirst = FALSE; | 846 bFirst = FALSE; |
851 } else { | 847 } else { |
852 pParag = new CFDE_TxtEdtParag(this); | 848 pParag = new CFDE_TxtEdtParag(this); |
853 pParag->m_nLineCount = -1; | 849 pParag->SetLineCount(-1); |
854 pParag->m_nCharCount = nLength - nTextStart + nCutPart; | 850 pParag->SetTextLength(nLength - nTextStart + nCutPart); |
855 pParag->m_nCharStart = nReserveCharStart; | 851 pParag->SetStartIndex(nReserveCharStart); |
856 m_ParagPtrArray.InsertAt(++nParagIndex, pParag); | 852 m_ParagPtrArray.InsertAt(++nParagIndex, pParag); |
857 } | 853 } |
858 m_pTxtBuf->Insert(nStart, lpText, nLength); | 854 m_pTxtBuf->Insert(nStart, lpText, nLength); |
859 int32_t nTotalLineCount = 0; | 855 int32_t nTotalLineCount = 0; |
860 for (i = ParagPos.nParagIndex; i <= nParagIndex; i++) { | 856 for (i = ParagPos.nParagIndex; i <= nParagIndex; i++) { |
861 pParag = m_ParagPtrArray[i]; | 857 pParag = m_ParagPtrArray[i]; |
862 pParag->CalcLines(); | 858 pParag->CalcLines(); |
863 nTotalLineCount += pParag->m_nLineCount; | 859 nTotalLineCount += pParag->GetLineCount(); |
864 } | 860 } |
865 m_nLineCount += nTotalLineCount - nReserveLineCount; | 861 m_nLineCount += nTotalLineCount - nReserveLineCount; |
866 m_Param.pEventSink->On_PageLoad(this, m_nCaretPage, 0); | 862 m_Param.pEventSink->On_PageLoad(this, m_nCaretPage, 0); |
867 UpdatePages(); | 863 UpdatePages(); |
868 } | 864 } |
869 | 865 |
870 void CFDE_TxtEdtEngine::Inner_DeleteRange(int32_t nStart, int32_t nCount) { | 866 void CFDE_TxtEdtEngine::Inner_DeleteRange(int32_t nStart, int32_t nCount) { |
871 if (nCount == -1) { | 867 if (nCount == -1) { |
872 nCount = m_pTxtBuf->GetTextLength() - nStart; | 868 nCount = m_pTxtBuf->GetTextLength() - nStart; |
873 } | 869 } |
874 int32_t nEnd = nStart + nCount - 1; | 870 int32_t nEnd = nStart + nCount - 1; |
875 ASSERT(nStart >= 0 && nEnd < m_pTxtBuf->GetTextLength()); | 871 ASSERT(nStart >= 0 && nEnd < m_pTxtBuf->GetTextLength()); |
876 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); | 872 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); |
877 FDE_TXTEDTPARAGPOS ParagPosBgn, ParagPosEnd; | 873 FDE_TXTEDTPARAGPOS ParagPosBgn, ParagPosEnd; |
878 TextPos2ParagPos(nStart, ParagPosBgn); | 874 TextPos2ParagPos(nStart, ParagPosBgn); |
879 TextPos2ParagPos(nEnd, ParagPosEnd); | 875 TextPos2ParagPos(nEnd, ParagPosEnd); |
880 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPosEnd.nParagIndex]; | 876 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPosEnd.nParagIndex]; |
881 FX_BOOL bLastParag = FALSE; | 877 FX_BOOL bLastParag = FALSE; |
882 if (ParagPosEnd.nCharIndex == pParag->m_nCharCount - 1) { | 878 if (ParagPosEnd.nCharIndex == pParag->GetTextLength() - 1) { |
883 if (ParagPosEnd.nParagIndex < m_ParagPtrArray.GetSize() - 1) { | 879 if (ParagPosEnd.nParagIndex < m_ParagPtrArray.GetSize() - 1) { |
884 ParagPosEnd.nParagIndex++; | 880 ParagPosEnd.nParagIndex++; |
885 } else { | 881 } else { |
886 bLastParag = TRUE; | 882 bLastParag = TRUE; |
887 } | 883 } |
888 } | 884 } |
889 int32_t nTotalLineCount = 0; | 885 int32_t nTotalLineCount = 0; |
890 int32_t nTotalCharCount = 0; | 886 int32_t nTotalCharCount = 0; |
891 int32_t i = 0; | 887 int32_t i = 0; |
892 for (i = ParagPosBgn.nParagIndex; i <= ParagPosEnd.nParagIndex; i++) { | 888 for (i = ParagPosBgn.nParagIndex; i <= ParagPosEnd.nParagIndex; i++) { |
893 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[i]; | 889 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[i]; |
894 pParag->CalcLines(); | 890 pParag->CalcLines(); |
895 nTotalLineCount += pParag->m_nLineCount; | 891 nTotalLineCount += pParag->GetLineCount(); |
896 nTotalCharCount += pParag->m_nCharCount; | 892 nTotalCharCount += pParag->GetTextLength(); |
897 } | 893 } |
898 m_pTxtBuf->Delete(nStart, nCount); | 894 m_pTxtBuf->Delete(nStart, nCount); |
899 int32_t nNextParagIndex = (ParagPosBgn.nCharIndex == 0 && bLastParag) | 895 int32_t nNextParagIndex = (ParagPosBgn.nCharIndex == 0 && bLastParag) |
900 ? ParagPosBgn.nParagIndex | 896 ? ParagPosBgn.nParagIndex |
901 : (ParagPosBgn.nParagIndex + 1); | 897 : (ParagPosBgn.nParagIndex + 1); |
902 for (i = nNextParagIndex; i <= ParagPosEnd.nParagIndex; i++) { | 898 for (i = nNextParagIndex; i <= ParagPosEnd.nParagIndex; i++) { |
903 delete m_ParagPtrArray[nNextParagIndex]; | 899 delete m_ParagPtrArray[nNextParagIndex]; |
904 m_ParagPtrArray.RemoveAt(nNextParagIndex); | 900 m_ParagPtrArray.RemoveAt(nNextParagIndex); |
905 } | 901 } |
906 if (!(bLastParag && ParagPosBgn.nCharIndex == 0)) { | 902 if (!(bLastParag && ParagPosBgn.nCharIndex == 0)) { |
907 pParag = m_ParagPtrArray[ParagPosBgn.nParagIndex]; | 903 pParag = m_ParagPtrArray[ParagPosBgn.nParagIndex]; |
908 pParag->m_nCharCount = nTotalCharCount - nCount; | 904 pParag->SetTextLength(nTotalCharCount - nCount); |
909 pParag->CalcLines(); | 905 pParag->CalcLines(); |
910 nTotalLineCount -= pParag->m_nLineCount; | 906 nTotalLineCount -= pParag->GetTextLength(); |
911 } | 907 } |
912 int32_t nParagCount = m_ParagPtrArray.GetSize(); | 908 int32_t nParagCount = m_ParagPtrArray.GetSize(); |
913 for (i = nNextParagIndex; i < nParagCount; i++) { | 909 for (i = nNextParagIndex; i < nParagCount; i++) |
914 m_ParagPtrArray[i]->m_nCharStart -= nCount; | 910 m_ParagPtrArray[i]->DecrementStartIndex(nCount); |
915 } | 911 |
916 m_nLineCount -= nTotalLineCount; | 912 m_nLineCount -= nTotalLineCount; |
917 UpdatePages(); | 913 UpdatePages(); |
918 int32_t nPageCount = CountPages(); | 914 int32_t nPageCount = CountPages(); |
919 if (m_nCaretPage >= nPageCount) { | 915 if (m_nCaretPage >= nPageCount) { |
920 m_nCaretPage = nPageCount - 1; | 916 m_nCaretPage = nPageCount - 1; |
921 } | 917 } |
922 m_Param.pEventSink->On_PageLoad(this, m_nCaretPage, 0); | 918 m_Param.pEventSink->On_PageLoad(this, m_nCaretPage, 0); |
923 } | 919 } |
924 void CFDE_TxtEdtEngine::DeleteRange_DoRecord(int32_t nStart, | 920 void CFDE_TxtEdtEngine::DeleteRange_DoRecord(int32_t nStart, |
925 int32_t nCount, | 921 int32_t nCount, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 FX_WCHAR wChar = L' '; | 953 FX_WCHAR wChar = L' '; |
958 int32_t nParagStart = 0; | 954 int32_t nParagStart = 0; |
959 int32_t nIndex = 0; | 955 int32_t nIndex = 0; |
960 IFX_CharIter* pIter = new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)m_pTxtBuf); | 956 IFX_CharIter* pIter = new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)m_pTxtBuf); |
961 pIter->SetAt(0); | 957 pIter->SetAt(0); |
962 do { | 958 do { |
963 wChar = pIter->GetChar(); | 959 wChar = pIter->GetChar(); |
964 nIndex = pIter->GetAt(); | 960 nIndex = pIter->GetAt(); |
965 if (wChar == m_wLineEnd) { | 961 if (wChar == m_wLineEnd) { |
966 CFDE_TxtEdtParag* pParag = new CFDE_TxtEdtParag(this); | 962 CFDE_TxtEdtParag* pParag = new CFDE_TxtEdtParag(this); |
967 pParag->m_nCharStart = nParagStart; | 963 pParag->SetStartIndex(nParagStart); |
968 pParag->m_nCharCount = nIndex - nParagStart + 1; | 964 pParag->SetTextLength(nIndex - nParagStart + 1); |
969 pParag->m_nLineCount = -1; | 965 pParag->SetLineCount(-1); |
970 m_ParagPtrArray.Add(pParag); | 966 m_ParagPtrArray.Add(pParag); |
971 nParagStart = nIndex + 1; | 967 nParagStart = nIndex + 1; |
972 } | 968 } |
973 } while (pIter->Next()); | 969 } while (pIter->Next()); |
974 pIter->Release(); | 970 pIter->Release(); |
975 } | 971 } |
976 | 972 |
977 void CFDE_TxtEdtEngine::RemoveAllParags() { | 973 void CFDE_TxtEdtEngine::RemoveAllParags() { |
978 int32_t nCount = m_ParagPtrArray.GetSize(); | 974 int32_t nCount = m_ParagPtrArray.GetSize(); |
979 for (int i = 0; i < nCount; ++i) | 975 for (int i = 0; i < nCount; ++i) |
(...skipping 15 matching lines...) Expand all Loading... |
995 void CFDE_TxtEdtEngine::UpdateParags() { | 991 void CFDE_TxtEdtEngine::UpdateParags() { |
996 int32_t nCount = m_ParagPtrArray.GetSize(); | 992 int32_t nCount = m_ParagPtrArray.GetSize(); |
997 if (nCount == 0) { | 993 if (nCount == 0) { |
998 return; | 994 return; |
999 } | 995 } |
1000 CFDE_TxtEdtParag* pParag = NULL; | 996 CFDE_TxtEdtParag* pParag = NULL; |
1001 int32_t nLineCount = 0; | 997 int32_t nLineCount = 0; |
1002 int32_t i = 0; | 998 int32_t i = 0; |
1003 for (i = 0; i < nCount; i++) { | 999 for (i = 0; i < nCount; i++) { |
1004 pParag = m_ParagPtrArray[i]; | 1000 pParag = m_ParagPtrArray[i]; |
1005 if (pParag->m_nLineCount == -1) { | 1001 if (pParag->GetLineCount() == -1) |
1006 pParag->CalcLines(); | 1002 pParag->CalcLines(); |
1007 } | 1003 |
1008 nLineCount += pParag->m_nLineCount; | 1004 nLineCount += pParag->GetLineCount(); |
1009 } | 1005 } |
1010 m_nLineCount = nLineCount; | 1006 m_nLineCount = nLineCount; |
1011 } | 1007 } |
1012 void CFDE_TxtEdtEngine::UpdatePages() { | 1008 void CFDE_TxtEdtEngine::UpdatePages() { |
1013 if (m_nLineCount == 0) { | 1009 if (m_nLineCount == 0) |
1014 return; | 1010 return; |
1015 } | 1011 |
1016 int32_t nPageCount = (m_nLineCount - 1) / (m_nPageLineCount) + 1; | 1012 int32_t nPageCount = (m_nLineCount - 1) / (m_nPageLineCount) + 1; |
1017 int32_t nSize = m_PagePtrArray.GetSize(); | 1013 int32_t nSize = m_PagePtrArray.GetSize(); |
1018 if (nSize == nPageCount) { | 1014 if (nSize == nPageCount) |
1019 return; | 1015 return; |
1020 } | 1016 |
1021 if (nSize > nPageCount) { | 1017 if (nSize > nPageCount) { |
1022 IFDE_TxtEdtPage* pPage = NULL; | 1018 IFDE_TxtEdtPage* pPage = NULL; |
1023 int32_t i = 0; | 1019 int32_t i = 0; |
1024 for (i = nSize - 1; i >= nPageCount; i--) { | 1020 for (i = nSize - 1; i >= nPageCount; i--) { |
1025 pPage = m_PagePtrArray[i]; | 1021 pPage = m_PagePtrArray[i]; |
1026 if (pPage) { | 1022 if (pPage) { |
1027 pPage->Release(); | 1023 pPage->Release(); |
1028 } | 1024 } |
1029 m_PagePtrArray.RemoveAt(i); | 1025 m_PagePtrArray.RemoveAt(i); |
1030 } | 1026 } |
1031 m_Param.pEventSink->On_PageCountChanged(this); | |
1032 return; | 1027 return; |
1033 } | 1028 } |
1034 if (nSize < nPageCount) { | 1029 if (nSize < nPageCount) { |
1035 IFDE_TxtEdtPage* pPage = NULL; | 1030 IFDE_TxtEdtPage* pPage = NULL; |
1036 int32_t i = 0; | 1031 int32_t i = 0; |
1037 for (i = nSize; i < nPageCount; i++) { | 1032 for (i = nSize; i < nPageCount; i++) { |
1038 pPage = IFDE_TxtEdtPage::Create(this, i); | 1033 pPage = IFDE_TxtEdtPage::Create(this, i); |
1039 m_PagePtrArray.Add(pPage); | 1034 m_PagePtrArray.Add(pPage); |
1040 } | 1035 } |
1041 m_Param.pEventSink->On_PageCountChanged(this); | |
1042 return; | 1036 return; |
1043 } | 1037 } |
1044 } | 1038 } |
1045 void CFDE_TxtEdtEngine::UpdateTxtBreak() { | 1039 void CFDE_TxtEdtEngine::UpdateTxtBreak() { |
1046 uint32_t dwStyle = m_pTextBreak->GetLayoutStyles(); | 1040 uint32_t dwStyle = m_pTextBreak->GetLayoutStyles(); |
1047 if (m_Param.dwMode & FDE_TEXTEDITMODE_MultiLines) { | 1041 if (m_Param.dwMode & FDE_TEXTEDITMODE_MultiLines) { |
1048 dwStyle &= ~FX_TXTLAYOUTSTYLE_SingleLine; | 1042 dwStyle &= ~FX_TXTLAYOUTSTYLE_SingleLine; |
1049 } else { | 1043 } else { |
1050 dwStyle |= FX_TXTLAYOUTSTYLE_SingleLine; | 1044 dwStyle |= FX_TXTLAYOUTSTYLE_SingleLine; |
1051 } | 1045 } |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 return m_nCaretPage; | 1231 return m_nCaretPage; |
1238 } | 1232 } |
1239 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); | 1233 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); |
1240 } | 1234 } |
1241 CFDE_TxtEdtParag* pParag = NULL; | 1235 CFDE_TxtEdtParag* pParag = NULL; |
1242 int32_t nLineCount = 0; | 1236 int32_t nLineCount = 0; |
1243 int32_t nParagCount = m_ParagPtrArray.GetSize(); | 1237 int32_t nParagCount = m_ParagPtrArray.GetSize(); |
1244 int32_t i = 0; | 1238 int32_t i = 0; |
1245 for (i = 0; i < nParagCount; i++) { | 1239 for (i = 0; i < nParagCount; i++) { |
1246 pParag = m_ParagPtrArray[i]; | 1240 pParag = m_ParagPtrArray[i]; |
1247 if (pParag->m_nCharStart <= nIndex && | 1241 if (pParag->GetStartIndex() <= nIndex && |
1248 nIndex < (pParag->m_nCharStart + pParag->m_nCharCount)) { | 1242 nIndex < (pParag->GetStartIndex() + pParag->GetTextLength())) { |
1249 break; | 1243 break; |
1250 } | 1244 } |
1251 nLineCount += pParag->m_nLineCount; | 1245 nLineCount += pParag->GetLineCount(); |
1252 } | 1246 } |
1253 pParag->LoadParag(); | 1247 pParag->LoadParag(); |
1254 int32_t nLineStart = -1; | 1248 int32_t nLineStart = -1; |
1255 int32_t nLineCharCount = -1; | 1249 int32_t nLineCharCount = -1; |
1256 for (i = 0; i < pParag->m_nLineCount; i++) { | 1250 for (i = 0; i < pParag->GetLineCount(); i++) { |
1257 pParag->GetLineRange(i, nLineStart, nLineCharCount); | 1251 pParag->GetLineRange(i, nLineStart, nLineCharCount); |
1258 if (nLineStart <= nIndex && nIndex < (nLineStart + nLineCharCount)) { | 1252 if (nLineStart <= nIndex && nIndex < (nLineStart + nLineCharCount)) { |
1259 break; | 1253 break; |
1260 } | 1254 } |
1261 } | 1255 } |
1262 ASSERT(i < pParag->m_nLineCount); | 1256 ASSERT(i < pParag->GetLineCount()); |
1263 nLineCount += (i + 1); | 1257 nLineCount += (i + 1); |
1264 m_nCaretPage = (nLineCount - 1) / m_nPageLineCount + 1 - 1; | 1258 m_nCaretPage = (nLineCount - 1) / m_nPageLineCount + 1 - 1; |
1265 m_Param.pEventSink->On_PageChange(this, m_nCaretPage); | |
1266 pParag->UnloadParag(); | 1259 pParag->UnloadParag(); |
1267 return m_nCaretPage; | 1260 return m_nCaretPage; |
1268 } | 1261 } |
1269 void CFDE_TxtEdtEngine::TextPos2ParagPos(int32_t nIndex, | 1262 void CFDE_TxtEdtEngine::TextPos2ParagPos(int32_t nIndex, |
1270 FDE_TXTEDTPARAGPOS& ParagPos) const { | 1263 FDE_TXTEDTPARAGPOS& ParagPos) const { |
1271 ASSERT(nIndex >= 0 && nIndex < m_pTxtBuf->GetTextLength()); | 1264 ASSERT(nIndex >= 0 && nIndex < m_pTxtBuf->GetTextLength()); |
1272 int32_t nCount = m_ParagPtrArray.GetSize(); | 1265 int32_t nCount = m_ParagPtrArray.GetSize(); |
1273 int32_t nBgn = 0; | 1266 int32_t nBgn = 0; |
1274 int32_t nMid = 0; | 1267 int32_t nMid = 0; |
1275 int32_t nEnd = nCount - 1; | 1268 int32_t nEnd = nCount - 1; |
1276 while (nEnd > nBgn) { | 1269 while (nEnd > nBgn) { |
1277 nMid = (nBgn + nEnd) / 2; | 1270 nMid = (nBgn + nEnd) / 2; |
1278 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[nMid]; | 1271 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[nMid]; |
1279 if (nIndex < pParag->m_nCharStart) { | 1272 if (nIndex < pParag->GetStartIndex()) { |
1280 nEnd = nMid - 1; | 1273 nEnd = nMid - 1; |
1281 } else if (nIndex >= (pParag->m_nCharStart + pParag->m_nCharCount)) { | 1274 } else if (nIndex >= (pParag->GetStartIndex() + pParag->GetTextLength())) { |
1282 nBgn = nMid + 1; | 1275 nBgn = nMid + 1; |
1283 } else { | 1276 } else { |
1284 break; | 1277 break; |
1285 } | 1278 } |
1286 } | 1279 } |
1287 if (nBgn == nEnd) { | 1280 if (nBgn == nEnd) { |
1288 nMid = nBgn; | 1281 nMid = nBgn; |
1289 } | 1282 } |
1290 ASSERT(nIndex >= m_ParagPtrArray[nMid]->m_nCharStart && | 1283 ASSERT(nIndex >= m_ParagPtrArray[nMid]->GetStartIndex() && |
1291 (nIndex < m_ParagPtrArray[nMid]->m_nCharStart + | 1284 (nIndex < m_ParagPtrArray[nMid]->GetStartIndex() + |
1292 m_ParagPtrArray[nMid]->m_nCharCount)); | 1285 m_ParagPtrArray[nMid]->GetTextLength())); |
1293 ParagPos.nParagIndex = nMid; | 1286 ParagPos.nParagIndex = nMid; |
1294 ParagPos.nCharIndex = nIndex - m_ParagPtrArray[nMid]->m_nCharStart; | 1287 ParagPos.nCharIndex = nIndex - m_ParagPtrArray[nMid]->GetStartIndex(); |
1295 } | 1288 } |
1296 int32_t CFDE_TxtEdtEngine::MoveForward(FX_BOOL& bBefore) { | 1289 int32_t CFDE_TxtEdtEngine::MoveForward(FX_BOOL& bBefore) { |
1297 if (m_nCaret == m_pTxtBuf->GetTextLength() - 1) { | 1290 if (m_nCaret == m_pTxtBuf->GetTextLength() - 1) { |
1298 return -1; | 1291 return -1; |
1299 } | 1292 } |
1300 int32_t nCaret = m_nCaret; | 1293 int32_t nCaret = m_nCaret; |
1301 if ((nCaret + 1 < m_pTxtBuf->GetTextLength()) && | 1294 if ((nCaret + 1 < m_pTxtBuf->GetTextLength()) && |
1302 (m_pTxtBuf->GetCharByIndex(nCaret) == L'\r') && | 1295 (m_pTxtBuf->GetCharByIndex(nCaret) == L'\r') && |
1303 (m_pTxtBuf->GetCharByIndex(nCaret + 1) == L'\n')) { | 1296 (m_pTxtBuf->GetCharByIndex(nCaret + 1) == L'\n')) { |
1304 nCaret++; | 1297 nCaret++; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 } else { | 1329 } else { |
1337 if (m_nCaretPage == 0) { | 1330 if (m_nCaretPage == 0) { |
1338 return FALSE; | 1331 return FALSE; |
1339 } | 1332 } |
1340 } | 1333 } |
1341 if (bLineReserve) { | 1334 if (bLineReserve) { |
1342 m_nCaretPage++; | 1335 m_nCaretPage++; |
1343 } else { | 1336 } else { |
1344 m_nCaretPage--; | 1337 m_nCaretPage--; |
1345 } | 1338 } |
1346 m_Param.pEventSink->On_PageChange(this, m_nCaretPage); | |
1347 ptCaret.x -= rtContent.left; | 1339 ptCaret.x -= rtContent.left; |
1348 IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage); | 1340 IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage); |
1349 ptCaret.x += pCurPage->GetContentsBox().right(); | 1341 ptCaret.x += pCurPage->GetContentsBox().right(); |
1350 } | 1342 } |
1351 } else { | 1343 } else { |
1352 ptCaret.x = m_fCaretPosReserve; | 1344 ptCaret.x = m_fCaretPosReserve; |
1353 ptCaret.y = m_rtCaret.top + m_rtCaret.height / 2 - m_Param.fLineSpace; | 1345 ptCaret.y = m_rtCaret.top + m_rtCaret.height / 2 - m_Param.fLineSpace; |
1354 if (ptCaret.y < rtContent.top) { | 1346 if (ptCaret.y < rtContent.top) { |
1355 if (m_nCaretPage == 0) { | 1347 if (m_nCaretPage == 0) { |
1356 return FALSE; | 1348 return FALSE; |
1357 } | 1349 } |
1358 ptCaret.y -= rtContent.top; | 1350 ptCaret.y -= rtContent.top; |
1359 m_nCaretPage--; | 1351 m_nCaretPage--; |
1360 m_Param.pEventSink->On_PageChange(this, m_nCaretPage); | |
1361 IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage); | 1352 IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage); |
1362 ptCaret.y += pCurPage->GetContentsBox().bottom(); | 1353 ptCaret.y += pCurPage->GetContentsBox().bottom(); |
1363 } | 1354 } |
1364 } | 1355 } |
1365 return TRUE; | 1356 return TRUE; |
1366 } | 1357 } |
1367 FX_BOOL CFDE_TxtEdtEngine::MoveDown(CFX_PointF& ptCaret) { | 1358 FX_BOOL CFDE_TxtEdtEngine::MoveDown(CFX_PointF& ptCaret) { |
1368 IFDE_TxtEdtPage* pPage = GetPage(m_nCaretPage); | 1359 IFDE_TxtEdtPage* pPage = GetPage(m_nCaretPage); |
1369 const CFX_RectF& rtContent = pPage->GetContentsBox(); | 1360 const CFX_RectF& rtContent = pPage->GetContentsBox(); |
1370 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) { | 1361 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) { |
1371 ptCaret.x = m_rtCaret.left + m_rtCaret.width / 2 + m_Param.fLineSpace; | 1362 ptCaret.x = m_rtCaret.left + m_rtCaret.width / 2 + m_Param.fLineSpace; |
1372 ptCaret.y = m_fCaretPosReserve; | 1363 ptCaret.y = m_fCaretPosReserve; |
1373 if (ptCaret.x >= rtContent.right()) { | 1364 if (ptCaret.x >= rtContent.right()) { |
1374 FX_BOOL bLineReserve = | 1365 FX_BOOL bLineReserve = |
1375 m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_LineReserve; | 1366 m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_LineReserve; |
1376 if (bLineReserve) { | 1367 if (bLineReserve) { |
1377 if (m_nCaretPage == 0) { | 1368 if (m_nCaretPage == 0) { |
1378 return FALSE; | 1369 return FALSE; |
1379 } | 1370 } |
1380 } else { | 1371 } else { |
1381 if (m_nCaretPage == CountPages() - 1) { | 1372 if (m_nCaretPage == CountPages() - 1) { |
1382 return FALSE; | 1373 return FALSE; |
1383 } | 1374 } |
1384 } | 1375 } |
1385 if (bLineReserve) { | 1376 if (bLineReserve) { |
1386 m_nCaretPage--; | 1377 m_nCaretPage--; |
1387 } else { | 1378 } else { |
1388 m_nCaretPage++; | 1379 m_nCaretPage++; |
1389 } | 1380 } |
1390 m_Param.pEventSink->On_PageChange(this, m_nCaretPage); | |
1391 ptCaret.x -= rtContent.right(); | 1381 ptCaret.x -= rtContent.right(); |
1392 IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage); | 1382 IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage); |
1393 ptCaret.x += pCurPage->GetContentsBox().left; | 1383 ptCaret.x += pCurPage->GetContentsBox().left; |
1394 } | 1384 } |
1395 } else { | 1385 } else { |
1396 ptCaret.x = m_fCaretPosReserve; | 1386 ptCaret.x = m_fCaretPosReserve; |
1397 ptCaret.y = m_rtCaret.top + m_rtCaret.height / 2 + m_Param.fLineSpace; | 1387 ptCaret.y = m_rtCaret.top + m_rtCaret.height / 2 + m_Param.fLineSpace; |
1398 if (ptCaret.y >= rtContent.bottom()) { | 1388 if (ptCaret.y >= rtContent.bottom()) { |
1399 if (m_nCaretPage == CountPages() - 1) { | 1389 if (m_nCaretPage == CountPages() - 1) { |
1400 return FALSE; | 1390 return FALSE; |
1401 } | 1391 } |
1402 ptCaret.y -= rtContent.bottom(); | 1392 ptCaret.y -= rtContent.bottom(); |
1403 m_nCaretPage++; | 1393 m_nCaretPage++; |
1404 m_Param.pEventSink->On_PageChange(this, m_nCaretPage); | |
1405 IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage); | 1394 IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage); |
1406 ptCaret.y += pCurPage->GetContentsBox().top; | 1395 ptCaret.y += pCurPage->GetContentsBox().top; |
1407 } | 1396 } |
1408 } | 1397 } |
1409 return TRUE; | 1398 return TRUE; |
1410 } | 1399 } |
1411 FX_BOOL CFDE_TxtEdtEngine::MoveLineStart() { | 1400 FX_BOOL CFDE_TxtEdtEngine::MoveLineStart() { |
1412 int32_t nIndex = m_bBefore ? m_nCaret : m_nCaret - 1; | 1401 int32_t nIndex = m_bBefore ? m_nCaret : m_nCaret - 1; |
1413 FDE_TXTEDTPARAGPOS ParagPos; | 1402 FDE_TXTEDTPARAGPOS ParagPos; |
1414 TextPos2ParagPos(nIndex, ParagPos); | 1403 TextPos2ParagPos(nIndex, ParagPos); |
1415 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex]; | 1404 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex]; |
1416 pParag->LoadParag(); | 1405 pParag->LoadParag(); |
1417 int32_t nLineCount = pParag->m_nLineCount; | 1406 int32_t nLineCount = pParag->GetLineCount(); |
1418 int32_t i = 0; | 1407 int32_t i = 0; |
1419 int32_t nStart = 0; | 1408 int32_t nStart = 0; |
1420 int32_t nCount = 0; | 1409 int32_t nCount = 0; |
1421 for (; i < nLineCount; i++) { | 1410 for (; i < nLineCount; i++) { |
1422 pParag->GetLineRange(i, nStart, nCount); | 1411 pParag->GetLineRange(i, nStart, nCount); |
1423 if (nIndex >= nStart && nIndex < nStart + nCount) { | 1412 if (nIndex >= nStart && nIndex < nStart + nCount) { |
1424 break; | 1413 break; |
1425 } | 1414 } |
1426 } | 1415 } |
1427 UpdateCaretRect(nStart, TRUE); | 1416 UpdateCaretRect(nStart, TRUE); |
1428 pParag->UnloadParag(); | 1417 pParag->UnloadParag(); |
1429 return TRUE; | 1418 return TRUE; |
1430 } | 1419 } |
1431 FX_BOOL CFDE_TxtEdtEngine::MoveLineEnd() { | 1420 FX_BOOL CFDE_TxtEdtEngine::MoveLineEnd() { |
1432 int32_t nIndex = m_bBefore ? m_nCaret : m_nCaret - 1; | 1421 int32_t nIndex = m_bBefore ? m_nCaret : m_nCaret - 1; |
1433 FDE_TXTEDTPARAGPOS ParagPos; | 1422 FDE_TXTEDTPARAGPOS ParagPos; |
1434 TextPos2ParagPos(nIndex, ParagPos); | 1423 TextPos2ParagPos(nIndex, ParagPos); |
1435 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex]; | 1424 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex]; |
1436 pParag->LoadParag(); | 1425 pParag->LoadParag(); |
1437 int32_t nLineCount = pParag->m_nLineCount; | 1426 int32_t nLineCount = pParag->GetLineCount(); |
1438 int32_t i = 0; | 1427 int32_t i = 0; |
1439 int32_t nStart = 0; | 1428 int32_t nStart = 0; |
1440 int32_t nCount = 0; | 1429 int32_t nCount = 0; |
1441 for (; i < nLineCount; i++) { | 1430 for (; i < nLineCount; i++) { |
1442 pParag->GetLineRange(i, nStart, nCount); | 1431 pParag->GetLineRange(i, nStart, nCount); |
1443 if (nIndex >= nStart && nIndex < nStart + nCount) { | 1432 if (nIndex >= nStart && nIndex < nStart + nCount) { |
1444 break; | 1433 break; |
1445 } | 1434 } |
1446 } | 1435 } |
1447 nIndex = nStart + nCount - 1; | 1436 nIndex = nStart + nCount - 1; |
(...skipping 14 matching lines...) Expand all Loading... |
1462 } | 1451 } |
1463 UpdateCaretRect(nIndex, bBefore); | 1452 UpdateCaretRect(nIndex, bBefore); |
1464 pParag->UnloadParag(); | 1453 pParag->UnloadParag(); |
1465 return TRUE; | 1454 return TRUE; |
1466 } | 1455 } |
1467 FX_BOOL CFDE_TxtEdtEngine::MoveParagStart() { | 1456 FX_BOOL CFDE_TxtEdtEngine::MoveParagStart() { |
1468 int32_t nIndex = m_bBefore ? m_nCaret : m_nCaret - 1; | 1457 int32_t nIndex = m_bBefore ? m_nCaret : m_nCaret - 1; |
1469 FDE_TXTEDTPARAGPOS ParagPos; | 1458 FDE_TXTEDTPARAGPOS ParagPos; |
1470 TextPos2ParagPos(nIndex, ParagPos); | 1459 TextPos2ParagPos(nIndex, ParagPos); |
1471 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex]; | 1460 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex]; |
1472 UpdateCaretRect(pParag->m_nCharStart, TRUE); | 1461 UpdateCaretRect(pParag->GetStartIndex(), TRUE); |
1473 return TRUE; | 1462 return TRUE; |
1474 } | 1463 } |
1475 FX_BOOL CFDE_TxtEdtEngine::MoveParagEnd() { | 1464 FX_BOOL CFDE_TxtEdtEngine::MoveParagEnd() { |
1476 int32_t nIndex = m_bBefore ? m_nCaret : m_nCaret - 1; | 1465 int32_t nIndex = m_bBefore ? m_nCaret : m_nCaret - 1; |
1477 FDE_TXTEDTPARAGPOS ParagPos; | 1466 FDE_TXTEDTPARAGPOS ParagPos; |
1478 TextPos2ParagPos(nIndex, ParagPos); | 1467 TextPos2ParagPos(nIndex, ParagPos); |
1479 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex]; | 1468 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex]; |
1480 nIndex = pParag->m_nCharStart + pParag->m_nCharCount - 1; | 1469 nIndex = pParag->GetStartIndex() + pParag->GetTextLength() - 1; |
1481 FX_WCHAR wChar = m_pTxtBuf->GetCharByIndex(nIndex); | 1470 FX_WCHAR wChar = m_pTxtBuf->GetCharByIndex(nIndex); |
1482 if (wChar == L'\n' && nIndex > 0) { | 1471 if (wChar == L'\n' && nIndex > 0) { |
1483 nIndex--; | 1472 nIndex--; |
1484 wChar = m_pTxtBuf->GetCharByIndex(nIndex); | 1473 wChar = m_pTxtBuf->GetCharByIndex(nIndex); |
1485 if (wChar != L'\r') { | 1474 if (wChar != L'\r') { |
1486 nIndex++; | 1475 nIndex++; |
1487 } | 1476 } |
1488 } | 1477 } |
1489 UpdateCaretRect(nIndex, TRUE); | 1478 UpdateCaretRect(nIndex, TRUE); |
1490 return TRUE; | 1479 return TRUE; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1766 int32_t nEngine = 0; | 1755 int32_t nEngine = 0; |
1767 ArchiveLoader >> nEngine; | 1756 ArchiveLoader >> nEngine; |
1768 m_pEngine = (CFDE_TxtEdtEngine*)(uintptr_t)nEngine; | 1757 m_pEngine = (CFDE_TxtEdtEngine*)(uintptr_t)nEngine; |
1769 int32_t iSel = 0; | 1758 int32_t iSel = 0; |
1770 ArchiveLoader >> iSel; | 1759 ArchiveLoader >> iSel; |
1771 m_bSel = !!iSel; | 1760 m_bSel = !!iSel; |
1772 ArchiveLoader >> m_nIndex; | 1761 ArchiveLoader >> m_nIndex; |
1773 ArchiveLoader >> m_nCaret; | 1762 ArchiveLoader >> m_nCaret; |
1774 ArchiveLoader >> m_wsRange; | 1763 ArchiveLoader >> m_wsRange; |
1775 } | 1764 } |
OLD | NEW |