| 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 "fpdfsdk/fxedit/include/fxet_edit.h" | 7 #include "fpdfsdk/fxedit/include/fxet_edit.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 m_pEdit->SelectNone(); | 699 m_pEdit->SelectNone(); |
| 700 m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos); | 700 m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos); |
| 701 m_pEdit->Clear(FALSE, TRUE); | 701 m_pEdit->Clear(FALSE, TRUE); |
| 702 } | 702 } |
| 703 } | 703 } |
| 704 | 704 |
| 705 void CFXEU_Clear::Undo() { | 705 void CFXEU_Clear::Undo() { |
| 706 if (m_pEdit) { | 706 if (m_pEdit) { |
| 707 m_pEdit->SelectNone(); | 707 m_pEdit->SelectNone(); |
| 708 m_pEdit->SetCaret(m_wrSel.BeginPos); | 708 m_pEdit->SetCaret(m_wrSel.BeginPos); |
| 709 m_pEdit->InsertText(m_swText.c_str(), DEFAULT_CHARSET, FALSE, TRUE); | 709 m_pEdit->InsertText(m_swText, DEFAULT_CHARSET, FALSE, TRUE); |
| 710 m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos); | 710 m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos); |
| 711 } | 711 } |
| 712 } | 712 } |
| 713 | 713 |
| 714 CFXEU_InsertText::CFXEU_InsertText(CFX_Edit* pEdit, | 714 CFXEU_InsertText::CFXEU_InsertText(CFX_Edit* pEdit, |
| 715 const CPVT_WordPlace& wpOldPlace, | 715 const CPVT_WordPlace& wpOldPlace, |
| 716 const CPVT_WordPlace& wpNewPlace, | 716 const CPVT_WordPlace& wpNewPlace, |
| 717 const CFX_WideString& swText, | 717 const CFX_WideString& swText, |
| 718 int32_t charset) | 718 int32_t charset) |
| 719 : m_pEdit(pEdit), | 719 : m_pEdit(pEdit), |
| 720 m_wpOld(wpOldPlace), | 720 m_wpOld(wpOldPlace), |
| 721 m_wpNew(wpNewPlace), | 721 m_wpNew(wpNewPlace), |
| 722 m_swText(swText), | 722 m_swText(swText), |
| 723 m_nCharset(charset) {} | 723 m_nCharset(charset) {} |
| 724 | 724 |
| 725 CFXEU_InsertText::~CFXEU_InsertText() {} | 725 CFXEU_InsertText::~CFXEU_InsertText() {} |
| 726 | 726 |
| 727 void CFXEU_InsertText::Redo() { | 727 void CFXEU_InsertText::Redo() { |
| 728 if (m_pEdit && IsLast()) { | 728 if (m_pEdit && IsLast()) { |
| 729 m_pEdit->SelectNone(); | 729 m_pEdit->SelectNone(); |
| 730 m_pEdit->SetCaret(m_wpOld); | 730 m_pEdit->SetCaret(m_wpOld); |
| 731 m_pEdit->InsertText(m_swText.c_str(), m_nCharset, FALSE, TRUE); | 731 m_pEdit->InsertText(m_swText, m_nCharset, FALSE, TRUE); |
| 732 } | 732 } |
| 733 } | 733 } |
| 734 | 734 |
| 735 void CFXEU_InsertText::Undo() { | 735 void CFXEU_InsertText::Undo() { |
| 736 if (m_pEdit) { | 736 if (m_pEdit) { |
| 737 m_pEdit->SelectNone(); | 737 m_pEdit->SelectNone(); |
| 738 m_pEdit->SetSel(m_wpOld, m_wpNew); | 738 m_pEdit->SetSel(m_wpOld, m_wpNew); |
| 739 m_pEdit->Clear(FALSE, TRUE); | 739 m_pEdit->Clear(FALSE, TRUE); |
| 740 } | 740 } |
| 741 } | 741 } |
| (...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 | 1663 |
| 1664 if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) { | 1664 if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) { |
| 1665 wrRet.EndPos = wr2.EndPos; | 1665 wrRet.EndPos = wr2.EndPos; |
| 1666 } else { | 1666 } else { |
| 1667 wrRet.EndPos = wr1.EndPos; | 1667 wrRet.EndPos = wr1.EndPos; |
| 1668 } | 1668 } |
| 1669 | 1669 |
| 1670 return wrRet; | 1670 return wrRet; |
| 1671 } | 1671 } |
| 1672 | 1672 |
| 1673 void CFX_Edit::SetText(const FX_WCHAR* text) { | 1673 void CFX_Edit::SetText(const CFX_WideString& sText) { |
| 1674 Empty(); | 1674 Empty(); |
| 1675 DoInsertText(CPVT_WordPlace(0, 0, -1), text, DEFAULT_CHARSET); | 1675 DoInsertText(CPVT_WordPlace(0, 0, -1), sText, DEFAULT_CHARSET); |
| 1676 Paint(); | 1676 Paint(); |
| 1677 } | 1677 } |
| 1678 | 1678 |
| 1679 FX_BOOL CFX_Edit::InsertWord(uint16_t word, int32_t charset) { | 1679 FX_BOOL CFX_Edit::InsertWord(uint16_t word, int32_t charset) { |
| 1680 return InsertWord(word, charset, nullptr, TRUE, TRUE); | 1680 return InsertWord(word, charset, nullptr, TRUE, TRUE); |
| 1681 } | 1681 } |
| 1682 | 1682 |
| 1683 FX_BOOL CFX_Edit::InsertReturn() { | 1683 FX_BOOL CFX_Edit::InsertReturn() { |
| 1684 return InsertReturn(nullptr, nullptr, TRUE, TRUE); | 1684 return InsertReturn(nullptr, nullptr, TRUE, TRUE); |
| 1685 } | 1685 } |
| 1686 | 1686 |
| 1687 FX_BOOL CFX_Edit::Backspace() { | 1687 FX_BOOL CFX_Edit::Backspace() { |
| 1688 return Backspace(TRUE, TRUE); | 1688 return Backspace(TRUE, TRUE); |
| 1689 } | 1689 } |
| 1690 | 1690 |
| 1691 FX_BOOL CFX_Edit::Delete() { | 1691 FX_BOOL CFX_Edit::Delete() { |
| 1692 return Delete(TRUE, TRUE); | 1692 return Delete(TRUE, TRUE); |
| 1693 } | 1693 } |
| 1694 | 1694 |
| 1695 FX_BOOL CFX_Edit::Clear() { | 1695 FX_BOOL CFX_Edit::Clear() { |
| 1696 return Clear(TRUE, TRUE); | 1696 return Clear(TRUE, TRUE); |
| 1697 } | 1697 } |
| 1698 | 1698 |
| 1699 FX_BOOL CFX_Edit::InsertText(const FX_WCHAR* text, int32_t charset) { | 1699 FX_BOOL CFX_Edit::InsertText(const CFX_WideString& sText, int32_t charset) { |
| 1700 return InsertText(text, charset, TRUE, TRUE); | 1700 return InsertText(sText, charset, TRUE, TRUE); |
| 1701 } | 1701 } |
| 1702 | 1702 |
| 1703 FX_FLOAT CFX_Edit::GetFontSize() const { | 1703 FX_FLOAT CFX_Edit::GetFontSize() const { |
| 1704 return m_pVT->GetFontSize(); | 1704 return m_pVT->GetFontSize(); |
| 1705 } | 1705 } |
| 1706 | 1706 |
| 1707 uint16_t CFX_Edit::GetPasswordChar() const { | 1707 uint16_t CFX_Edit::GetPasswordChar() const { |
| 1708 return m_pVT->GetPasswordChar(); | 1708 return m_pVT->GetPasswordChar(); |
| 1709 } | 1709 } |
| 1710 | 1710 |
| (...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2678 SetCaretOrigin(); | 2678 SetCaretOrigin(); |
| 2679 SetCaretInfo(); | 2679 SetCaretInfo(); |
| 2680 } | 2680 } |
| 2681 | 2681 |
| 2682 if (m_bOprNotify && m_pOprNotify) | 2682 if (m_bOprNotify && m_pOprNotify) |
| 2683 m_pOprNotify->OnClear(m_wpCaret, m_wpOldCaret); | 2683 m_pOprNotify->OnClear(m_wpCaret, m_wpOldCaret); |
| 2684 | 2684 |
| 2685 return TRUE; | 2685 return TRUE; |
| 2686 } | 2686 } |
| 2687 | 2687 |
| 2688 FX_BOOL CFX_Edit::InsertText(const FX_WCHAR* text, | 2688 FX_BOOL CFX_Edit::InsertText(const CFX_WideString& sText, |
| 2689 int32_t charset, | 2689 int32_t charset, |
| 2690 FX_BOOL bAddUndo, | 2690 FX_BOOL bAddUndo, |
| 2691 FX_BOOL bPaint) { | 2691 FX_BOOL bPaint) { |
| 2692 if (IsTextOverflow()) | 2692 if (IsTextOverflow()) |
| 2693 return FALSE; | 2693 return FALSE; |
| 2694 | 2694 |
| 2695 m_pVT->UpdateWordPlace(m_wpCaret); | 2695 m_pVT->UpdateWordPlace(m_wpCaret); |
| 2696 SetCaret(DoInsertText(m_wpCaret, text, charset)); | 2696 SetCaret(DoInsertText(m_wpCaret, sText, charset)); |
| 2697 m_SelState.Set(m_wpCaret, m_wpCaret); | 2697 m_SelState.Set(m_wpCaret, m_wpCaret); |
| 2698 if (m_wpCaret == m_wpOldCaret) |
| 2699 return FALSE; |
| 2698 | 2700 |
| 2699 if (m_wpCaret != m_wpOldCaret) { | 2701 if (bAddUndo && m_bEnableUndo) { |
| 2700 if (bAddUndo && m_bEnableUndo) { | 2702 AddEditUndoItem( |
| 2701 AddEditUndoItem( | 2703 new CFXEU_InsertText(this, m_wpOldCaret, m_wpCaret, sText, charset)); |
| 2702 new CFXEU_InsertText(this, m_wpOldCaret, m_wpCaret, text, charset)); | 2704 } |
| 2703 } | |
| 2704 | 2705 |
| 2705 if (bPaint) | 2706 if (bPaint) |
| 2706 PaintInsertText(m_wpOldCaret, m_wpCaret); | 2707 PaintInsertText(m_wpOldCaret, m_wpCaret); |
| 2707 | 2708 |
| 2708 if (m_bOprNotify && m_pOprNotify) | 2709 if (m_bOprNotify && m_pOprNotify) |
| 2709 m_pOprNotify->OnInsertText(m_wpCaret, m_wpOldCaret); | 2710 m_pOprNotify->OnInsertText(m_wpCaret, m_wpOldCaret); |
| 2710 | 2711 |
| 2711 return TRUE; | 2712 return TRUE; |
| 2712 } | |
| 2713 return FALSE; | |
| 2714 } | 2713 } |
| 2715 | 2714 |
| 2716 void CFX_Edit::PaintInsertText(const CPVT_WordPlace& wpOld, | 2715 void CFX_Edit::PaintInsertText(const CPVT_WordPlace& wpOld, |
| 2717 const CPVT_WordPlace& wpNew) { | 2716 const CPVT_WordPlace& wpNew) { |
| 2718 if (m_pVT->IsValid()) { | 2717 if (m_pVT->IsValid()) { |
| 2719 RearrangePart(CPVT_WordRange(wpOld, wpNew)); | 2718 RearrangePart(CPVT_WordRange(wpOld, wpNew)); |
| 2720 ScrollToCaret(); | 2719 ScrollToCaret(); |
| 2721 Refresh(); | 2720 Refresh(); |
| 2722 SetCaretOrigin(); | 2721 SetCaretOrigin(); |
| 2723 SetCaretInfo(); | 2722 SetCaretInfo(); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2876 pIterator->SetAt(place); | 2875 pIterator->SetAt(place); |
| 2877 CPVT_Line line; | 2876 CPVT_Line line; |
| 2878 pIterator->GetLine(line); | 2877 pIterator->GetLine(line); |
| 2879 | 2878 |
| 2880 pIterator->SetAt(wpOld); | 2879 pIterator->SetAt(wpOld); |
| 2881 | 2880 |
| 2882 return line.ptLine.y + line.fLineDescent; | 2881 return line.ptLine.y + line.fLineDescent; |
| 2883 } | 2882 } |
| 2884 | 2883 |
| 2885 CPVT_WordPlace CFX_Edit::DoInsertText(const CPVT_WordPlace& place, | 2884 CPVT_WordPlace CFX_Edit::DoInsertText(const CPVT_WordPlace& place, |
| 2886 const FX_WCHAR* text, | 2885 const CFX_WideString& sText, |
| 2887 int32_t charset) { | 2886 int32_t charset) { |
| 2888 CPVT_WordPlace wp = place; | 2887 CPVT_WordPlace wp = place; |
| 2889 | 2888 |
| 2890 if (m_pVT->IsValid()) { | 2889 if (m_pVT->IsValid()) { |
| 2891 CFX_WideString sText = text; | |
| 2892 | |
| 2893 for (int32_t i = 0, sz = sText.GetLength(); i < sz; i++) { | 2890 for (int32_t i = 0, sz = sText.GetLength(); i < sz; i++) { |
| 2894 uint16_t word = sText[i]; | 2891 uint16_t word = sText[i]; |
| 2895 switch (word) { | 2892 switch (word) { |
| 2896 case 0x0D: | 2893 case 0x0D: |
| 2897 wp = m_pVT->InsertSection(wp, nullptr, nullptr); | 2894 wp = m_pVT->InsertSection(wp, nullptr, nullptr); |
| 2898 if (sText[i + 1] == 0x0A) | 2895 if (sText[i + 1] == 0x0A) |
| 2899 i++; | 2896 i++; |
| 2900 break; | 2897 break; |
| 2901 case 0x0A: | 2898 case 0x0A: |
| 2902 wp = m_pVT->InsertSection(wp, nullptr, nullptr); | 2899 wp = m_pVT->InsertSection(wp, nullptr, nullptr); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3056 int32_t CFX_Edit_RectArray::GetSize() const { | 3053 int32_t CFX_Edit_RectArray::GetSize() const { |
| 3057 return m_Rects.GetSize(); | 3054 return m_Rects.GetSize(); |
| 3058 } | 3055 } |
| 3059 | 3056 |
| 3060 CFX_FloatRect* CFX_Edit_RectArray::GetAt(int32_t nIndex) const { | 3057 CFX_FloatRect* CFX_Edit_RectArray::GetAt(int32_t nIndex) const { |
| 3061 if (nIndex < 0 || nIndex >= m_Rects.GetSize()) | 3058 if (nIndex < 0 || nIndex >= m_Rects.GetSize()) |
| 3062 return nullptr; | 3059 return nullptr; |
| 3063 | 3060 |
| 3064 return m_Rects.GetAt(nIndex); | 3061 return m_Rects.GetAt(nIndex); |
| 3065 } | 3062 } |
| OLD | NEW |