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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 m_pTxtBuf->Insert(nLength, &m_wLineEnd, 1); | 153 m_pTxtBuf->Insert(nLength, &m_wLineEnd, 1); |
154 RebuildParagraphs(); | 154 RebuildParagraphs(); |
155 } | 155 } |
156 | 156 |
157 int32_t CFDE_TxtEdtEngine::GetTextLength() const { | 157 int32_t CFDE_TxtEdtEngine::GetTextLength() const { |
158 return GetTextBufLength(); | 158 return GetTextBufLength(); |
159 } | 159 } |
160 | 160 |
161 void CFDE_TxtEdtEngine::GetText(CFX_WideString& wsText, | 161 void CFDE_TxtEdtEngine::GetText(CFX_WideString& wsText, |
162 int32_t nStart, | 162 int32_t nStart, |
163 int32_t nCount) { | 163 int32_t nCount) const { |
164 int32_t nTextBufLength = GetTextBufLength(); | 164 int32_t nTextBufLength = GetTextBufLength(); |
165 if (nCount == -1) { | 165 if (nCount == -1) |
166 nCount = nTextBufLength - nStart; | 166 nCount = nTextBufLength - nStart; |
167 } | 167 |
168 m_pTxtBuf->GetRange(wsText, nStart, nCount); | 168 m_pTxtBuf->GetRange(wsText, nStart, nCount); |
169 RecoverParagEnd(wsText); | 169 RecoverParagEnd(wsText); |
170 } | 170 } |
171 | 171 |
172 void CFDE_TxtEdtEngine::ClearText() { | 172 void CFDE_TxtEdtEngine::ClearText() { |
173 DeleteRange(0, -1); | 173 DeleteRange(0, -1); |
174 } | 174 } |
175 | 175 |
176 int32_t CFDE_TxtEdtEngine::GetCaretRect(CFX_RectF& rtCaret) const { | 176 int32_t CFDE_TxtEdtEngine::GetCaretRect(CFX_RectF& rtCaret) const { |
177 rtCaret = m_rtCaret; | 177 rtCaret = m_rtCaret; |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 nRangeCnt--; | 639 nRangeCnt--; |
640 nRangeBgn++; | 640 nRangeBgn++; |
641 while (nRangeCnt--) { | 641 while (nRangeCnt--) { |
642 delete m_SelRangePtrArr[nRangeBgn]; | 642 delete m_SelRangePtrArr[nRangeBgn]; |
643 m_SelRangePtrArr.RemoveAt(nRangeBgn); | 643 m_SelRangePtrArr.RemoveAt(nRangeBgn); |
644 } | 644 } |
645 } | 645 } |
646 m_Param.pEventSink->On_SelChanged(this); | 646 m_Param.pEventSink->On_SelChanged(this); |
647 } | 647 } |
648 | 648 |
649 int32_t CFDE_TxtEdtEngine::CountSelRanges() { | 649 int32_t CFDE_TxtEdtEngine::CountSelRanges() const { |
650 return m_SelRangePtrArr.GetSize(); | 650 return m_SelRangePtrArr.GetSize(); |
651 } | 651 } |
652 | 652 |
653 int32_t CFDE_TxtEdtEngine::GetSelRange(int32_t nIndex, int32_t& nStart) { | 653 int32_t CFDE_TxtEdtEngine::GetSelRange(int32_t nIndex, int32_t& nStart) const { |
654 nStart = m_SelRangePtrArr[nIndex]->nStart; | 654 nStart = m_SelRangePtrArr[nIndex]->nStart; |
655 return m_SelRangePtrArr[nIndex]->nCount; | 655 return m_SelRangePtrArr[nIndex]->nCount; |
656 } | 656 } |
657 | 657 |
658 void CFDE_TxtEdtEngine::ClearSelection() { | 658 void CFDE_TxtEdtEngine::ClearSelection() { |
659 int32_t nCount = m_SelRangePtrArr.GetSize(); | 659 int32_t nCount = m_SelRangePtrArr.GetSize(); |
660 for (int i = 0; i < nCount; ++i) | 660 for (int i = 0; i < nCount; ++i) |
661 delete m_SelRangePtrArr[i]; | 661 delete m_SelRangePtrArr[i]; |
662 m_SelRangePtrArr.RemoveAll(); | 662 m_SelRangePtrArr.RemoveAll(); |
663 if (nCount && m_Param.pEventSink) | 663 if (nCount && m_Param.pEventSink) |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 m_nFirstLineEnd = FDE_TXTEDIT_LINEEND_CR; | 1183 m_nFirstLineEnd = FDE_TXTEDIT_LINEEND_CR; |
1184 m_bAutoLineEnd = false; | 1184 m_bAutoLineEnd = false; |
1185 } | 1185 } |
1186 bPreIsCR = false; | 1186 bPreIsCR = false; |
1187 } break; | 1187 } break; |
1188 } | 1188 } |
1189 } | 1189 } |
1190 return bPreIsCR; | 1190 return bPreIsCR; |
1191 } | 1191 } |
1192 | 1192 |
1193 void CFDE_TxtEdtEngine::RecoverParagEnd(CFX_WideString& wsText) { | 1193 void CFDE_TxtEdtEngine::RecoverParagEnd(CFX_WideString& wsText) const { |
1194 FX_WCHAR wc = (m_nFirstLineEnd == FDE_TXTEDIT_LINEEND_CR) ? L'\n' : L'\r'; | 1194 FX_WCHAR wc = (m_nFirstLineEnd == FDE_TXTEDIT_LINEEND_CR) ? L'\n' : L'\r'; |
1195 if (m_nFirstLineEnd == FDE_TXTEDIT_LINEEND_CRLF) { | 1195 if (m_nFirstLineEnd == FDE_TXTEDIT_LINEEND_CRLF) { |
1196 CFX_ArrayTemplate<int32_t> PosArr; | 1196 CFX_ArrayTemplate<int32_t> PosArr; |
1197 int32_t nLength = wsText.GetLength(); | 1197 int32_t nLength = wsText.GetLength(); |
1198 int32_t i = 0; | 1198 int32_t i = 0; |
1199 FX_WCHAR* lpPos = const_cast<FX_WCHAR*>(wsText.c_str()); | 1199 FX_WCHAR* lpPos = const_cast<FX_WCHAR*>(wsText.c_str()); |
1200 for (i = 0; i < nLength; i++, lpPos++) { | 1200 for (i = 0; i < nLength; i++, lpPos++) { |
1201 if (*lpPos == m_wLineEnd) { | 1201 if (*lpPos == m_wLineEnd) { |
1202 *lpPos = wc; | 1202 *lpPos = wc; |
1203 PosArr.Add(i); | 1203 PosArr.Add(i); |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1622 m_SelRangePtrArr.RemoveAt(nCountRange); | 1622 m_SelRangePtrArr.RemoveAt(nCountRange); |
1623 DeleteRange_DoRecord(nSelStart, nSelCount, true); | 1623 DeleteRange_DoRecord(nSelStart, nSelCount, true); |
1624 } | 1624 } |
1625 ClearSelection(); | 1625 ClearSelection(); |
1626 m_Param.pEventSink->On_TextChanged(this, m_ChangeInfo); | 1626 m_Param.pEventSink->On_TextChanged(this, m_ChangeInfo); |
1627 m_Param.pEventSink->On_SelChanged(this); | 1627 m_Param.pEventSink->On_SelChanged(this); |
1628 SetCaretPos(nSelStart, true); | 1628 SetCaretPos(nSelStart, true); |
1629 return; | 1629 return; |
1630 } | 1630 } |
1631 } | 1631 } |
OLD | NEW |