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 "xfa/fde/cfde_txtedtbuf.h" | 9 #include "xfa/fde/cfde_txtedtbuf.h" |
10 #include "xfa/fde/cfde_txtedtbufiter.h" | 10 #include "xfa/fde/cfde_txtedtbufiter.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 FXSYS_memset(&m_rtCaret, 0, sizeof(CFX_RectF)); | 44 FXSYS_memset(&m_rtCaret, 0, sizeof(CFX_RectF)); |
45 m_pTxtBuf = new CFDE_TxtEdtBuf(); | 45 m_pTxtBuf = new CFDE_TxtEdtBuf(); |
46 m_bAutoLineEnd = (m_Param.nLineEnd == FDE_TXTEDIT_LINEEND_Auto); | 46 m_bAutoLineEnd = (m_Param.nLineEnd == FDE_TXTEDIT_LINEEND_Auto); |
47 } | 47 } |
48 | 48 |
49 CFDE_TxtEdtEngine::~CFDE_TxtEdtEngine() { | 49 CFDE_TxtEdtEngine::~CFDE_TxtEdtEngine() { |
50 delete m_pTxtBuf; | 50 delete m_pTxtBuf; |
51 delete m_pTextBreak; | 51 delete m_pTextBreak; |
52 RemoveAllParags(); | 52 RemoveAllParags(); |
53 RemoveAllPages(); | 53 RemoveAllPages(); |
54 m_Param.pEventSink = NULL; | 54 m_Param.pEventSink = nullptr; |
55 ClearSelection(); | 55 ClearSelection(); |
56 } | 56 } |
57 | 57 |
58 void CFDE_TxtEdtEngine::SetEditParams(const FDE_TXTEDTPARAMS& params) { | 58 void CFDE_TxtEdtEngine::SetEditParams(const FDE_TXTEDTPARAMS& params) { |
59 if (!m_pTextBreak) | 59 if (!m_pTextBreak) |
60 m_pTextBreak = new CFX_TxtBreak(FX_TXTBREAKPOLICY_None); | 60 m_pTextBreak = new CFX_TxtBreak(FX_TXTBREAKPOLICY_None); |
61 | 61 |
62 FXSYS_memcpy(&m_Param, ¶ms, sizeof(FDE_TXTEDTPARAMS)); | 62 FXSYS_memcpy(&m_Param, ¶ms, sizeof(FDE_TXTEDTPARAMS)); |
63 m_wLineEnd = params.wLineBreakChar; | 63 m_wLineEnd = params.wLineBreakChar; |
64 m_bAutoLineEnd = (m_Param.nLineEnd == FDE_TXTEDIT_LINEEND_Auto); | 64 m_bAutoLineEnd = (m_Param.nLineEnd == FDE_TXTEDIT_LINEEND_Auto); |
65 UpdateTxtBreak(); | 65 UpdateTxtBreak(); |
66 } | 66 } |
67 | 67 |
68 FDE_TXTEDTPARAMS* CFDE_TxtEdtEngine::GetEditParams() { | 68 FDE_TXTEDTPARAMS* CFDE_TxtEdtEngine::GetEditParams() { |
69 return &m_Param; | 69 return &m_Param; |
70 } | 70 } |
71 | 71 |
72 int32_t CFDE_TxtEdtEngine::CountPages() const { | 72 int32_t CFDE_TxtEdtEngine::CountPages() const { |
73 if (m_nLineCount == 0) { | 73 if (m_nLineCount == 0) { |
74 return 0; | 74 return 0; |
75 } | 75 } |
76 return ((m_nLineCount - 1) / m_nPageLineCount) + 1; | 76 return ((m_nLineCount - 1) / m_nPageLineCount) + 1; |
77 } | 77 } |
78 | 78 |
79 IFDE_TxtEdtPage* CFDE_TxtEdtEngine::GetPage(int32_t nIndex) { | 79 IFDE_TxtEdtPage* CFDE_TxtEdtEngine::GetPage(int32_t nIndex) { |
80 if (m_PagePtrArray.GetSize() <= nIndex) { | 80 if (m_PagePtrArray.GetSize() <= nIndex) { |
81 return NULL; | 81 return nullptr; |
82 } | 82 } |
83 return (IFDE_TxtEdtPage*)m_PagePtrArray[nIndex]; | 83 return (IFDE_TxtEdtPage*)m_PagePtrArray[nIndex]; |
84 } | 84 } |
85 | 85 |
86 void CFDE_TxtEdtEngine::SetTextByStream(IFX_Stream* pStream) { | 86 void CFDE_TxtEdtEngine::SetTextByStream(IFX_Stream* pStream) { |
87 ResetEngine(); | 87 ResetEngine(); |
88 int32_t nIndex = 0; | 88 int32_t nIndex = 0; |
89 if (pStream != NULL && pStream->GetLength()) { | 89 if (pStream && pStream->GetLength()) { |
90 int32_t nStreamLength = pStream->GetLength(); | 90 int32_t nStreamLength = pStream->GetLength(); |
91 FX_BOOL bValid = TRUE; | 91 FX_BOOL bValid = TRUE; |
92 if (m_nLimit > 0 && nStreamLength > m_nLimit) { | 92 if (m_nLimit > 0 && nStreamLength > m_nLimit) { |
93 bValid = FALSE; | 93 bValid = FALSE; |
94 } | 94 } |
95 FX_BOOL bPreIsCR = FALSE; | 95 FX_BOOL bPreIsCR = FALSE; |
96 if (bValid) { | 96 if (bValid) { |
97 uint8_t bom[4]; | 97 uint8_t bom[4]; |
98 int32_t nPos = pStream->GetBOM(bom); | 98 int32_t nPos = pStream->GetBOM(bom); |
99 pStream->Seek(FX_STREAMSEEK_Begin, nPos); | 99 pStream->Seek(FX_STREAMSEEK_Begin, nPos); |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 int32_t CFDE_TxtEdtEngine::StartLayout() { | 661 int32_t CFDE_TxtEdtEngine::StartLayout() { |
662 Lock(); | 662 Lock(); |
663 RemoveAllPages(); | 663 RemoveAllPages(); |
664 m_nLayoutPos = 0; | 664 m_nLayoutPos = 0; |
665 m_nLineCount = 0; | 665 m_nLineCount = 0; |
666 return 0; | 666 return 0; |
667 } | 667 } |
668 | 668 |
669 int32_t CFDE_TxtEdtEngine::DoLayout(IFX_Pause* pPause) { | 669 int32_t CFDE_TxtEdtEngine::DoLayout(IFX_Pause* pPause) { |
670 int32_t nCount = m_ParagPtrArray.GetSize(); | 670 int32_t nCount = m_ParagPtrArray.GetSize(); |
671 CFDE_TxtEdtParag* pParag = NULL; | 671 CFDE_TxtEdtParag* pParag = nullptr; |
672 int32_t nLineCount = 0; | 672 int32_t nLineCount = 0; |
673 for (; m_nLayoutPos < nCount; m_nLayoutPos++) { | 673 for (; m_nLayoutPos < nCount; m_nLayoutPos++) { |
674 pParag = m_ParagPtrArray[m_nLayoutPos]; | 674 pParag = m_ParagPtrArray[m_nLayoutPos]; |
675 pParag->CalcLines(); | 675 pParag->CalcLines(); |
676 nLineCount += pParag->GetLineCount(); | 676 nLineCount += pParag->GetLineCount(); |
677 if ((pPause != NULL) && (nLineCount > m_nPageLineCount) && | 677 if (pPause && nLineCount > m_nPageLineCount && pPause->NeedToPauseNow()) { |
678 pPause->NeedToPauseNow()) { | |
679 m_nLineCount += nLineCount; | 678 m_nLineCount += nLineCount; |
680 return (++m_nLayoutPos * 100) / nCount; | 679 return (++m_nLayoutPos * 100) / nCount; |
681 } | 680 } |
682 } | 681 } |
683 m_nLineCount += nLineCount; | 682 m_nLineCount += nLineCount; |
684 return 100; | 683 return 100; |
685 } | 684 } |
686 | 685 |
687 void CFDE_TxtEdtEngine::EndLayout() { | 686 void CFDE_TxtEdtEngine::EndLayout() { |
688 UpdatePages(); | 687 UpdatePages(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 int32_t CFDE_TxtEdtEngine::CountParags() const { | 724 int32_t CFDE_TxtEdtEngine::CountParags() const { |
726 return m_ParagPtrArray.GetSize(); | 725 return m_ParagPtrArray.GetSize(); |
727 } | 726 } |
728 | 727 |
729 CFDE_TxtEdtParag* CFDE_TxtEdtEngine::GetParag(int32_t nParagIndex) const { | 728 CFDE_TxtEdtParag* CFDE_TxtEdtEngine::GetParag(int32_t nParagIndex) const { |
730 return m_ParagPtrArray[nParagIndex]; | 729 return m_ParagPtrArray[nParagIndex]; |
731 } | 730 } |
732 | 731 |
733 IFX_CharIter* CFDE_TxtEdtEngine::CreateCharIter() { | 732 IFX_CharIter* CFDE_TxtEdtEngine::CreateCharIter() { |
734 if (!m_pTxtBuf) { | 733 if (!m_pTxtBuf) { |
735 return NULL; | 734 return nullptr; |
736 } | 735 } |
737 return new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)m_pTxtBuf); | 736 return new CFDE_TxtEdtBufIter((CFDE_TxtEdtBuf*)m_pTxtBuf); |
738 } | 737 } |
739 | 738 |
740 int32_t CFDE_TxtEdtEngine::Line2Parag(int32_t nStartParag, | 739 int32_t CFDE_TxtEdtEngine::Line2Parag(int32_t nStartParag, |
741 int32_t nStartLineofParag, | 740 int32_t nStartLineofParag, |
742 int32_t nLineIndex, | 741 int32_t nLineIndex, |
743 int32_t& nStartLine) const { | 742 int32_t& nStartLine) const { |
744 int32_t nLineTotal = nStartLineofParag; | 743 int32_t nLineTotal = nStartLineofParag; |
745 int32_t nCount = m_ParagPtrArray.GetSize(); | 744 int32_t nCount = m_ParagPtrArray.GetSize(); |
746 CFDE_TxtEdtParag* pParag = NULL; | 745 CFDE_TxtEdtParag* pParag = nullptr; |
747 int32_t i = nStartParag; | 746 int32_t i = nStartParag; |
748 for (; i < nCount; i++) { | 747 for (; i < nCount; i++) { |
749 pParag = m_ParagPtrArray[i]; | 748 pParag = m_ParagPtrArray[i]; |
750 nLineTotal += pParag->GetLineCount(); | 749 nLineTotal += pParag->GetLineCount(); |
751 if (nLineTotal > nLineIndex) { | 750 if (nLineTotal > nLineIndex) { |
752 break; | 751 break; |
753 } | 752 } |
754 } | 753 } |
755 nStartLine = nLineTotal - pParag->GetLineCount(); | 754 nStartLine = nLineTotal - pParag->GetLineCount(); |
756 return i; | 755 return i; |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 for (int32_t i = 0; i < m_PagePtrArray.GetSize(); i++) | 988 for (int32_t i = 0; i < m_PagePtrArray.GetSize(); i++) |
990 delete m_PagePtrArray[i]; | 989 delete m_PagePtrArray[i]; |
991 m_PagePtrArray.RemoveAll(); | 990 m_PagePtrArray.RemoveAll(); |
992 } | 991 } |
993 | 992 |
994 void CFDE_TxtEdtEngine::UpdateParags() { | 993 void CFDE_TxtEdtEngine::UpdateParags() { |
995 int32_t nCount = m_ParagPtrArray.GetSize(); | 994 int32_t nCount = m_ParagPtrArray.GetSize(); |
996 if (nCount == 0) { | 995 if (nCount == 0) { |
997 return; | 996 return; |
998 } | 997 } |
999 CFDE_TxtEdtParag* pParag = NULL; | 998 CFDE_TxtEdtParag* pParag = nullptr; |
1000 int32_t nLineCount = 0; | 999 int32_t nLineCount = 0; |
1001 int32_t i = 0; | 1000 int32_t i = 0; |
1002 for (i = 0; i < nCount; i++) { | 1001 for (i = 0; i < nCount; i++) { |
1003 pParag = m_ParagPtrArray[i]; | 1002 pParag = m_ParagPtrArray[i]; |
1004 if (pParag->GetLineCount() == -1) | 1003 if (pParag->GetLineCount() == -1) |
1005 pParag->CalcLines(); | 1004 pParag->CalcLines(); |
1006 | 1005 |
1007 nLineCount += pParag->GetLineCount(); | 1006 nLineCount += pParag->GetLineCount(); |
1008 } | 1007 } |
1009 m_nLineCount = nLineCount; | 1008 m_nLineCount = nLineCount; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 IFDE_TxtEdtPage* pPage = m_PagePtrArray[m_nCaretPage]; | 1222 IFDE_TxtEdtPage* pPage = m_PagePtrArray[m_nCaretPage]; |
1224 m_Param.pEventSink->On_PageLoad(this, m_nCaretPage, 0); | 1223 m_Param.pEventSink->On_PageLoad(this, m_nCaretPage, 0); |
1225 int32_t nPageCharStart = pPage->GetCharStart(); | 1224 int32_t nPageCharStart = pPage->GetCharStart(); |
1226 int32_t nPageCharCount = pPage->GetCharCount(); | 1225 int32_t nPageCharCount = pPage->GetCharCount(); |
1227 if (nIndex >= nPageCharStart && nIndex < nPageCharStart + nPageCharCount) { | 1226 if (nIndex >= nPageCharStart && nIndex < nPageCharStart + nPageCharCount) { |
1228 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); | 1227 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); |
1229 return m_nCaretPage; | 1228 return m_nCaretPage; |
1230 } | 1229 } |
1231 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); | 1230 m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0); |
1232 } | 1231 } |
1233 CFDE_TxtEdtParag* pParag = NULL; | 1232 CFDE_TxtEdtParag* pParag = nullptr; |
1234 int32_t nLineCount = 0; | 1233 int32_t nLineCount = 0; |
1235 int32_t nParagCount = m_ParagPtrArray.GetSize(); | 1234 int32_t nParagCount = m_ParagPtrArray.GetSize(); |
1236 int32_t i = 0; | 1235 int32_t i = 0; |
1237 for (i = 0; i < nParagCount; i++) { | 1236 for (i = 0; i < nParagCount; i++) { |
1238 pParag = m_ParagPtrArray[i]; | 1237 pParag = m_ParagPtrArray[i]; |
1239 if (pParag->GetStartIndex() <= nIndex && | 1238 if (pParag->GetStartIndex() <= nIndex && |
1240 nIndex < (pParag->GetStartIndex() + pParag->GetTextLength())) { | 1239 nIndex < (pParag->GetStartIndex() + pParag->GetTextLength())) { |
1241 break; | 1240 break; |
1242 } | 1241 } |
1243 nLineCount += pParag->GetLineCount(); | 1242 nLineCount += pParag->GetLineCount(); |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1603 m_SelRangePtrArr.RemoveAt(nCountRange); | 1602 m_SelRangePtrArr.RemoveAt(nCountRange); |
1604 DeleteRange_DoRecord(nSelStart, nSelCount, TRUE); | 1603 DeleteRange_DoRecord(nSelStart, nSelCount, TRUE); |
1605 } | 1604 } |
1606 ClearSelection(); | 1605 ClearSelection(); |
1607 m_Param.pEventSink->On_TextChanged(this, m_ChangeInfo); | 1606 m_Param.pEventSink->On_TextChanged(this, m_ChangeInfo); |
1608 m_Param.pEventSink->On_SelChanged(this); | 1607 m_Param.pEventSink->On_SelChanged(this); |
1609 SetCaretPos(nSelStart, TRUE); | 1608 SetCaretPos(nSelStart, TRUE); |
1610 return; | 1609 return; |
1611 } | 1610 } |
1612 } | 1611 } |
OLD | NEW |