summaryrefslogtreecommitdiff
path: root/xfa/fee/fde_txtedtengine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fee/fde_txtedtengine.cpp')
-rw-r--r--xfa/fee/fde_txtedtengine.cpp143
1 files changed, 66 insertions, 77 deletions
diff --git a/xfa/fee/fde_txtedtengine.cpp b/xfa/fee/fde_txtedtengine.cpp
index 1dc03dcc85..812817fbfa 100644
--- a/xfa/fee/fde_txtedtengine.cpp
+++ b/xfa/fee/fde_txtedtengine.cpp
@@ -9,11 +9,10 @@
#include <algorithm>
#include "xfa/fde/tto/fde_textout.h"
-#include "xfa/fee/fde_txtedtbuf.h"
#include "xfa/fee/fde_txtedtparag.h"
-#include "xfa/fee/ifde_txtedtbuf.h"
#include "xfa/fee/ifde_txtedtengine.h"
#include "xfa/fee/ifde_txtedtpage.h"
+#include "xfa/fwl/basewidget/fwl_editimp.h"
#define FDE_PAGEWIDTH_MAX 0xFFFF
#define FDE_TXTPLATESIZE (1024 * 12)
@@ -21,9 +20,6 @@
#define FDE_TXTEDT_DORECORD_INS 0
#define FDE_TXTEDT_DORECORD_DEL 1
-IFDE_TxtEdtEngine* IFDE_TxtEdtEngine::Create() {
- return new CFDE_TxtEdtEngine();
-}
CFDE_TxtEdtEngine::CFDE_TxtEdtEngine()
: m_pTextBreak(nullptr),
m_nPageLineCount(20),
@@ -71,7 +67,7 @@ void CFDE_TxtEdtEngine::SetEditParams(const FDE_TXTEDTPARAMS& params) {
m_bAutoLineEnd = (m_Param.nLineEnd == FDE_TXTEDIT_LINEEND_Auto);
UpdateTxtBreak();
}
-const FDE_TXTEDTPARAMS* CFDE_TxtEdtEngine::GetEditParams() const {
+FDE_TXTEDTPARAMS* CFDE_TxtEdtEngine::GetEditParams() {
return &m_Param;
}
int32_t CFDE_TxtEdtEngine::CountPages() const {
@@ -329,7 +325,7 @@ int32_t CFDE_TxtEdtEngine::Insert(int32_t nStart,
int32_t nTotalLength = GetTextBufLength();
int32_t nCount = m_SelRangePtrArr.GetSize();
for (int32_t i = 0; i < nCount; i++) {
- FDE_LPTXTEDTSELRANGE lpSelRange = m_SelRangePtrArr.GetAt(i);
+ FDE_TXTEDTSELRANGE* lpSelRange = m_SelRangePtrArr.GetAt(i);
nTotalLength -= lpSelRange->nCount;
}
int32_t nExpectLength = nTotalLength + nLength;
@@ -538,7 +534,7 @@ void CFDE_TxtEdtEngine::SetAliasChar(FX_WCHAR wcAlias) {
}
void CFDE_TxtEdtEngine::RemoveSelRange(int32_t nStart, int32_t nCount) {
- FDE_LPTXTEDTSELRANGE lpTemp = NULL;
+ FDE_TXTEDTSELRANGE* lpTemp = nullptr;
int32_t nRangeCount = m_SelRangePtrArr.GetSize();
int32_t i = 0;
for (i = 0; i < nRangeCount; i++) {
@@ -557,17 +553,17 @@ void CFDE_TxtEdtEngine::AddSelRange(int32_t nStart, int32_t nCount) {
}
int32_t nSize = m_SelRangePtrArr.GetSize();
if (nSize <= 0) {
- FDE_LPTXTEDTSELRANGE lpSelRange = new FDE_TXTEDTSELRANGE;
+ FDE_TXTEDTSELRANGE* lpSelRange = new FDE_TXTEDTSELRANGE;
lpSelRange->nStart = nStart;
lpSelRange->nCount = nCount;
m_SelRangePtrArr.Add(lpSelRange);
m_Param.pEventSink->On_SelChanged(this);
return;
}
- FDE_LPTXTEDTSELRANGE lpTemp = NULL;
+ FDE_TXTEDTSELRANGE* lpTemp = nullptr;
lpTemp = m_SelRangePtrArr[nSize - 1];
if (nStart >= lpTemp->nStart + lpTemp->nCount) {
- FDE_LPTXTEDTSELRANGE lpSelRange = new FDE_TXTEDTSELRANGE;
+ FDE_TXTEDTSELRANGE* lpSelRange = new FDE_TXTEDTSELRANGE;
lpSelRange->nStart = nStart;
lpSelRange->nCount = nCount;
m_SelRangePtrArr.Add(lpSelRange);
@@ -602,7 +598,7 @@ void CFDE_TxtEdtEngine::AddSelRange(int32_t nStart, int32_t nCount) {
}
}
if (nRangeCnt == 0) {
- FDE_LPTXTEDTSELRANGE lpSelRange = new FDE_TXTEDTSELRANGE;
+ FDE_TXTEDTSELRANGE* lpSelRange = new FDE_TXTEDTSELRANGE;
lpSelRange->nStart = nStart;
lpSelRange->nCount = nCount;
m_SelRangePtrArr.InsertAt(nRangeBgn, lpSelRange);
@@ -683,7 +679,7 @@ int32_t CFDE_TxtEdtEngine::DoLayout(IFX_Pause* pPause) {
for (; m_nLayoutPos < nCount; m_nLayoutPos++) {
pParag = m_ParagPtrArray[m_nLayoutPos];
pParag->CalcLines();
- nLineCount += pParag->m_nLineCount;
+ nLineCount += pParag->GetLineCount();
if ((pPause != NULL) && (nLineCount > m_nPageLineCount) &&
pPause->NeedToPauseNow()) {
m_nLineCount += nLineCount;
@@ -709,8 +705,8 @@ void CFDE_TxtEdtEngine::EndLayout() {
FX_BOOL CFDE_TxtEdtEngine::Optimize(IFX_Pause* pPause) {
return m_pTxtBuf->Optimize(pPause);
}
-IFDE_TxtEdtBuf* CFDE_TxtEdtEngine::GetTextBuf() const {
- return (IFDE_TxtEdtBuf*)m_pTxtBuf;
+CFDE_TxtEdtBuf* CFDE_TxtEdtEngine::GetTextBuf() const {
+ return m_pTxtBuf;
}
int32_t CFDE_TxtEdtEngine::GetTextBufLength() const {
return m_pTxtBuf->GetTextLength() - 1;
@@ -727,7 +723,7 @@ int32_t CFDE_TxtEdtEngine::GetPageLineCount() const {
int32_t CFDE_TxtEdtEngine::CountParags() const {
return m_ParagPtrArray.GetSize();
}
-IFDE_TxtEdtParag* CFDE_TxtEdtEngine::GetParag(int32_t nParagIndex) const {
+CFDE_TxtEdtParag* CFDE_TxtEdtEngine::GetParag(int32_t nParagIndex) const {
return m_ParagPtrArray[nParagIndex];
}
IFX_CharIter* CFDE_TxtEdtEngine::CreateCharIter() {
@@ -746,12 +742,12 @@ int32_t CFDE_TxtEdtEngine::Line2Parag(int32_t nStartParag,
int32_t i = nStartParag;
for (; i < nCount; i++) {
pParag = m_ParagPtrArray[i];
- nLineTotal += pParag->m_nLineCount;
+ nLineTotal += pParag->GetLineCount();
if (nLineTotal > nLineIndex) {
break;
}
}
- nStartLine = nLineTotal - pParag->m_nLineCount;
+ nStartLine = nLineTotal - pParag->GetLineCount();
return i;
}
void CFDE_TxtEdtEngine::GetPreDeleteText(CFX_WideString& wsText,
@@ -812,14 +808,14 @@ void CFDE_TxtEdtEngine::Inner_Insert(int32_t nStart,
m_Param.pEventSink->On_PageUnload(this, m_nCaretPage, 0);
int32_t nParagCount = m_ParagPtrArray.GetSize();
int32_t i = 0;
- for (i = ParagPos.nParagIndex + 1; i < nParagCount; i++) {
- m_ParagPtrArray[i]->m_nCharStart += nLength;
- }
+ for (i = ParagPos.nParagIndex + 1; i < nParagCount; i++)
+ m_ParagPtrArray[i]->IncrementStartIndex(nLength);
+
CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex];
- int32_t nReserveLineCount = pParag->m_nLineCount;
- int32_t nReserveCharStart = pParag->m_nCharStart;
+ int32_t nReserveLineCount = pParag->GetLineCount();
+ int32_t nReserveCharStart = pParag->GetStartIndex();
int32_t nLeavePart = ParagPos.nCharIndex;
- int32_t nCutPart = pParag->m_nCharCount - ParagPos.nCharIndex;
+ int32_t nCutPart = pParag->GetTextLength() - ParagPos.nCharIndex;
int32_t nTextStart = 0;
FX_WCHAR wCurChar = L' ';
const FX_WCHAR* lpPos = lpText;
@@ -829,30 +825,30 @@ void CFDE_TxtEdtEngine::Inner_Insert(int32_t nStart,
wCurChar = *lpPos;
if (wCurChar == m_wLineEnd) {
if (bFirst) {
- pParag->m_nCharCount = nLeavePart + (i - nTextStart + 1);
- pParag->m_nLineCount = -1;
- nReserveCharStart += pParag->m_nCharCount;
+ pParag->SetTextLength(nLeavePart + (i - nTextStart + 1));
+ pParag->SetLineCount(-1);
+ nReserveCharStart += pParag->GetTextLength();
bFirst = FALSE;
} else {
pParag = new CFDE_TxtEdtParag(this);
- pParag->m_nLineCount = -1;
- pParag->m_nCharCount = i - nTextStart + 1;
- pParag->m_nCharStart = nReserveCharStart;
+ pParag->SetLineCount(-1);
+ pParag->SetTextLength(i - nTextStart + 1);
+ pParag->SetStartIndex(nReserveCharStart);
m_ParagPtrArray.InsertAt(++nParagIndex, pParag);
- nReserveCharStart += pParag->m_nCharCount;
+ nReserveCharStart += pParag->GetTextLength();
}
nTextStart = i + 1;
}
}
if (bFirst) {
- pParag->m_nCharCount += nLength;
- pParag->m_nLineCount = -1;
+ pParag->IncrementTextLength(nLength);
+ pParag->SetLineCount(-1);
bFirst = FALSE;
} else {
pParag = new CFDE_TxtEdtParag(this);
- pParag->m_nLineCount = -1;
- pParag->m_nCharCount = nLength - nTextStart + nCutPart;
- pParag->m_nCharStart = nReserveCharStart;
+ pParag->SetLineCount(-1);
+ pParag->SetTextLength(nLength - nTextStart + nCutPart);
+ pParag->SetStartIndex(nReserveCharStart);
m_ParagPtrArray.InsertAt(++nParagIndex, pParag);
}
m_pTxtBuf->Insert(nStart, lpText, nLength);
@@ -860,7 +856,7 @@ void CFDE_TxtEdtEngine::Inner_Insert(int32_t nStart,
for (i = ParagPos.nParagIndex; i <= nParagIndex; i++) {
pParag = m_ParagPtrArray[i];
pParag->CalcLines();
- nTotalLineCount += pParag->m_nLineCount;
+ nTotalLineCount += pParag->GetLineCount();
}
m_nLineCount += nTotalLineCount - nReserveLineCount;
m_Param.pEventSink->On_PageLoad(this, m_nCaretPage, 0);
@@ -879,7 +875,7 @@ void CFDE_TxtEdtEngine::Inner_DeleteRange(int32_t nStart, int32_t nCount) {
TextPos2ParagPos(nEnd, ParagPosEnd);
CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPosEnd.nParagIndex];
FX_BOOL bLastParag = FALSE;
- if (ParagPosEnd.nCharIndex == pParag->m_nCharCount - 1) {
+ if (ParagPosEnd.nCharIndex == pParag->GetTextLength() - 1) {
if (ParagPosEnd.nParagIndex < m_ParagPtrArray.GetSize() - 1) {
ParagPosEnd.nParagIndex++;
} else {
@@ -892,8 +888,8 @@ void CFDE_TxtEdtEngine::Inner_DeleteRange(int32_t nStart, int32_t nCount) {
for (i = ParagPosBgn.nParagIndex; i <= ParagPosEnd.nParagIndex; i++) {
CFDE_TxtEdtParag* pParag = m_ParagPtrArray[i];
pParag->CalcLines();
- nTotalLineCount += pParag->m_nLineCount;
- nTotalCharCount += pParag->m_nCharCount;
+ nTotalLineCount += pParag->GetLineCount();
+ nTotalCharCount += pParag->GetTextLength();
}
m_pTxtBuf->Delete(nStart, nCount);
int32_t nNextParagIndex = (ParagPosBgn.nCharIndex == 0 && bLastParag)
@@ -905,14 +901,14 @@ void CFDE_TxtEdtEngine::Inner_DeleteRange(int32_t nStart, int32_t nCount) {
}
if (!(bLastParag && ParagPosBgn.nCharIndex == 0)) {
pParag = m_ParagPtrArray[ParagPosBgn.nParagIndex];
- pParag->m_nCharCount = nTotalCharCount - nCount;
+ pParag->SetTextLength(nTotalCharCount - nCount);
pParag->CalcLines();
- nTotalLineCount -= pParag->m_nLineCount;
+ nTotalLineCount -= pParag->GetTextLength();
}
int32_t nParagCount = m_ParagPtrArray.GetSize();
- for (i = nNextParagIndex; i < nParagCount; i++) {
- m_ParagPtrArray[i]->m_nCharStart -= nCount;
- }
+ for (i = nNextParagIndex; i < nParagCount; i++)
+ m_ParagPtrArray[i]->DecrementStartIndex(nCount);
+
m_nLineCount -= nTotalLineCount;
UpdatePages();
int32_t nPageCount = CountPages();
@@ -964,9 +960,9 @@ void CFDE_TxtEdtEngine::RebuildParagraphs() {
nIndex = pIter->GetAt();
if (wChar == m_wLineEnd) {
CFDE_TxtEdtParag* pParag = new CFDE_TxtEdtParag(this);
- pParag->m_nCharStart = nParagStart;
- pParag->m_nCharCount = nIndex - nParagStart + 1;
- pParag->m_nLineCount = -1;
+ pParag->SetStartIndex(nParagStart);
+ pParag->SetTextLength(nIndex - nParagStart + 1);
+ pParag->SetLineCount(-1);
m_ParagPtrArray.Add(pParag);
nParagStart = nIndex + 1;
}
@@ -1002,22 +998,22 @@ void CFDE_TxtEdtEngine::UpdateParags() {
int32_t i = 0;
for (i = 0; i < nCount; i++) {
pParag = m_ParagPtrArray[i];
- if (pParag->m_nLineCount == -1) {
+ if (pParag->GetLineCount() == -1)
pParag->CalcLines();
- }
- nLineCount += pParag->m_nLineCount;
+
+ nLineCount += pParag->GetLineCount();
}
m_nLineCount = nLineCount;
}
void CFDE_TxtEdtEngine::UpdatePages() {
- if (m_nLineCount == 0) {
+ if (m_nLineCount == 0)
return;
- }
+
int32_t nPageCount = (m_nLineCount - 1) / (m_nPageLineCount) + 1;
int32_t nSize = m_PagePtrArray.GetSize();
- if (nSize == nPageCount) {
+ if (nSize == nPageCount)
return;
- }
+
if (nSize > nPageCount) {
IFDE_TxtEdtPage* pPage = NULL;
int32_t i = 0;
@@ -1028,7 +1024,6 @@ void CFDE_TxtEdtEngine::UpdatePages() {
}
m_PagePtrArray.RemoveAt(i);
}
- m_Param.pEventSink->On_PageCountChanged(this);
return;
}
if (nSize < nPageCount) {
@@ -1038,7 +1033,6 @@ void CFDE_TxtEdtEngine::UpdatePages() {
pPage = IFDE_TxtEdtPage::Create(this, i);
m_PagePtrArray.Add(pPage);
}
- m_Param.pEventSink->On_PageCountChanged(this);
return;
}
}
@@ -1244,25 +1238,24 @@ int32_t CFDE_TxtEdtEngine::MovePage2Char(int32_t nIndex) {
int32_t i = 0;
for (i = 0; i < nParagCount; i++) {
pParag = m_ParagPtrArray[i];
- if (pParag->m_nCharStart <= nIndex &&
- nIndex < (pParag->m_nCharStart + pParag->m_nCharCount)) {
+ if (pParag->GetStartIndex() <= nIndex &&
+ nIndex < (pParag->GetStartIndex() + pParag->GetTextLength())) {
break;
}
- nLineCount += pParag->m_nLineCount;
+ nLineCount += pParag->GetLineCount();
}
pParag->LoadParag();
int32_t nLineStart = -1;
int32_t nLineCharCount = -1;
- for (i = 0; i < pParag->m_nLineCount; i++) {
+ for (i = 0; i < pParag->GetLineCount(); i++) {
pParag->GetLineRange(i, nLineStart, nLineCharCount);
if (nLineStart <= nIndex && nIndex < (nLineStart + nLineCharCount)) {
break;
}
}
- ASSERT(i < pParag->m_nLineCount);
+ ASSERT(i < pParag->GetLineCount());
nLineCount += (i + 1);
m_nCaretPage = (nLineCount - 1) / m_nPageLineCount + 1 - 1;
- m_Param.pEventSink->On_PageChange(this, m_nCaretPage);
pParag->UnloadParag();
return m_nCaretPage;
}
@@ -1276,9 +1269,9 @@ void CFDE_TxtEdtEngine::TextPos2ParagPos(int32_t nIndex,
while (nEnd > nBgn) {
nMid = (nBgn + nEnd) / 2;
CFDE_TxtEdtParag* pParag = m_ParagPtrArray[nMid];
- if (nIndex < pParag->m_nCharStart) {
+ if (nIndex < pParag->GetStartIndex()) {
nEnd = nMid - 1;
- } else if (nIndex >= (pParag->m_nCharStart + pParag->m_nCharCount)) {
+ } else if (nIndex >= (pParag->GetStartIndex() + pParag->GetTextLength())) {
nBgn = nMid + 1;
} else {
break;
@@ -1287,11 +1280,11 @@ void CFDE_TxtEdtEngine::TextPos2ParagPos(int32_t nIndex,
if (nBgn == nEnd) {
nMid = nBgn;
}
- ASSERT(nIndex >= m_ParagPtrArray[nMid]->m_nCharStart &&
- (nIndex < m_ParagPtrArray[nMid]->m_nCharStart +
- m_ParagPtrArray[nMid]->m_nCharCount));
+ ASSERT(nIndex >= m_ParagPtrArray[nMid]->GetStartIndex() &&
+ (nIndex < m_ParagPtrArray[nMid]->GetStartIndex() +
+ m_ParagPtrArray[nMid]->GetTextLength()));
ParagPos.nParagIndex = nMid;
- ParagPos.nCharIndex = nIndex - m_ParagPtrArray[nMid]->m_nCharStart;
+ ParagPos.nCharIndex = nIndex - m_ParagPtrArray[nMid]->GetStartIndex();
}
int32_t CFDE_TxtEdtEngine::MoveForward(FX_BOOL& bBefore) {
if (m_nCaret == m_pTxtBuf->GetTextLength() - 1) {
@@ -1343,7 +1336,6 @@ FX_BOOL CFDE_TxtEdtEngine::MoveUp(CFX_PointF& ptCaret) {
} else {
m_nCaretPage--;
}
- m_Param.pEventSink->On_PageChange(this, m_nCaretPage);
ptCaret.x -= rtContent.left;
IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage);
ptCaret.x += pCurPage->GetContentsBox().right();
@@ -1357,7 +1349,6 @@ FX_BOOL CFDE_TxtEdtEngine::MoveUp(CFX_PointF& ptCaret) {
}
ptCaret.y -= rtContent.top;
m_nCaretPage--;
- m_Param.pEventSink->On_PageChange(this, m_nCaretPage);
IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage);
ptCaret.y += pCurPage->GetContentsBox().bottom();
}
@@ -1387,7 +1378,6 @@ FX_BOOL CFDE_TxtEdtEngine::MoveDown(CFX_PointF& ptCaret) {
} else {
m_nCaretPage++;
}
- m_Param.pEventSink->On_PageChange(this, m_nCaretPage);
ptCaret.x -= rtContent.right();
IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage);
ptCaret.x += pCurPage->GetContentsBox().left;
@@ -1401,7 +1391,6 @@ FX_BOOL CFDE_TxtEdtEngine::MoveDown(CFX_PointF& ptCaret) {
}
ptCaret.y -= rtContent.bottom();
m_nCaretPage++;
- m_Param.pEventSink->On_PageChange(this, m_nCaretPage);
IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage);
ptCaret.y += pCurPage->GetContentsBox().top;
}
@@ -1414,7 +1403,7 @@ FX_BOOL CFDE_TxtEdtEngine::MoveLineStart() {
TextPos2ParagPos(nIndex, ParagPos);
CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex];
pParag->LoadParag();
- int32_t nLineCount = pParag->m_nLineCount;
+ int32_t nLineCount = pParag->GetLineCount();
int32_t i = 0;
int32_t nStart = 0;
int32_t nCount = 0;
@@ -1434,7 +1423,7 @@ FX_BOOL CFDE_TxtEdtEngine::MoveLineEnd() {
TextPos2ParagPos(nIndex, ParagPos);
CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex];
pParag->LoadParag();
- int32_t nLineCount = pParag->m_nLineCount;
+ int32_t nLineCount = pParag->GetLineCount();
int32_t i = 0;
int32_t nStart = 0;
int32_t nCount = 0;
@@ -1469,7 +1458,7 @@ FX_BOOL CFDE_TxtEdtEngine::MoveParagStart() {
FDE_TXTEDTPARAGPOS ParagPos;
TextPos2ParagPos(nIndex, ParagPos);
CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex];
- UpdateCaretRect(pParag->m_nCharStart, TRUE);
+ UpdateCaretRect(pParag->GetStartIndex(), TRUE);
return TRUE;
}
FX_BOOL CFDE_TxtEdtEngine::MoveParagEnd() {
@@ -1477,7 +1466,7 @@ FX_BOOL CFDE_TxtEdtEngine::MoveParagEnd() {
FDE_TXTEDTPARAGPOS ParagPos;
TextPos2ParagPos(nIndex, ParagPos);
CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex];
- nIndex = pParag->m_nCharStart + pParag->m_nCharCount - 1;
+ nIndex = pParag->GetStartIndex() + pParag->GetTextLength() - 1;
FX_WCHAR wChar = m_pTxtBuf->GetCharByIndex(nIndex);
if (wChar == L'\n' && nIndex > 0) {
nIndex--;