diff options
-rw-r--r-- | xfa/fde/cfde_txtedtengine.cpp | 52 | ||||
-rw-r--r-- | xfa/fde/cfde_txtedtengine.h | 5 | ||||
-rw-r--r-- | xfa/fwl/cfwl_edit.cpp | 24 |
3 files changed, 35 insertions, 46 deletions
diff --git a/xfa/fde/cfde_txtedtengine.cpp b/xfa/fde/cfde_txtedtengine.cpp index a3d743ca02..e69f299e30 100644 --- a/xfa/fde/cfde_txtedtengine.cpp +++ b/xfa/fde/cfde_txtedtengine.cpp @@ -26,10 +26,8 @@ const uint32_t kUnicodeParagraphSeparator = 0x2029; enum FDE_TXTEDT_MODIFY_RET { FDE_TXTEDT_MODIFY_RET_F_Locked = -5, FDE_TXTEDT_MODIFY_RET_F_Invalidate = -4, - FDE_TXTEDT_MODIFY_RET_F_Boundary = -3, FDE_TXTEDT_MODIFY_RET_F_Full = -2, FDE_TXTEDT_MODIFY_RET_S_Normal = 0, - FDE_TXTEDT_MODIFY_RET_S_Part = 2, }; enum FDE_TXTEDIT_LINEEND { @@ -337,18 +335,17 @@ int32_t CFDE_TxtEdtEngine::MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret, return m_nCaret; } -int32_t CFDE_TxtEdtEngine::Insert(int32_t nStart, - const wchar_t* lpText, - int32_t nLength) { +int32_t CFDE_TxtEdtEngine::Insert(const CFX_WideString& str) { if (IsLocked()) return FDE_TXTEDT_MODIFY_RET_F_Locked; + int32_t nLength = str.GetLength(); CFX_WideString wsTemp; wchar_t* lpBuffer = wsTemp.GetBuffer(nLength); - memcpy(lpBuffer, lpText, nLength * sizeof(wchar_t)); + memcpy(lpBuffer, str.c_str(), nLength * sizeof(wchar_t)); ReplaceParagEnd(lpBuffer, nLength, false); wsTemp.ReleaseBuffer(nLength); - bool bPart = false; + if (m_nLimit > 0) { int32_t nTotalLength = GetTextLength(); for (const auto& lpSelRange : m_SelRangePtrArr) @@ -358,14 +355,11 @@ int32_t CFDE_TxtEdtEngine::Insert(int32_t nStart, if (nTotalLength == m_nLimit) return FDE_TXTEDT_MODIFY_RET_F_Full; - if (nExpectLength > m_nLimit) { + if (nExpectLength > m_nLimit) nLength -= (nExpectLength - m_nLimit); - bPart = true; - } } if ((m_Param.dwMode & FDE_TEXTEDITMODE_LimitArea_Vert) || (m_Param.dwMode & FDE_TEXTEDITMODE_LimitArea_Horz)) { - int32_t nTemp = nLength; if (m_Param.dwMode & FDE_TEXTEDITMODE_Password) { while (nLength > 0) { CFX_WideString wsText = GetPreInsertText(m_nCaret, lpBuffer, nLength); @@ -389,12 +383,8 @@ int32_t CFDE_TxtEdtEngine::Insert(int32_t nStart, nLength--; } } - if (nLength == 0) { + if (nLength == 0) return FDE_TXTEDT_MODIFY_RET_F_Full; - } - if (nLength < nTemp) { - bPart = true; - } } if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { CFX_WideString wsText = GetPreInsertText(m_nCaret, lpBuffer, nLength); @@ -411,7 +401,7 @@ int32_t CFDE_TxtEdtEngine::Insert(int32_t nStart, Inner_Insert(m_nCaret, lpBuffer, nLength); m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Insert; m_ChangeInfo.wsInsert = CFX_WideString(lpBuffer, nLength); - nStart = m_nCaret; + int32_t nStart = m_nCaret; nStart += nLength; wchar_t wChar = m_pTxtBuf->GetCharByIndex(nStart - 1); bool bBefore = true; @@ -421,23 +411,23 @@ int32_t CFDE_TxtEdtEngine::Insert(int32_t nStart, } SetCaretPos(nStart, bBefore); m_Param.pEventSink->OnTextChanged(m_ChangeInfo); - return bPart ? FDE_TXTEDT_MODIFY_RET_S_Part : FDE_TXTEDT_MODIFY_RET_S_Normal; + return FDE_TXTEDT_MODIFY_RET_S_Normal; } -int32_t CFDE_TxtEdtEngine::Delete(int32_t nStart, bool bBackspace) { - if (IsLocked()) { - return FDE_TXTEDT_MODIFY_RET_F_Locked; - } +void CFDE_TxtEdtEngine::Delete(bool bBackspace) { + if (IsLocked()) + return; if (IsSelect()) { DeleteSelect(); - return FDE_TXTEDT_MODIFY_RET_S_Normal; + return; } int32_t nCount = 1; + int32_t nStart = m_nCaret; if (bBackspace) { - if (nStart == 0) { - return FDE_TXTEDT_MODIFY_RET_F_Boundary; - } + if (nStart == 0) + return; + if (nStart > 2 && m_pTxtBuf->GetCharByIndex(nStart - 1) == L'\n' && m_pTxtBuf->GetCharByIndex(nStart - 2) == L'\r') { nStart--; @@ -445,9 +435,9 @@ int32_t CFDE_TxtEdtEngine::Delete(int32_t nStart, bool bBackspace) { } nStart--; } else { - if (nStart == GetTextLength()) { - return FDE_TXTEDT_MODIFY_RET_F_Full; - } + if (nStart == GetTextLength()) + return; + if ((nStart + 1 < GetTextLength()) && (m_pTxtBuf->GetCharByIndex(nStart) == L'\r') && (m_pTxtBuf->GetCharByIndex(nStart + 1) == L'\n')) { @@ -457,8 +447,9 @@ int32_t CFDE_TxtEdtEngine::Delete(int32_t nStart, bool bBackspace) { if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { CFX_WideString wsText = GetPreDeleteText(nStart, nCount); if (!m_Param.pEventSink->OnValidate(wsText)) - return FDE_TXTEDT_MODIFY_RET_F_Invalidate; + return; } + CFX_WideString wsRange = m_pTxtBuf->GetRange(nStart, nCount); m_Param.pEventSink->OnAddDoRecord(pdfium::MakeUnique<DeleteOperation>( this, nStart, m_nCaret, wsRange, false)); @@ -469,7 +460,6 @@ int32_t CFDE_TxtEdtEngine::Delete(int32_t nStart, bool bBackspace) { SetCaretPos(nStart + ((!bBackspace && nStart > 0) ? -1 : 0), (bBackspace || nStart == 0)); m_Param.pEventSink->OnTextChanged(m_ChangeInfo); - return FDE_TXTEDT_MODIFY_RET_S_Normal; } void CFDE_TxtEdtEngine::RemoveSelRange(int32_t nStart, int32_t nCount) { diff --git a/xfa/fde/cfde_txtedtengine.h b/xfa/fde/cfde_txtedtengine.h index 19aed3fe7b..31de49b4d2 100644 --- a/xfa/fde/cfde_txtedtengine.h +++ b/xfa/fde/cfde_txtedtengine.h @@ -111,15 +111,14 @@ class CFDE_TxtEdtEngine { int32_t SetCaretPos(int32_t nIndex, bool bBefore); int32_t MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret, bool bShift, bool bCtrl); - int32_t Insert(int32_t nStart, const wchar_t* lpText, int32_t nLength); - int32_t Delete(int32_t nStart, bool bBackspace); + int32_t Insert(const CFX_WideString& str); + void Delete(bool bBackspace); void SetLimit(int32_t nLimit) { m_nLimit = nLimit; } int32_t GetLimit() const { return m_nLimit; } void SetAliasChar(wchar_t wcAlias) { m_wcAliasChar = wcAlias; } void RemoveSelRange(int32_t nStart, int32_t nCount); - void AddSelRange(int32_t nStart, int32_t nCount); int32_t CountSelRanges() const { return pdfium::CollectionSize<int32_t>(m_SelRangePtrArr); diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp index 7dd8baded8..38f8f70498 100644 --- a/xfa/fwl/cfwl_edit.cpp +++ b/xfa/fwl/cfwl_edit.cpp @@ -347,14 +347,12 @@ bool CFWL_Edit::Cut(CFX_WideString& wsCut) { wsCut += wsTemp; wsTemp.clear(); } - m_EdtEngine.Delete(0, false); + m_EdtEngine.Delete(false); return true; } bool CFWL_Edit::Paste(const CFX_WideString& wsPaste) { - int32_t nCaret = m_EdtEngine.GetCaretPos(); - int32_t iError = - m_EdtEngine.Insert(nCaret, wsPaste.c_str(), wsPaste.GetLength()); + int32_t iError = m_EdtEngine.Insert(wsPaste); if (iError < 0) { ProcessInsertError(iError); return false; @@ -1195,6 +1193,9 @@ void CFWL_Edit::ClearRecord() { } void CFWL_Edit::ProcessInsertError(int32_t iError) { + // TODO(dsinclair): This should probably also send events for Validation + // failure .... + if (iError != -2) return; @@ -1422,11 +1423,11 @@ void CFWL_Edit::OnKeyDown(CFWL_MessageKey* pMsg) { (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { break; } - int32_t nCaret = m_EdtEngine.GetCaretPos(); + #if (_FX_OS_ == _FX_MACOSX_) - m_EdtEngine.Delete(nCaret, true); + m_EdtEngine.Delete(true); #else - m_EdtEngine.Delete(nCaret, false); + m_EdtEngine.Delete(false); #endif break; } @@ -1447,21 +1448,20 @@ void CFWL_Edit::OnChar(CFWL_MessageKey* pMsg) { int32_t iError = 0; wchar_t c = static_cast<wchar_t>(pMsg->m_dwKeyCode); - int32_t nCaret = m_EdtEngine.GetCaretPos(); switch (c) { case FWL_VKEY_Back: - m_EdtEngine.Delete(nCaret, true); + m_EdtEngine.Delete(true); break; case FWL_VKEY_NewLine: case FWL_VKEY_Escape: break; case FWL_VKEY_Tab: { - iError = m_EdtEngine.Insert(nCaret, L"\t", 1); + iError = m_EdtEngine.Insert(L"\t"); break; } case FWL_VKEY_Return: { if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_WantReturn) { - iError = m_EdtEngine.Insert(nCaret, L"\n", 1); + iError = m_EdtEngine.Insert(L"\n"); } break; } @@ -1485,7 +1485,7 @@ void CFWL_Edit::OnChar(CFWL_MessageKey* pMsg) { { break; } - iError = m_EdtEngine.Insert(nCaret, &c, 1); + iError = m_EdtEngine.Insert(CFX_WideString(c)); break; } } |