Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: xfa/fde/cfde_txtedtengine.cpp

Issue 2208423002: Use smart pointers for class owned pointers under xfa/fde (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: one more change Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fde/cfde_txtedtengine.h ('k') | xfa/fde/cfde_txtedtpage.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 nLineEnd(0), 43 nLineEnd(0),
44 nHorzScale(100), 44 nHorzScale(100),
45 fCharSpace(0), 45 fCharSpace(0),
46 pEventSink(nullptr) {} 46 pEventSink(nullptr) {}
47 47
48 FDE_TXTEDT_TEXTCHANGE_INFO::FDE_TXTEDT_TEXTCHANGE_INFO() {} 48 FDE_TXTEDT_TEXTCHANGE_INFO::FDE_TXTEDT_TEXTCHANGE_INFO() {}
49 49
50 FDE_TXTEDT_TEXTCHANGE_INFO::~FDE_TXTEDT_TEXTCHANGE_INFO() {} 50 FDE_TXTEDT_TEXTCHANGE_INFO::~FDE_TXTEDT_TEXTCHANGE_INFO() {}
51 51
52 CFDE_TxtEdtEngine::CFDE_TxtEdtEngine() 52 CFDE_TxtEdtEngine::CFDE_TxtEdtEngine()
53 : m_pTextBreak(nullptr), 53 : m_pTxtBuf(new CFDE_TxtEdtBuf()),
54 m_nPageLineCount(20), 54 m_nPageLineCount(20),
55 m_nLineCount(0), 55 m_nLineCount(0),
56 m_nAnchorPos(-1), 56 m_nAnchorPos(-1),
57 m_nLayoutPos(0), 57 m_nLayoutPos(0),
58 m_fCaretPosReserve(0.0), 58 m_fCaretPosReserve(0.0),
59 m_nCaret(0), 59 m_nCaret(0),
60 m_bBefore(TRUE), 60 m_bBefore(TRUE),
61 m_nCaretPage(0), 61 m_nCaretPage(0),
62 m_dwFindFlags(0), 62 m_dwFindFlags(0),
63 m_bLock(FALSE), 63 m_bLock(FALSE),
64 m_nLimit(0), 64 m_nLimit(0),
65 m_wcAliasChar(L'*'), 65 m_wcAliasChar(L'*'),
66 m_nFirstLineEnd(FDE_TXTEDIT_LINEEND_Auto), 66 m_nFirstLineEnd(FDE_TXTEDIT_LINEEND_Auto),
67 m_bAutoLineEnd(TRUE), 67 m_bAutoLineEnd(TRUE),
68 m_wLineEnd(kUnicodeParagraphSeparator) { 68 m_wLineEnd(kUnicodeParagraphSeparator) {
69 FXSYS_memset(&m_rtCaret, 0, sizeof(CFX_RectF)); 69 FXSYS_memset(&m_rtCaret, 0, sizeof(CFX_RectF));
70 m_pTxtBuf = new CFDE_TxtEdtBuf();
71 m_bAutoLineEnd = (m_Param.nLineEnd == FDE_TXTEDIT_LINEEND_Auto); 70 m_bAutoLineEnd = (m_Param.nLineEnd == FDE_TXTEDIT_LINEEND_Auto);
72 } 71 }
73 72
74 CFDE_TxtEdtEngine::~CFDE_TxtEdtEngine() { 73 CFDE_TxtEdtEngine::~CFDE_TxtEdtEngine() {
75 delete m_pTxtBuf;
76 delete m_pTextBreak;
77 RemoveAllParags(); 74 RemoveAllParags();
78 RemoveAllPages(); 75 RemoveAllPages();
79 m_Param.pEventSink = nullptr; 76 m_Param.pEventSink = nullptr;
80 ClearSelection(); 77 ClearSelection();
81 } 78 }
82 79
83 void CFDE_TxtEdtEngine::SetEditParams(const FDE_TXTEDTPARAMS& params) { 80 void CFDE_TxtEdtEngine::SetEditParams(const FDE_TXTEDTPARAMS& params) {
84 if (!m_pTextBreak) 81 if (!m_pTextBreak)
85 m_pTextBreak = new CFX_TxtBreak(FX_TXTBREAKPOLICY_None); 82 m_pTextBreak.reset(new CFX_TxtBreak(FX_TXTBREAKPOLICY_None));
86 83
87 FXSYS_memcpy(&m_Param, &params, sizeof(FDE_TXTEDTPARAMS)); 84 FXSYS_memcpy(&m_Param, &params, sizeof(FDE_TXTEDTPARAMS));
88 m_wLineEnd = params.wLineBreakChar; 85 m_wLineEnd = params.wLineBreakChar;
89 m_bAutoLineEnd = (m_Param.nLineEnd == FDE_TXTEDIT_LINEEND_Auto); 86 m_bAutoLineEnd = (m_Param.nLineEnd == FDE_TXTEDIT_LINEEND_Auto);
90 UpdateTxtBreak(); 87 UpdateTxtBreak();
91 } 88 }
92 89
93 FDE_TXTEDTPARAMS* CFDE_TxtEdtEngine::GetEditParams() { 90 FDE_TXTEDTPARAMS* CFDE_TxtEdtEngine::GetEditParams() {
94 return &m_Param; 91 return &m_Param;
95 } 92 }
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 } 717 }
721 m_rtCaret.Set(0, 0, 1, m_Param.fFontSize); 718 m_rtCaret.Set(0, 0, 1, m_Param.fFontSize);
722 Unlock(); 719 Unlock();
723 } 720 }
724 721
725 FX_BOOL CFDE_TxtEdtEngine::Optimize(IFX_Pause* pPause) { 722 FX_BOOL CFDE_TxtEdtEngine::Optimize(IFX_Pause* pPause) {
726 return m_pTxtBuf->Optimize(pPause); 723 return m_pTxtBuf->Optimize(pPause);
727 } 724 }
728 725
729 CFDE_TxtEdtBuf* CFDE_TxtEdtEngine::GetTextBuf() const { 726 CFDE_TxtEdtBuf* CFDE_TxtEdtEngine::GetTextBuf() const {
730 return m_pTxtBuf; 727 return m_pTxtBuf.get();
731 } 728 }
732 729
733 int32_t CFDE_TxtEdtEngine::GetTextBufLength() const { 730 int32_t CFDE_TxtEdtEngine::GetTextBufLength() const {
734 return m_pTxtBuf->GetTextLength() - 1; 731 return m_pTxtBuf->GetTextLength() - 1;
735 } 732 }
736 733
737 CFX_TxtBreak* CFDE_TxtEdtEngine::GetTextBreak() const { 734 CFX_TxtBreak* CFDE_TxtEdtEngine::GetTextBreak() const {
738 return m_pTextBreak; 735 return m_pTextBreak.get();
739 } 736 }
740 737
741 int32_t CFDE_TxtEdtEngine::GetLineCount() const { 738 int32_t CFDE_TxtEdtEngine::GetLineCount() const {
742 return m_nLineCount; 739 return m_nLineCount;
743 } 740 }
744 741
745 int32_t CFDE_TxtEdtEngine::GetPageLineCount() const { 742 int32_t CFDE_TxtEdtEngine::GetPageLineCount() const {
746 return m_nPageLineCount; 743 return m_nPageLineCount;
747 } 744 }
748 745
749 int32_t CFDE_TxtEdtEngine::CountParags() const { 746 int32_t CFDE_TxtEdtEngine::CountParags() const {
750 return m_ParagPtrArray.GetSize(); 747 return m_ParagPtrArray.GetSize();
751 } 748 }
752 749
753 CFDE_TxtEdtParag* CFDE_TxtEdtEngine::GetParag(int32_t nParagIndex) const { 750 CFDE_TxtEdtParag* CFDE_TxtEdtEngine::GetParag(int32_t nParagIndex) const {
754 return m_ParagPtrArray[nParagIndex]; 751 return m_ParagPtrArray[nParagIndex];
755 } 752 }
756 753
757 IFX_CharIter* CFDE_TxtEdtEngine::CreateCharIter() { 754 IFX_CharIter* CFDE_TxtEdtEngine::CreateCharIter() {
758 if (!m_pTxtBuf) { 755 if (!m_pTxtBuf)
759 return nullptr; 756 return nullptr;
760 } 757 return new CFDE_TxtEdtBufIter(m_pTxtBuf.get());
761 return new CFDE_TxtEdtBufIter(static_cast<CFDE_TxtEdtBuf*>(m_pTxtBuf));
762 } 758 }
763 759
764 int32_t CFDE_TxtEdtEngine::Line2Parag(int32_t nStartParag, 760 int32_t CFDE_TxtEdtEngine::Line2Parag(int32_t nStartParag,
765 int32_t nStartLineofParag, 761 int32_t nStartLineofParag,
766 int32_t nLineIndex, 762 int32_t nLineIndex,
767 int32_t& nStartLine) const { 763 int32_t& nStartLine) const {
768 int32_t nLineTotal = nStartLineofParag; 764 int32_t nLineTotal = nStartLineofParag;
769 int32_t nCount = m_ParagPtrArray.GetSize(); 765 int32_t nCount = m_ParagPtrArray.GetSize();
770 CFDE_TxtEdtParag* pParag = nullptr; 766 CFDE_TxtEdtParag* pParag = nullptr;
771 int32_t i = nStartParag; 767 int32_t i = nStartParag;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 m_nCaret = 0; 975 m_nCaret = 0;
980 m_pTxtBuf->Clear(FALSE); 976 m_pTxtBuf->Clear(FALSE);
981 m_nCaret = 0; 977 m_nCaret = 0;
982 } 978 }
983 979
984 void CFDE_TxtEdtEngine::RebuildParagraphs() { 980 void CFDE_TxtEdtEngine::RebuildParagraphs() {
985 RemoveAllParags(); 981 RemoveAllParags();
986 FX_WCHAR wChar = L' '; 982 FX_WCHAR wChar = L' ';
987 int32_t nParagStart = 0; 983 int32_t nParagStart = 0;
988 int32_t nIndex = 0; 984 int32_t nIndex = 0;
989 std::unique_ptr<IFX_CharIter> pIter( 985 std::unique_ptr<IFX_CharIter> pIter(new CFDE_TxtEdtBufIter(m_pTxtBuf.get()));
990 new CFDE_TxtEdtBufIter(static_cast<CFDE_TxtEdtBuf*>(m_pTxtBuf)));
991 pIter->SetAt(0); 986 pIter->SetAt(0);
992 do { 987 do {
993 wChar = pIter->GetChar(); 988 wChar = pIter->GetChar();
994 nIndex = pIter->GetAt(); 989 nIndex = pIter->GetAt();
995 if (wChar == m_wLineEnd) { 990 if (wChar == m_wLineEnd) {
996 CFDE_TxtEdtParag* pParag = new CFDE_TxtEdtParag(this); 991 CFDE_TxtEdtParag* pParag = new CFDE_TxtEdtParag(this);
997 pParag->SetStartIndex(nParagStart); 992 pParag->SetStartIndex(nParagStart);
998 pParag->SetTextLength(nIndex - nParagStart + 1); 993 pParag->SetTextLength(nIndex - nParagStart + 1);
999 pParag->SetLineCount(-1); 994 pParag->SetLineCount(-1);
1000 m_ParagPtrArray.Add(pParag); 995 m_ParagPtrArray.Add(pParag);
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 m_SelRangePtrArr.RemoveAt(nCountRange); 1622 m_SelRangePtrArr.RemoveAt(nCountRange);
1628 DeleteRange_DoRecord(nSelStart, nSelCount, TRUE); 1623 DeleteRange_DoRecord(nSelStart, nSelCount, TRUE);
1629 } 1624 }
1630 ClearSelection(); 1625 ClearSelection();
1631 m_Param.pEventSink->On_TextChanged(this, m_ChangeInfo); 1626 m_Param.pEventSink->On_TextChanged(this, m_ChangeInfo);
1632 m_Param.pEventSink->On_SelChanged(this); 1627 m_Param.pEventSink->On_SelChanged(this);
1633 SetCaretPos(nSelStart, TRUE); 1628 SetCaretPos(nSelStart, TRUE);
1634 return; 1629 return;
1635 } 1630 }
1636 } 1631 }
OLDNEW
« no previous file with comments | « xfa/fde/cfde_txtedtengine.h ('k') | xfa/fde/cfde_txtedtpage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698