From be9b8947d0090e20116822fe7caf5e7973d6b20a Mon Sep 17 00:00:00 2001 From: dsinclair Date: Wed, 18 May 2016 06:09:33 -0700 Subject: Pass objects instead of strings for undo/redo records. Currently the Undo/Redo records are serialized as byte strings and stored into a CFX_ByteStringArray. They are deserialized when used. This CL removes the serialization and stores the objects in a deque of unique pointers. Review-Url: https://codereview.chromium.org/1980293004 --- core/fxcrt/fx_basic_buffer.cpp | 127 ------------------------- core/fxcrt/include/fx_basic.h | 65 ------------- xfa/fee/fde_txtedtengine.cpp | 165 +++++++-------------------------- xfa/fee/fde_txtedtengine.h | 34 +++---- xfa/fwl/basewidget/fwl_comboboximp.cpp | 23 +++-- xfa/fwl/basewidget/fwl_comboboximp.h | 4 +- xfa/fwl/basewidget/fwl_editimp.cpp | 51 +++++----- xfa/fwl/basewidget/fwl_editimp.h | 25 ++--- xfa/fwl/basewidget/ifwl_combobox.h | 5 +- xfa/fwl/basewidget/ifwl_edit.h | 5 +- xfa/fwl/lightwidget/cfwl_combobox.cpp | 8 +- xfa/fwl/lightwidget/cfwl_combobox.h | 4 +- xfa/fwl/lightwidget/cfwl_edit.cpp | 12 +-- xfa/fwl/lightwidget/cfwl_edit.h | 5 +- 14 files changed, 114 insertions(+), 419 deletions(-) diff --git a/core/fxcrt/fx_basic_buffer.cpp b/core/fxcrt/fx_basic_buffer.cpp index 2762497e5c..91ca6dad7c 100644 --- a/core/fxcrt/fx_basic_buffer.cpp +++ b/core/fxcrt/fx_basic_buffer.cpp @@ -182,133 +182,6 @@ CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const CFX_WideTextBuf& buf) { return *this; } -#ifdef PDF_ENABLE_XFA -CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(uint8_t i) { - if (m_pStream) { - m_pStream->WriteBlock(&i, 1); - } else { - m_SavingBuf.AppendByte(i); - } - return *this; -} -CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(int i) { - if (m_pStream) { - m_pStream->WriteBlock(&i, sizeof(int)); - } else { - m_SavingBuf.AppendBlock(&i, sizeof(int)); - } - return *this; -} -CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(uint32_t i) { - if (m_pStream) { - m_pStream->WriteBlock(&i, sizeof(uint32_t)); - } else { - m_SavingBuf.AppendBlock(&i, sizeof(uint32_t)); - } - return *this; -} -CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(FX_FLOAT f) { - if (m_pStream) { - m_pStream->WriteBlock(&f, sizeof(FX_FLOAT)); - } else { - m_SavingBuf.AppendBlock(&f, sizeof(FX_FLOAT)); - } - return *this; -} -CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(const CFX_ByteStringC& bstr) { - int len = bstr.GetLength(); - if (m_pStream) { - m_pStream->WriteBlock(&len, sizeof(int)); - m_pStream->WriteBlock(bstr.raw_str(), len); - } else { - m_SavingBuf.AppendBlock(&len, sizeof(int)); - m_SavingBuf.AppendBlock(bstr.raw_str(), len); - } - return *this; -} -CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(const FX_WCHAR* wstr) { - FX_STRSIZE len = FXSYS_wcslen(wstr); - if (m_pStream) { - m_pStream->WriteBlock(&len, sizeof(int)); - m_pStream->WriteBlock(wstr, len); - } else { - m_SavingBuf.AppendBlock(&len, sizeof(int)); - m_SavingBuf.AppendBlock(wstr, len); - } - return *this; -} -CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(const CFX_WideString& wstr) { - CFX_ByteString encoded = wstr.UTF16LE_Encode(); - return operator<<(encoded.AsStringC()); -} -void CFX_ArchiveSaver::Write(const void* pData, FX_STRSIZE dwSize) { - if (m_pStream) { - m_pStream->WriteBlock(pData, dwSize); - } else { - m_SavingBuf.AppendBlock(pData, dwSize); - } -} -CFX_ArchiveLoader::CFX_ArchiveLoader(const uint8_t* pData, uint32_t dwSize) { - m_pLoadingBuf = pData; - m_LoadingPos = 0; - m_LoadingSize = dwSize; -} -FX_BOOL CFX_ArchiveLoader::IsEOF() { - return m_LoadingPos >= m_LoadingSize; -} -CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(uint8_t& i) { - if (m_LoadingPos >= m_LoadingSize) { - return *this; - } - i = m_pLoadingBuf[m_LoadingPos++]; - return *this; -} -CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(int& i) { - Read(&i, sizeof(int)); - return *this; -} -CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(uint32_t& i) { - Read(&i, sizeof(uint32_t)); - return *this; -} -CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(FX_FLOAT& i) { - Read(&i, sizeof(FX_FLOAT)); - return *this; -} -CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(CFX_ByteString& str) { - if (m_LoadingPos + 4 > m_LoadingSize) { - return *this; - } - int len; - operator>>(len); - str.clear(); - if (len <= 0 || m_LoadingPos + len > m_LoadingSize) { - return *this; - } - FX_CHAR* buffer = str.GetBuffer(len); - FXSYS_memcpy(buffer, m_pLoadingBuf + m_LoadingPos, len); - str.ReleaseBuffer(len); - m_LoadingPos += len; - return *this; -} -CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(CFX_WideString& str) { - CFX_ByteString encoded; - operator>>(encoded); - str = CFX_WideString::FromUTF16LE( - reinterpret_cast(encoded.c_str()), - encoded.GetLength() / sizeof(unsigned short)); - return *this; -} -FX_BOOL CFX_ArchiveLoader::Read(void* pBuf, uint32_t dwSize) { - if (m_LoadingPos + dwSize > m_LoadingSize) { - return FALSE; - } - FXSYS_memcpy(pBuf, m_pLoadingBuf + m_LoadingPos, dwSize); - m_LoadingPos += dwSize; - return TRUE; -} -#endif // PDF_ENABLE_XFA - void CFX_BitStream::Init(const uint8_t* pData, uint32_t dwSize) { m_pData = pData; m_BitSize = dwSize * 8; diff --git a/core/fxcrt/include/fx_basic.h b/core/fxcrt/include/fx_basic.h index 59d72b8f5a..1835d9e0a6 100644 --- a/core/fxcrt/include/fx_basic.h +++ b/core/fxcrt/include/fx_basic.h @@ -108,71 +108,6 @@ class CFX_WideTextBuf : public CFX_BinaryBuf { CFX_WideTextBuf& operator<<(const CFX_WideTextBuf& buf); }; -#ifdef PDF_ENABLE_XFA -class CFX_ArchiveSaver { - public: - CFX_ArchiveSaver() : m_pStream(NULL) {} - - CFX_ArchiveSaver& operator<<(uint8_t i); - - CFX_ArchiveSaver& operator<<(int i); - - CFX_ArchiveSaver& operator<<(uint32_t i); - - CFX_ArchiveSaver& operator<<(FX_FLOAT i); - - CFX_ArchiveSaver& operator<<(double i); - - CFX_ArchiveSaver& operator<<(const CFX_ByteStringC& bstr); - - CFX_ArchiveSaver& operator<<(const FX_WCHAR* bstr); - - CFX_ArchiveSaver& operator<<(const CFX_WideString& wstr); - - void Write(const void* pData, FX_STRSIZE dwSize); - - intptr_t GetLength() { return m_SavingBuf.GetSize(); } - - const uint8_t* GetBuffer() { return m_SavingBuf.GetBuffer(); } - - void SetStream(IFX_FileStream* pStream) { m_pStream = pStream; } - - protected: - CFX_BinaryBuf m_SavingBuf; - - IFX_FileStream* m_pStream; -}; -class CFX_ArchiveLoader { - public: - CFX_ArchiveLoader(const uint8_t* pData, uint32_t dwSize); - - CFX_ArchiveLoader& operator>>(uint8_t& i); - - CFX_ArchiveLoader& operator>>(int& i); - - CFX_ArchiveLoader& operator>>(uint32_t& i); - - CFX_ArchiveLoader& operator>>(FX_FLOAT& i); - - CFX_ArchiveLoader& operator>>(double& i); - - CFX_ArchiveLoader& operator>>(CFX_ByteString& bstr); - - CFX_ArchiveLoader& operator>>(CFX_WideString& wstr); - - FX_BOOL IsEOF(); - - FX_BOOL Read(void* pBuf, uint32_t dwSize); - - protected: - uint32_t m_LoadingPos; - - const uint8_t* m_pLoadingBuf; - - uint32_t m_LoadingSize; -}; -#endif // PDF_ENABLE_XFA - class CFX_FileBufferArchive { public: CFX_FileBufferArchive(); diff --git a/xfa/fee/fde_txtedtengine.cpp b/xfa/fee/fde_txtedtengine.cpp index 826f0ce62c..d1d33fe8c6 100644 --- a/xfa/fee/fde_txtedtengine.cpp +++ b/xfa/fee/fde_txtedtengine.cpp @@ -383,14 +383,11 @@ int32_t CFDE_TxtEdtEngine::Insert(int32_t nStart, if (IsSelect()) { DeleteSelect(); } - if (!(m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo)) { - IFDE_TxtEdtDoRecord* pRecord = - new CFDE_TxtEdtDoRecord_Insert(this, m_nCaret, lpBuffer, nLength); - CFX_ByteString bsDoRecord; - pRecord->Serialize(bsDoRecord); - m_Param.pEventSink->On_AddDoRecord(this, bsDoRecord.AsStringC()); - pRecord->Release(); - } + if (!(m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo)) + m_Param.pEventSink->On_AddDoRecord( + this, + new CFDE_TxtEdtDoRecord_Insert(this, m_nCaret, lpBuffer, nLength)); + GetText(m_ChangeInfo.wsPrevText, 0); Inner_Insert(m_nCaret, lpBuffer, nLength); m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Insert; @@ -447,12 +444,9 @@ int32_t CFDE_TxtEdtEngine::Delete(int32_t nStart, FX_BOOL bBackspace) { if (!(m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo)) { CFX_WideString wsRange; m_pTxtBuf->GetRange(wsRange, nStart, nCount); - IFDE_TxtEdtDoRecord* pRecord = - new CFDE_TxtEdtDoRecord_DeleteRange(this, nStart, m_nCaret, wsRange); - CFX_ByteString bsDoRecord; - pRecord->Serialize(bsDoRecord); - m_Param.pEventSink->On_AddDoRecord(this, bsDoRecord.AsStringC()); - pRecord->Release(); + m_Param.pEventSink->On_AddDoRecord( + this, + new CFDE_TxtEdtDoRecord_DeleteRange(this, nStart, m_nCaret, wsRange)); } m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Delete; GetText(m_ChangeInfo.wsDelete, nStart, nCount); @@ -634,38 +628,22 @@ void CFDE_TxtEdtEngine::ClearSelection() { m_Param.pEventSink->On_SelChanged(this); } -FX_BOOL CFDE_TxtEdtEngine::Redo(const CFX_ByteStringC& bsRedo) { - if (IsLocked()) { +FX_BOOL CFDE_TxtEdtEngine::Redo(const IFDE_TxtEdtDoRecord* pDoRecord) { + if (IsLocked()) return FALSE; - } - if (m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo) { + if (m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo) return FALSE; - } - IFDE_TxtEdtDoRecord* pDoRecord = IFDE_TxtEdtDoRecord::Create(bsRedo); - ASSERT(pDoRecord); - if (pDoRecord == NULL) { - return FALSE; - } - FX_BOOL bOK = pDoRecord->Redo(); - pDoRecord->Release(); - return bOK; + return pDoRecord->Redo(); } -FX_BOOL CFDE_TxtEdtEngine::Undo(const CFX_ByteStringC& bsUndo) { - if (IsLocked()) { + +FX_BOOL CFDE_TxtEdtEngine::Undo(const IFDE_TxtEdtDoRecord* pDoRecord) { + if (IsLocked()) return FALSE; - } - if (m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo) { + if (m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo) return FALSE; - } - IFDE_TxtEdtDoRecord* pDoRecord = IFDE_TxtEdtDoRecord::Create(bsUndo); - ASSERT(pDoRecord); - if (pDoRecord == NULL) { - return FALSE; - } - FX_BOOL bOK = pDoRecord->Undo(); - pDoRecord->Release(); - return bOK; + return pDoRecord->Undo(); } + int32_t CFDE_TxtEdtEngine::StartLayout() { Lock(); RemoveAllPages(); @@ -930,12 +908,9 @@ void CFDE_TxtEdtEngine::DeleteRange_DoRecord(int32_t nStart, if (!(m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo)) { CFX_WideString wsRange; m_pTxtBuf->GetRange(wsRange, nStart, nCount); - IFDE_TxtEdtDoRecord* pRecord = new CFDE_TxtEdtDoRecord_DeleteRange( - this, nStart, m_nCaret, wsRange, bSel); - CFX_ByteString bsDoRecord; - pRecord->Serialize(bsDoRecord); - m_Param.pEventSink->On_AddDoRecord(this, bsDoRecord.AsStringC()); - pRecord->Release(); + m_Param.pEventSink->On_AddDoRecord( + this, new CFDE_TxtEdtDoRecord_DeleteRange(this, nStart, m_nCaret, + wsRange, bSel)); } m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Delete; GetText(m_ChangeInfo.wsDelete, nStart, nCount); @@ -1601,24 +1576,6 @@ void CFDE_TxtEdtEngine::DeleteSelect() { } } -IFDE_TxtEdtDoRecord* IFDE_TxtEdtDoRecord::Create( - const CFX_ByteStringC& bsDoRecord) { - const uint32_t* lpBuf = - reinterpret_cast(bsDoRecord.raw_str()); - switch (*lpBuf) { - case FDE_TXTEDT_DORECORD_INS: - return new CFDE_TxtEdtDoRecord_Insert(bsDoRecord); - case FDE_TXTEDT_DORECORD_DEL: - return new CFDE_TxtEdtDoRecord_DeleteRange(bsDoRecord); - default: - return nullptr; - } -} - -CFDE_TxtEdtDoRecord_Insert::CFDE_TxtEdtDoRecord_Insert( - const CFX_ByteStringC& bsDoRecord) { - Deserialize(bsDoRecord); -} CFDE_TxtEdtDoRecord_Insert::CFDE_TxtEdtDoRecord_Insert( CFDE_TxtEdtEngine* pEngine, int32_t nCaret, @@ -1630,11 +1587,10 @@ CFDE_TxtEdtDoRecord_Insert::CFDE_TxtEdtDoRecord_Insert( FXSYS_memcpy(lpBuffer, lpText, nLength * sizeof(FX_WCHAR)); m_wsInsert.ReleaseBuffer(); } + CFDE_TxtEdtDoRecord_Insert::~CFDE_TxtEdtDoRecord_Insert() {} -void CFDE_TxtEdtDoRecord_Insert::Release() { - delete this; -} -FX_BOOL CFDE_TxtEdtDoRecord_Insert::Undo() { + +FX_BOOL CFDE_TxtEdtDoRecord_Insert::Undo() const { if (m_pEngine->IsSelect()) { m_pEngine->ClearSelection(); } @@ -1646,7 +1602,8 @@ FX_BOOL CFDE_TxtEdtDoRecord_Insert::Undo() { m_pEngine->SetCaretPos(m_nCaret, TRUE); return TRUE; } -FX_BOOL CFDE_TxtEdtDoRecord_Insert::Redo() { + +FX_BOOL CFDE_TxtEdtDoRecord_Insert::Redo() const { m_pEngine->Inner_Insert(m_nCaret, m_wsInsert.c_str(), m_wsInsert.GetLength()); FDE_TXTEDTPARAMS& Param = m_pEngine->m_Param; m_pEngine->m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Insert; @@ -1655,34 +1612,7 @@ FX_BOOL CFDE_TxtEdtDoRecord_Insert::Redo() { m_pEngine->SetCaretPos(m_nCaret, FALSE); return TRUE; } -void CFDE_TxtEdtDoRecord_Insert::Serialize(CFX_ByteString& bsDoRecord) const { - CFX_ArchiveSaver ArchiveSaver; - ArchiveSaver << int32_t(FDE_TXTEDT_DORECORD_INS); - ArchiveSaver << (int32_t)(uintptr_t)m_pEngine; - ArchiveSaver << m_nCaret; - ArchiveSaver << m_wsInsert; - int32_t nLength = ArchiveSaver.GetLength(); - const uint8_t* lpSrcBuf = ArchiveSaver.GetBuffer(); - FX_CHAR* lpDstBuf = bsDoRecord.GetBuffer(nLength); - FXSYS_memcpy(lpDstBuf, lpSrcBuf, nLength); - bsDoRecord.ReleaseBuffer(nLength); -} -void CFDE_TxtEdtDoRecord_Insert::Deserialize( - const CFX_ByteStringC& bsDoRecord) { - CFX_ArchiveLoader ArchiveLoader(bsDoRecord.raw_str(), bsDoRecord.GetLength()); - int32_t nType = 0; - ArchiveLoader >> nType; - ASSERT(nType == FDE_TXTEDT_DORECORD_INS); - int32_t nEngine = 0; - ArchiveLoader >> nEngine; - m_pEngine = (CFDE_TxtEdtEngine*)(uintptr_t)nEngine; - ArchiveLoader >> m_nCaret; - ArchiveLoader >> m_wsInsert; -} -CFDE_TxtEdtDoRecord_DeleteRange::CFDE_TxtEdtDoRecord_DeleteRange( - const CFX_ByteStringC& bsDoRecord) { - Deserialize(bsDoRecord); -} + CFDE_TxtEdtDoRecord_DeleteRange::CFDE_TxtEdtDoRecord_DeleteRange( CFDE_TxtEdtEngine* pEngine, int32_t nIndex, @@ -1696,11 +1626,10 @@ CFDE_TxtEdtDoRecord_DeleteRange::CFDE_TxtEdtDoRecord_DeleteRange( m_wsRange(wsRange) { ASSERT(pEngine); } + CFDE_TxtEdtDoRecord_DeleteRange::~CFDE_TxtEdtDoRecord_DeleteRange() {} -void CFDE_TxtEdtDoRecord_DeleteRange::Release() { - delete this; -} -FX_BOOL CFDE_TxtEdtDoRecord_DeleteRange::Undo() { + +FX_BOOL CFDE_TxtEdtDoRecord_DeleteRange::Undo() const { if (m_pEngine->IsSelect()) { m_pEngine->ClearSelection(); } @@ -1715,7 +1644,8 @@ FX_BOOL CFDE_TxtEdtDoRecord_DeleteRange::Undo() { m_pEngine->SetCaretPos(m_nCaret, TRUE); return TRUE; } -FX_BOOL CFDE_TxtEdtDoRecord_DeleteRange::Redo() { + +FX_BOOL CFDE_TxtEdtDoRecord_DeleteRange::Redo() const { m_pEngine->Inner_DeleteRange(m_nIndex, m_wsRange.GetLength()); if (m_bSel) { m_pEngine->RemoveSelRange(m_nIndex, m_wsRange.GetLength()); @@ -1727,34 +1657,3 @@ FX_BOOL CFDE_TxtEdtDoRecord_DeleteRange::Redo() { m_pEngine->SetCaretPos(m_nIndex, TRUE); return TRUE; } -void CFDE_TxtEdtDoRecord_DeleteRange::Serialize( - CFX_ByteString& bsDoRecord) const { - CFX_ArchiveSaver ArchiveSaver; - ArchiveSaver << int32_t(FDE_TXTEDT_DORECORD_DEL); - ArchiveSaver << (int32_t)(uintptr_t)m_pEngine; - ArchiveSaver << (int32_t)m_bSel; - ArchiveSaver << m_nIndex; - ArchiveSaver << m_nCaret; - ArchiveSaver << m_wsRange; - int32_t nLength = ArchiveSaver.GetLength(); - const uint8_t* lpSrcBuf = ArchiveSaver.GetBuffer(); - FX_CHAR* lpDstBuf = bsDoRecord.GetBuffer(nLength); - FXSYS_memcpy(lpDstBuf, lpSrcBuf, nLength); - bsDoRecord.ReleaseBuffer(nLength); -} -void CFDE_TxtEdtDoRecord_DeleteRange::Deserialize( - const CFX_ByteStringC& bsDoRecord) { - CFX_ArchiveLoader ArchiveLoader(bsDoRecord.raw_str(), bsDoRecord.GetLength()); - int32_t nType = 0; - ArchiveLoader >> nType; - ASSERT(nType == FDE_TXTEDT_DORECORD_DEL); - int32_t nEngine = 0; - ArchiveLoader >> nEngine; - m_pEngine = (CFDE_TxtEdtEngine*)(uintptr_t)nEngine; - int32_t iSel = 0; - ArchiveLoader >> iSel; - m_bSel = !!iSel; - ArchiveLoader >> m_nIndex; - ArchiveLoader >> m_nCaret; - ArchiveLoader >> m_wsRange; -} diff --git a/xfa/fee/fde_txtedtengine.h b/xfa/fee/fde_txtedtengine.h index 4671bf549a..585caa1eb6 100644 --- a/xfa/fee/fde_txtedtengine.h +++ b/xfa/fee/fde_txtedtengine.h @@ -20,12 +20,10 @@ class CFDE_TxtEdtDoRecord_DeleteRange; class IFDE_TxtEdtDoRecord { public: - static IFDE_TxtEdtDoRecord* Create(const CFX_ByteStringC& bsDoRecord); virtual ~IFDE_TxtEdtDoRecord() {} - virtual void Release() = 0; - virtual FX_BOOL Redo() = 0; - virtual FX_BOOL Undo() = 0; - virtual void Serialize(CFX_ByteString& bsDoRecord) const = 0; + + virtual FX_BOOL Redo() const = 0; + virtual FX_BOOL Undo() const = 0; }; class CFDE_TxtEdtEngine { @@ -74,8 +72,8 @@ class CFDE_TxtEdtEngine { int32_t GetSelRange(int32_t nIndex, int32_t& nStart); void ClearSelection(); - FX_BOOL Redo(const CFX_ByteStringC& bsRedo); - FX_BOOL Undo(const CFX_ByteStringC& bsUndo); + FX_BOOL Redo(const IFDE_TxtEdtDoRecord* pRecord); + FX_BOOL Undo(const IFDE_TxtEdtDoRecord* pRecord); int32_t StartLayout(); int32_t DoLayout(IFX_Pause* pPause); @@ -195,19 +193,14 @@ class CFDE_TxtEdtEngine { class CFDE_TxtEdtDoRecord_Insert : public IFDE_TxtEdtDoRecord { public: - CFDE_TxtEdtDoRecord_Insert(const CFX_ByteStringC& bsDoRecord); CFDE_TxtEdtDoRecord_Insert(CFDE_TxtEdtEngine* pEngine, int32_t nCaret, const FX_WCHAR* lpText, int32_t nLength); - virtual void Release(); - virtual FX_BOOL Undo(); - virtual FX_BOOL Redo(); - virtual void Serialize(CFX_ByteString& bsDoRecord) const; + ~CFDE_TxtEdtDoRecord_Insert() override; - protected: - ~CFDE_TxtEdtDoRecord_Insert(); - void Deserialize(const CFX_ByteStringC& bsDoRecord); + FX_BOOL Undo() const override; + FX_BOOL Redo() const override; private: CFDE_TxtEdtEngine* m_pEngine; @@ -217,20 +210,15 @@ class CFDE_TxtEdtDoRecord_Insert : public IFDE_TxtEdtDoRecord { class CFDE_TxtEdtDoRecord_DeleteRange : public IFDE_TxtEdtDoRecord { public: - CFDE_TxtEdtDoRecord_DeleteRange(const CFX_ByteStringC& bsDoRecord); CFDE_TxtEdtDoRecord_DeleteRange(CFDE_TxtEdtEngine* pEngine, int32_t nIndex, int32_t nCaret, const CFX_WideString& wsRange, FX_BOOL bSel = FALSE); - virtual void Release(); - virtual FX_BOOL Undo(); - virtual FX_BOOL Redo(); - virtual void Serialize(CFX_ByteString& bsDoRecord) const; + ~CFDE_TxtEdtDoRecord_DeleteRange() override; - protected: - ~CFDE_TxtEdtDoRecord_DeleteRange(); - void Deserialize(const CFX_ByteStringC& bsDoRecord); + FX_BOOL Undo() const override; + FX_BOOL Redo() const override; private: CFDE_TxtEdtEngine* m_pEngine; diff --git a/xfa/fwl/basewidget/fwl_comboboximp.cpp b/xfa/fwl/basewidget/fwl_comboboximp.cpp index 81c2fa75d3..6af49d8021 100644 --- a/xfa/fwl/basewidget/fwl_comboboximp.cpp +++ b/xfa/fwl/basewidget/fwl_comboboximp.cpp @@ -69,11 +69,11 @@ FWL_Error IFWL_ComboBox::SetEditLimit(int32_t nLimit) { FWL_Error IFWL_ComboBox::EditDoClipboard(int32_t iCmd) { return static_cast(GetImpl())->EditDoClipboard(iCmd); } -FX_BOOL IFWL_ComboBox::EditRedo(const CFX_ByteStringC& bsRecord) { - return static_cast(GetImpl())->EditRedo(bsRecord); +FX_BOOL IFWL_ComboBox::EditRedo(const IFDE_TxtEdtDoRecord* pRecord) { + return static_cast(GetImpl())->EditRedo(pRecord); } -FX_BOOL IFWL_ComboBox::EditUndo(const CFX_ByteStringC& bsRecord) { - return static_cast(GetImpl())->EditUndo(bsRecord); +FX_BOOL IFWL_ComboBox::EditUndo(const IFDE_TxtEdtDoRecord* pRecord) { + return static_cast(GetImpl())->EditUndo(pRecord); } IFWL_ListBox* IFWL_ComboBox::GetListBoxt() { return static_cast(GetImpl())->GetListBoxt(); @@ -789,16 +789,15 @@ FWL_Error CFWL_ComboBoxImp::EditDoClipboard(int32_t iCmd) { return FWL_Error::Indefinite; return m_pEdit->DoClipboard(iCmd); } -FX_BOOL CFWL_ComboBoxImp::EditRedo(const CFX_ByteStringC& bsRecord) { - if (!m_pEdit) - return FALSE; - return m_pEdit->Redo(bsRecord); + +FX_BOOL CFWL_ComboBoxImp::EditRedo(const IFDE_TxtEdtDoRecord* pRecord) { + return m_pEdit && m_pEdit->Redo(pRecord); } -FX_BOOL CFWL_ComboBoxImp::EditUndo(const CFX_ByteStringC& bsRecord) { - if (!m_pEdit) - return FALSE; - return m_pEdit->Undo(bsRecord); + +FX_BOOL CFWL_ComboBoxImp::EditUndo(const IFDE_TxtEdtDoRecord* pRecord) { + return m_pEdit && m_pEdit->Undo(pRecord); } + IFWL_ListBox* CFWL_ComboBoxImp::GetListBoxt() { return m_pListBox.get(); } diff --git a/xfa/fwl/basewidget/fwl_comboboximp.h b/xfa/fwl/basewidget/fwl_comboboximp.h index 45cb47d321..42452e6871 100644 --- a/xfa/fwl/basewidget/fwl_comboboximp.h +++ b/xfa/fwl/basewidget/fwl_comboboximp.h @@ -117,8 +117,8 @@ class CFWL_ComboBoxImp : public CFWL_WidgetImp { int32_t GetEditLimit(); FWL_Error SetEditLimit(int32_t nLimit); FWL_Error EditDoClipboard(int32_t iCmd); - FX_BOOL EditRedo(const CFX_ByteStringC& bsRecord); - FX_BOOL EditUndo(const CFX_ByteStringC& bsRecord); + FX_BOOL EditRedo(const IFDE_TxtEdtDoRecord* pRecord); + FX_BOOL EditUndo(const IFDE_TxtEdtDoRecord* pRecord); IFWL_ListBox* GetListBoxt(); FX_BOOL AfterFocusShowDropList(); FWL_Error OpenDropDownList(FX_BOOL bActivate); diff --git a/xfa/fwl/basewidget/fwl_editimp.cpp b/xfa/fwl/basewidget/fwl_editimp.cpp index 1e0fede4be..2d7d50580d 100644 --- a/xfa/fwl/basewidget/fwl_editimp.cpp +++ b/xfa/fwl/basewidget/fwl_editimp.cpp @@ -148,11 +148,11 @@ FX_BOOL IFWL_Edit::Paste(const CFX_WideString& wsPaste) { FX_BOOL IFWL_Edit::Delete() { return static_cast(GetImpl())->Delete(); } -FX_BOOL IFWL_Edit::Redo(const CFX_ByteStringC& bsRecord) { - return static_cast(GetImpl())->Redo(bsRecord); +FX_BOOL IFWL_Edit::Redo(const IFDE_TxtEdtDoRecord* pRecord) { + return static_cast(GetImpl())->Redo(pRecord); } -FX_BOOL IFWL_Edit::Undo(const CFX_ByteStringC& bsRecord) { - return static_cast(GetImpl())->Undo(bsRecord); +FX_BOOL IFWL_Edit::Undo(const IFDE_TxtEdtDoRecord* pRecord) { + return static_cast(GetImpl())->Undo(pRecord); } FX_BOOL IFWL_Edit::Undo() { return static_cast(GetImpl())->Undo(); @@ -749,36 +749,32 @@ FX_BOOL CFWL_EditImp::Delete() { return TRUE; } -FX_BOOL CFWL_EditImp::Redo(const CFX_ByteStringC& bsRecord) { +FX_BOOL CFWL_EditImp::Redo(const IFDE_TxtEdtDoRecord* pRecord) { if (!m_pEdtEngine) return FALSE; if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoRedoUndo) return TRUE; - return m_pEdtEngine->Redo(bsRecord); + return m_pEdtEngine->Redo(pRecord); } -FX_BOOL CFWL_EditImp::Undo(const CFX_ByteStringC& bsRecord) { +FX_BOOL CFWL_EditImp::Undo(const IFDE_TxtEdtDoRecord* pRecord) { if (!m_pEdtEngine) return FALSE; if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoRedoUndo) return TRUE; - return m_pEdtEngine->Undo(bsRecord); + return m_pEdtEngine->Undo(pRecord); } FX_BOOL CFWL_EditImp::Undo() { if (!CanUndo()) return FALSE; - - CFX_ByteString bsRecord = m_RecordArr[m_iCurRecord--]; - return Undo(bsRecord.AsStringC()); + return Undo(m_DoRecords[m_iCurRecord--].get()); } FX_BOOL CFWL_EditImp::Redo() { if (!CanRedo()) return FALSE; - - CFX_ByteString bsRecord = m_RecordArr[++m_iCurRecord]; - return Redo(bsRecord.AsStringC()); + return Redo(m_DoRecords[++m_iCurRecord].get()); } FX_BOOL CFWL_EditImp::CanUndo() { @@ -786,7 +782,7 @@ FX_BOOL CFWL_EditImp::CanUndo() { } FX_BOOL CFWL_EditImp::CanRedo() { - return m_iCurRecord < m_RecordArr.GetSize() - 1; + return m_iCurRecord < m_DoRecords.size() - 1; } FWL_Error CFWL_EditImp::SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant) { @@ -931,8 +927,8 @@ FX_BOOL CFWL_EditImp::On_PageUnload(CFDE_TxtEdtEngine* pEdit, } void CFWL_EditImp::On_AddDoRecord(CFDE_TxtEdtEngine* pEdit, - const CFX_ByteStringC& bsDoRecord) { - AddDoRecord(bsDoRecord); + IFDE_TxtEdtDoRecord* pRecord) { + AddDoRecord(pRecord); } FX_BOOL CFWL_EditImp::On_Validate(CFDE_TxtEdtEngine* pEdit, @@ -1468,20 +1464,21 @@ FX_BOOL CFWL_EditImp::IsContentHeightOverflow() { return FALSE; return pPage->GetContentsBox().height > m_rtEngine.height + 1.0f; } -int32_t CFWL_EditImp::AddDoRecord(const CFX_ByteStringC& bsDoRecord) { - int32_t nCount = m_RecordArr.GetSize(); +int32_t CFWL_EditImp::AddDoRecord(IFDE_TxtEdtDoRecord* pRecord) { + int32_t nCount = m_DoRecords.size(); if (m_iCurRecord == nCount - 1) { if (nCount == m_iMaxRecord) { - m_RecordArr.RemoveAt(0); + m_DoRecords.pop_front(); m_iCurRecord--; } } else { - for (int32_t i = nCount - 1; i > m_iCurRecord; i--) { - m_RecordArr.RemoveAt(i); - } + m_DoRecords.erase(m_DoRecords.begin() + m_iCurRecord + 1, + m_DoRecords.end()); } - m_RecordArr.Add(CFX_ByteString(bsDoRecord)); - return m_iCurRecord = m_RecordArr.GetSize() - 1; + + m_DoRecords.push_back(std::unique_ptr(pRecord)); + m_iCurRecord = m_DoRecords.size() - 1; + return m_iCurRecord; } void CFWL_EditImp::Layout() { GetClientRect(m_rtClient); @@ -1736,10 +1733,12 @@ void CFWL_EditImp::InitCaret() { m_pCaret.reset(); } } + void CFWL_EditImp::ClearRecord() { m_iCurRecord = -1; - m_RecordArr.RemoveAll(); + m_DoRecords.clear(); } + void CFWL_EditImp::ProcessInsertError(int32_t iError) { switch (iError) { case -2: { diff --git a/xfa/fwl/basewidget/fwl_editimp.h b/xfa/fwl/basewidget/fwl_editimp.h index 9c0853b4fd..484c1f8841 100644 --- a/xfa/fwl/basewidget/fwl_editimp.h +++ b/xfa/fwl/basewidget/fwl_editimp.h @@ -7,6 +7,7 @@ #ifndef XFA_FWL_BASEWIDGET_FWL_EDITIMP_H_ #define XFA_FWL_BASEWIDGET_FWL_EDITIMP_H_ +#include #include #include @@ -15,14 +16,15 @@ #include "xfa/fwl/core/fwl_widgetimp.h" #include "xfa/fxgraphics/cfx_path.h" +class CFWL_EditImp; +class CFWL_EditImpDelegate; class CFWL_MsgActivate; class CFWL_MsgDeactivate; class CFWL_MsgMouse; -class CFWL_WidgetImpProperties; class CFWL_WidgetImpDelegate; +class CFWL_WidgetImpProperties; +class IFDE_TxtEdtDoRecord; class IFWL_Caret; -class CFWL_EditImp; -class CFWL_EditImpDelegate; class CFWL_EditImp : public CFWL_WidgetImp { public: @@ -71,8 +73,8 @@ class CFWL_EditImp : public CFWL_WidgetImp { virtual FX_BOOL Cut(CFX_WideString& wsCut); virtual FX_BOOL Paste(const CFX_WideString& wsPaste); virtual FX_BOOL Delete(); - virtual FX_BOOL Redo(const CFX_ByteStringC& bsRecord); - virtual FX_BOOL Undo(const CFX_ByteStringC& bsRecord); + virtual FX_BOOL Redo(const IFDE_TxtEdtDoRecord* pRecord); + virtual FX_BOOL Undo(const IFDE_TxtEdtDoRecord* pRecord); virtual FX_BOOL Undo(); virtual FX_BOOL Redo(); virtual FX_BOOL CanUndo(); @@ -95,8 +97,7 @@ class CFWL_EditImp : public CFWL_WidgetImp { FX_BOOL On_PageUnload(CFDE_TxtEdtEngine* pEdit, int32_t nPageIndex, int32_t nPurpose); - void On_AddDoRecord(CFDE_TxtEdtEngine* pEdit, - const CFX_ByteStringC& bsDoRecord); + void On_AddDoRecord(CFDE_TxtEdtEngine* pEdit, IFDE_TxtEdtDoRecord* pRecord); FX_BOOL On_Validate(CFDE_TxtEdtEngine* pEdit, CFX_WideString& wsText); void SetScrollOffset(FX_FLOAT fScrollOffset); FX_BOOL GetSuggestWords(CFX_PointF pointf, @@ -105,6 +106,9 @@ class CFWL_EditImp : public CFWL_WidgetImp { const CFX_ByteStringC& bsReplace); protected: + friend class CFWL_TxtEdtEventSink; + friend class CFWL_EditImpDelegate; + void DrawTextBk(CFX_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix = NULL); @@ -130,7 +134,7 @@ class CFWL_EditImp : public CFWL_WidgetImp { void ClearRecord(); FX_BOOL IsShowScrollBar(FX_BOOL bVert); FX_BOOL IsContentHeightOverflow(); - int32_t AddDoRecord(const CFX_ByteStringC& bsDoRecord); + int32_t AddDoRecord(IFDE_TxtEdtDoRecord* pRecord); void ProcessInsertError(int32_t iError); void DrawSpellCheck(CFX_Graphics* pGraphics, @@ -141,6 +145,7 @@ class CFWL_EditImp : public CFWL_WidgetImp { FX_FLOAT fOffSetX, FX_FLOAT fOffSetY); int32_t GetWordAtPoint(CFX_PointF pointf, int32_t& nCount); + CFX_RectF m_rtClient; CFX_RectF m_rtEngine; CFX_RectF m_rtStatic; @@ -162,12 +167,10 @@ class CFWL_EditImp : public CFWL_WidgetImp { std::unique_ptr m_pHorzScrollBar; std::unique_ptr m_pCaret; CFX_WideString m_wsCache; - friend class CFWL_TxtEdtEventSink; - friend class CFWL_EditImpDelegate; uint32_t m_backColor; FX_BOOL m_updateBackColor; CFX_WideString m_wsFont; - CFX_ByteStringArray m_RecordArr; + std::deque> m_DoRecords; int32_t m_iCurRecord; int32_t m_iMaxRecord; }; diff --git a/xfa/fwl/basewidget/ifwl_combobox.h b/xfa/fwl/basewidget/ifwl_combobox.h index 916e60b5bb..9755fc7686 100644 --- a/xfa/fwl/basewidget/ifwl_combobox.h +++ b/xfa/fwl/basewidget/ifwl_combobox.h @@ -11,6 +11,7 @@ #include "xfa/fxgraphics/include/cfx_graphics.h" class CFWL_WidgetImpProperties; +class IFDE_TxtEdtDoRecord; class IFWL_ComboBox; #define FWL_CLASS_ComboBox L"FWL_COMBOBOX" @@ -90,8 +91,8 @@ class IFWL_ComboBox : public IFWL_Widget { int32_t GetEditLimit(); FWL_Error SetEditLimit(int32_t nLimit); FWL_Error EditDoClipboard(int32_t iCmd); - FX_BOOL EditRedo(const CFX_ByteStringC& bsRecord); - FX_BOOL EditUndo(const CFX_ByteStringC& bsRecord); + FX_BOOL EditRedo(const IFDE_TxtEdtDoRecord* pRecord); + FX_BOOL EditUndo(const IFDE_TxtEdtDoRecord* pRecord); IFWL_ListBox* GetListBoxt(); FX_BOOL AfterFocusShowDropList(); FWL_Error OpenDropDownList(FX_BOOL bActivate); diff --git a/xfa/fwl/basewidget/ifwl_edit.h b/xfa/fwl/basewidget/ifwl_edit.h index 5650bce4dc..4cd0ab2d88 100644 --- a/xfa/fwl/basewidget/ifwl_edit.h +++ b/xfa/fwl/basewidget/ifwl_edit.h @@ -91,6 +91,7 @@ std::vector bsArraySuggestWords; END_FWL_EVENT_DEF class CFWL_WidgetImpProperties; +class IFDE_TxtEdtDoRecord; class IFWL_EditDP : public IFWL_DataProvider {}; @@ -128,8 +129,8 @@ class IFWL_Edit : public IFWL_Widget { FX_BOOL Cut(CFX_WideString& wsCut); FX_BOOL Paste(const CFX_WideString& wsPaste); FX_BOOL Delete(); - FX_BOOL Redo(const CFX_ByteStringC& bsRecord); - FX_BOOL Undo(const CFX_ByteStringC& bsRecord); + FX_BOOL Redo(const IFDE_TxtEdtDoRecord* pRecord); + FX_BOOL Undo(const IFDE_TxtEdtDoRecord* pRecord); FX_BOOL Undo(); FX_BOOL Redo(); FX_BOOL CanUndo(); diff --git a/xfa/fwl/lightwidget/cfwl_combobox.cpp b/xfa/fwl/lightwidget/cfwl_combobox.cpp index ca88a23429..d70113b18a 100644 --- a/xfa/fwl/lightwidget/cfwl_combobox.cpp +++ b/xfa/fwl/lightwidget/cfwl_combobox.cpp @@ -140,16 +140,16 @@ FWL_Error CFWL_ComboBox::EditDoClipboard(int32_t iCmd) { return static_cast(m_pIface)->EditDoClipboard(iCmd); } -FX_BOOL CFWL_ComboBox::EditRedo(const CFX_ByteStringC& bsRecord) { +FX_BOOL CFWL_ComboBox::EditRedo(const IFDE_TxtEdtDoRecord* pRecord) { if (!m_pIface) return FALSE; - return static_cast(m_pIface)->EditRedo(bsRecord); + return static_cast(m_pIface)->EditRedo(pRecord); } -FX_BOOL CFWL_ComboBox::EditUndo(const CFX_ByteStringC& bsRecord) { +FX_BOOL CFWL_ComboBox::EditUndo(const IFDE_TxtEdtDoRecord* pRecord) { if (!m_pIface) return FALSE; - return static_cast(m_pIface)->EditUndo(bsRecord); + return static_cast(m_pIface)->EditUndo(pRecord); } FWL_Error CFWL_ComboBox::SetMaxListHeight(FX_FLOAT fMaxHeight) { diff --git a/xfa/fwl/lightwidget/cfwl_combobox.h b/xfa/fwl/lightwidget/cfwl_combobox.h index 5a639e33d9..b5d0327ba9 100644 --- a/xfa/fwl/lightwidget/cfwl_combobox.h +++ b/xfa/fwl/lightwidget/cfwl_combobox.h @@ -40,8 +40,8 @@ class CFWL_ComboBox : public CFWL_Widget { int32_t GetEditLimit(); FWL_Error SetEditLimit(int32_t nLimit); FWL_Error EditDoClipboard(int32_t iCmd); - FX_BOOL EditRedo(const CFX_ByteStringC& bsRecord); - FX_BOOL EditUndo(const CFX_ByteStringC& bsRecord); + FX_BOOL EditRedo(const IFDE_TxtEdtDoRecord* pRecord); + FX_BOOL EditUndo(const IFDE_TxtEdtDoRecord* pRecord); FWL_Error SetMaxListHeight(FX_FLOAT fMaxHeight); FWL_Error SetItemData(int32_t iIndex, void* pData); void* GetItemData(int32_t iIndex); diff --git a/xfa/fwl/lightwidget/cfwl_edit.cpp b/xfa/fwl/lightwidget/cfwl_edit.cpp index f151edd7e9..f1471ea13b 100644 --- a/xfa/fwl/lightwidget/cfwl_edit.cpp +++ b/xfa/fwl/lightwidget/cfwl_edit.cpp @@ -154,16 +154,12 @@ FWL_Error CFWL_Edit::DoClipboard(int32_t iCmd) { return static_cast(m_pIface)->DoClipboard(iCmd); } -FX_BOOL CFWL_Edit::Redo(const CFX_ByteStringC& bsRecord) { - if (!m_pIface) - return FALSE; - return static_cast(m_pIface)->Redo(bsRecord); +FX_BOOL CFWL_Edit::Redo(const IFDE_TxtEdtDoRecord* pRecord) { + return m_pIface && static_cast(m_pIface)->Redo(pRecord); } -FX_BOOL CFWL_Edit::Undo(const CFX_ByteStringC& bsRecord) { - if (!m_pIface) - return FALSE; - return static_cast(m_pIface)->Undo(bsRecord); +FX_BOOL CFWL_Edit::Undo(const IFDE_TxtEdtDoRecord* pRecord) { + return m_pIface && static_cast(m_pIface)->Undo(pRecord); } FWL_Error CFWL_Edit::SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant) { diff --git a/xfa/fwl/lightwidget/cfwl_edit.h b/xfa/fwl/lightwidget/cfwl_edit.h index c7001a3166..349b380670 100644 --- a/xfa/fwl/lightwidget/cfwl_edit.h +++ b/xfa/fwl/lightwidget/cfwl_edit.h @@ -12,6 +12,7 @@ #include "xfa/fwl/lightwidget/cfwl_widget.h" class CFWL_WidgetProperties; +class IFDE_TxtEdtDoRecord; class CFWL_Edit : public CFWL_Widget { public: @@ -40,8 +41,8 @@ class CFWL_Edit : public CFWL_Widget { int32_t nLen, const CFX_WideStringC& wsReplace); FWL_Error DoClipboard(int32_t iCmd); - FX_BOOL Redo(const CFX_ByteStringC& bsRecord); - FX_BOOL Undo(const CFX_ByteStringC& bsRecord); + FX_BOOL Redo(const IFDE_TxtEdtDoRecord* pRecord); + FX_BOOL Undo(const IFDE_TxtEdtDoRecord* pRecord); FWL_Error SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant); FWL_Error SetNumberRange(int32_t iMin, int32_t iMax); FWL_Error SetBackColor(uint32_t dwColor); -- cgit v1.2.3