John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dsinclair | 0bb385b | 2016-09-29 17:03:59 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/fxedit/fxet_edit.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 8 | |
Lei Zhang | 375a864 | 2016-01-11 11:59:17 -0800 | [diff] [blame] | 9 | #include <algorithm> |
thestig | d4c34f2 | 2016-09-28 17:04:51 -0700 | [diff] [blame] | 10 | #include <memory> |
Henrique Nakashima | 2e2da13 | 2017-06-27 13:43:22 -0400 | [diff] [blame] | 11 | #include <sstream> |
thestig | d4c34f2 | 2016-09-28 17:04:51 -0700 | [diff] [blame] | 12 | #include <utility> |
Lei Zhang | 375a864 | 2016-01-11 11:59:17 -0800 | [diff] [blame] | 13 | |
dsinclair | bc5e6d2 | 2016-10-04 11:08:49 -0700 | [diff] [blame] | 14 | #include "core/fpdfapi/font/cpdf_font.h" |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 15 | #include "core/fpdfapi/page/cpdf_pageobject.h" |
| 16 | #include "core/fpdfapi/page/cpdf_pageobjectholder.h" |
| 17 | #include "core/fpdfapi/page/cpdf_pathobject.h" |
| 18 | #include "core/fpdfapi/page/cpdf_textobject.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 19 | #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
dsinclair | 69d9c68 | 2016-10-04 12:18:35 -0700 | [diff] [blame] | 20 | #include "core/fpdfapi/render/cpdf_renderoptions.h" |
| 21 | #include "core/fpdfapi/render/cpdf_textrenderer.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 22 | #include "core/fpdfdoc/cpvt_section.h" |
| 23 | #include "core/fpdfdoc/cpvt_word.h" |
| 24 | #include "core/fpdfdoc/ipvt_fontmap.h" |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 25 | #include "core/fxcrt/fx_codepage.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 26 | #include "core/fxge/cfx_graphstatedata.h" |
| 27 | #include "core/fxge/cfx_pathdata.h" |
| 28 | #include "core/fxge/cfx_renderdevice.h" |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 29 | #include "fpdfsdk/cfx_systemhandler.h" |
dsinclair | 0bb385b | 2016-09-29 17:03:59 -0700 | [diff] [blame] | 30 | #include "fpdfsdk/fxedit/fx_edit.h" |
Lei Zhang | 633a3b7 | 2017-06-02 15:27:22 -0700 | [diff] [blame] | 31 | #include "fpdfsdk/pdfwindow/cpwl_edit.h" |
| 32 | #include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h" |
Dan Sinclair | 0fdd1ae | 2017-07-05 16:00:48 -0400 | [diff] [blame] | 33 | #include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h" |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 34 | #include "third_party/base/ptr_util.h" |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 35 | #include "third_party/base/stl_util.h" |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 36 | |
dsinclair | 8f4bf9a | 2016-05-04 13:51:51 -0700 | [diff] [blame] | 37 | namespace { |
| 38 | |
| 39 | const int kEditUndoMaxItems = 10000; |
| 40 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 41 | void DrawTextString(CFX_RenderDevice* pDevice, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 42 | const CFX_PointF& pt, |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 43 | CPDF_Font* pFont, |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 44 | float fFontSize, |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 45 | CFX_Matrix* pUser2Device, |
| 46 | const CFX_ByteString& str, |
| 47 | FX_ARGB crTextFill, |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 48 | int32_t nHorzScale) { |
Dan Sinclair | a0061af | 2017-02-23 09:25:17 -0500 | [diff] [blame] | 49 | CFX_PointF pos = pUser2Device->Transform(pt); |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 50 | |
| 51 | if (pFont) { |
| 52 | if (nHorzScale != 100) { |
| 53 | CFX_Matrix mt(nHorzScale / 100.0f, 0, 0, 1, 0, 0); |
| 54 | mt.Concat(*pUser2Device); |
| 55 | |
| 56 | CPDF_RenderOptions ro; |
| 57 | ro.m_Flags = RENDER_CLEARTYPE; |
Dan Sinclair | f55e72e | 2017-07-13 14:53:28 -0400 | [diff] [blame] | 58 | ro.m_ColorMode = CPDF_RenderOptions::kNormal; |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 59 | |
Dan Sinclair | a0061af | 2017-02-23 09:25:17 -0500 | [diff] [blame] | 60 | CPDF_TextRenderer::DrawTextString(pDevice, pos.x, pos.y, pFont, fFontSize, |
| 61 | &mt, str, crTextFill, nullptr, &ro); |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 62 | } else { |
| 63 | CPDF_RenderOptions ro; |
| 64 | ro.m_Flags = RENDER_CLEARTYPE; |
Dan Sinclair | f55e72e | 2017-07-13 14:53:28 -0400 | [diff] [blame] | 65 | ro.m_ColorMode = CPDF_RenderOptions::kNormal; |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 66 | |
Dan Sinclair | a0061af | 2017-02-23 09:25:17 -0500 | [diff] [blame] | 67 | CPDF_TextRenderer::DrawTextString(pDevice, pos.x, pos.y, pFont, fFontSize, |
| 68 | pUser2Device, str, crTextFill, nullptr, |
| 69 | &ro); |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
dsinclair | 8f4bf9a | 2016-05-04 13:51:51 -0700 | [diff] [blame] | 74 | } // namespace |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 75 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 76 | CFX_Edit_Iterator::CFX_Edit_Iterator(CFX_Edit* pEdit, |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 77 | CPDF_VariableText::Iterator* pVTIterator) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 78 | : m_pEdit(pEdit), m_pVTIterator(pVTIterator) {} |
| 79 | |
| 80 | CFX_Edit_Iterator::~CFX_Edit_Iterator() {} |
| 81 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 82 | bool CFX_Edit_Iterator::NextWord() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | return m_pVTIterator->NextWord(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 84 | } |
| 85 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 86 | bool CFX_Edit_Iterator::PrevWord() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | return m_pVTIterator->PrevWord(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 88 | } |
| 89 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 90 | bool CFX_Edit_Iterator::GetWord(CPVT_Word& word) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 91 | ASSERT(m_pEdit); |
| 92 | |
| 93 | if (m_pVTIterator->GetWord(word)) { |
| 94 | word.ptWord = m_pEdit->VTToEdit(word.ptWord); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 95 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 97 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 98 | } |
| 99 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 100 | bool CFX_Edit_Iterator::GetLine(CPVT_Line& line) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 101 | ASSERT(m_pEdit); |
| 102 | |
| 103 | if (m_pVTIterator->GetLine(line)) { |
| 104 | line.ptLine = m_pEdit->VTToEdit(line.ptLine); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 105 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 106 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 107 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 110 | void CFX_Edit_Iterator::SetAt(int32_t nWordIndex) { |
| 111 | m_pVTIterator->SetAt(nWordIndex); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 114 | void CFX_Edit_Iterator::SetAt(const CPVT_WordPlace& place) { |
| 115 | m_pVTIterator->SetAt(place); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 118 | const CPVT_WordPlace& CFX_Edit_Iterator::GetAt() const { |
| 119 | return m_pVTIterator->GetAt(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 120 | } |
| 121 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 122 | CFX_Edit_Provider::CFX_Edit_Provider(IPVT_FontMap* pFontMap) |
| 123 | : CPDF_VariableText::Provider(pFontMap), m_pFontMap(pFontMap) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 124 | ASSERT(m_pFontMap); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 127 | CFX_Edit_Provider::~CFX_Edit_Provider() {} |
| 128 | |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 129 | IPVT_FontMap* CFX_Edit_Provider::GetFontMap() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 130 | return m_pFontMap; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 131 | } |
| 132 | |
npm | 41d6bbe | 2016-09-14 11:54:44 -0700 | [diff] [blame] | 133 | int32_t CFX_Edit_Provider::GetCharWidth(int32_t nFontIndex, uint16_t word) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 134 | if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 135 | uint32_t charcode = word; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 136 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 137 | if (pPDFFont->IsUnicodeCompatible()) |
| 138 | charcode = pPDFFont->CharCodeFromUnicode(word); |
| 139 | else |
| 140 | charcode = m_pFontMap->CharCodeFromUnicode(nFontIndex, word); |
| 141 | |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 142 | if (charcode != CPDF_Font::kInvalidCharCode) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 143 | return pPDFFont->GetCharWidthF(charcode); |
| 144 | } |
| 145 | |
| 146 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 149 | int32_t CFX_Edit_Provider::GetTypeAscent(int32_t nFontIndex) { |
| 150 | if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) |
| 151 | return pPDFFont->GetTypeAscent(); |
| 152 | |
| 153 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 156 | int32_t CFX_Edit_Provider::GetTypeDescent(int32_t nFontIndex) { |
| 157 | if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) |
| 158 | return pPDFFont->GetTypeDescent(); |
| 159 | |
| 160 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 163 | int32_t CFX_Edit_Provider::GetWordFontIndex(uint16_t word, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 164 | int32_t charset, |
| 165 | int32_t nFontIndex) { |
| 166 | return m_pFontMap->GetWordFontIndex(word, charset, nFontIndex); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 169 | int32_t CFX_Edit_Provider::GetDefaultFontIndex() { |
| 170 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 171 | } |
| 172 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 173 | bool CFX_Edit_Provider::IsLatinWord(uint16_t word) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 174 | return FX_EDIT_ISLATINWORD(word); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 177 | CFX_Edit_Refresh::CFX_Edit_Refresh() {} |
| 178 | |
| 179 | CFX_Edit_Refresh::~CFX_Edit_Refresh() {} |
| 180 | |
| 181 | void CFX_Edit_Refresh::BeginRefresh() { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 182 | m_RefreshRects.Clear(); |
| 183 | m_OldLineRects = std::move(m_NewLineRects); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 186 | void CFX_Edit_Refresh::Push(const CPVT_WordRange& linerange, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 187 | const CFX_FloatRect& rect) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 188 | m_NewLineRects.Add(linerange, rect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 191 | void CFX_Edit_Refresh::NoAnalyse() { |
| 192 | { |
| 193 | for (int32_t i = 0, sz = m_OldLineRects.GetSize(); i < sz; i++) |
| 194 | if (CFX_Edit_LineRect* pOldRect = m_OldLineRects.GetAt(i)) |
| 195 | m_RefreshRects.Add(pOldRect->m_rcLine); |
| 196 | } |
| 197 | |
| 198 | { |
| 199 | for (int32_t i = 0, sz = m_NewLineRects.GetSize(); i < sz; i++) |
| 200 | if (CFX_Edit_LineRect* pNewRect = m_NewLineRects.GetAt(i)) |
| 201 | m_RefreshRects.Add(pNewRect->m_rcLine); |
| 202 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 205 | const CFX_Edit_RectArray* CFX_Edit_Refresh::GetRefreshRects() const { |
| 206 | return &m_RefreshRects; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 209 | void CFX_Edit_Refresh::EndRefresh() { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 210 | m_RefreshRects.Clear(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 213 | CFX_Edit_Undo::CFX_Edit_Undo(int32_t nBufsize) |
| 214 | : m_nCurUndoPos(0), |
| 215 | m_nBufSize(nBufsize), |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 216 | m_bWorking(false) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 217 | |
| 218 | CFX_Edit_Undo::~CFX_Edit_Undo() { |
| 219 | Reset(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 220 | } |
| 221 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 222 | bool CFX_Edit_Undo::CanUndo() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 223 | return m_nCurUndoPos > 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 226 | void CFX_Edit_Undo::Undo() { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 227 | m_bWorking = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 228 | if (m_nCurUndoPos > 0) { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 229 | m_UndoItemStack[m_nCurUndoPos - 1]->Undo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 230 | m_nCurUndoPos--; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 231 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 232 | m_bWorking = false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 233 | } |
| 234 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 235 | bool CFX_Edit_Undo::CanRedo() const { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 236 | return m_nCurUndoPos < m_UndoItemStack.size(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 239 | void CFX_Edit_Undo::Redo() { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 240 | m_bWorking = true; |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 241 | if (m_nCurUndoPos < m_UndoItemStack.size()) { |
| 242 | m_UndoItemStack[m_nCurUndoPos]->Redo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 243 | m_nCurUndoPos++; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 244 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 245 | m_bWorking = false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 248 | void CFX_Edit_Undo::AddItem(std::unique_ptr<IFX_Edit_UndoItem> pItem) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 249 | ASSERT(!m_bWorking); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 250 | ASSERT(pItem); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 251 | ASSERT(m_nBufSize > 1); |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 252 | if (m_nCurUndoPos < m_UndoItemStack.size()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 253 | RemoveTails(); |
| 254 | |
Lei Zhang | 1a89e36 | 2017-03-23 15:27:25 -0700 | [diff] [blame] | 255 | if (m_UndoItemStack.size() >= m_nBufSize) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 256 | RemoveHeads(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 257 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 258 | m_UndoItemStack.push_back(std::move(pItem)); |
| 259 | m_nCurUndoPos = m_UndoItemStack.size(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 262 | void CFX_Edit_Undo::RemoveHeads() { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 263 | ASSERT(m_UndoItemStack.size() > 1); |
| 264 | m_UndoItemStack.pop_front(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 267 | void CFX_Edit_Undo::RemoveTails() { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 268 | while (m_UndoItemStack.size() > m_nCurUndoPos) |
| 269 | m_UndoItemStack.pop_back(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | void CFX_Edit_Undo::Reset() { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 273 | m_UndoItemStack.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 274 | m_nCurUndoPos = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 275 | } |
| 276 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 277 | CFX_Edit_UndoItem::CFX_Edit_UndoItem() : m_bFirst(true), m_bLast(true) {} |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 278 | |
| 279 | CFX_Edit_UndoItem::~CFX_Edit_UndoItem() {} |
| 280 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 281 | CFX_WideString CFX_Edit_UndoItem::GetUndoTitle() const { |
| 282 | return CFX_WideString(); |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 283 | } |
| 284 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 285 | void CFX_Edit_UndoItem::SetFirst(bool bFirst) { |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 286 | m_bFirst = bFirst; |
| 287 | } |
| 288 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 289 | void CFX_Edit_UndoItem::SetLast(bool bLast) { |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 290 | m_bLast = bLast; |
| 291 | } |
| 292 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 293 | bool CFX_Edit_UndoItem::IsLast() { |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 294 | return m_bLast; |
| 295 | } |
| 296 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 297 | CFXEU_InsertWord::CFXEU_InsertWord(CFX_Edit* pEdit, |
| 298 | const CPVT_WordPlace& wpOldPlace, |
| 299 | const CPVT_WordPlace& wpNewPlace, |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 300 | uint16_t word, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | int32_t charset, |
| 302 | const CPVT_WordProps* pWordProps) |
| 303 | : m_pEdit(pEdit), |
| 304 | m_wpOld(wpOldPlace), |
| 305 | m_wpNew(wpNewPlace), |
| 306 | m_Word(word), |
| 307 | m_nCharset(charset), |
| 308 | m_WordProps() { |
| 309 | if (pWordProps) |
| 310 | m_WordProps = *pWordProps; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 313 | CFXEU_InsertWord::~CFXEU_InsertWord() {} |
| 314 | |
| 315 | void CFXEU_InsertWord::Redo() { |
| 316 | if (m_pEdit) { |
| 317 | m_pEdit->SelectNone(); |
| 318 | m_pEdit->SetCaret(m_wpOld); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 319 | m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, false, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 320 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 323 | void CFXEU_InsertWord::Undo() { |
| 324 | if (m_pEdit) { |
| 325 | m_pEdit->SelectNone(); |
| 326 | m_pEdit->SetCaret(m_wpNew); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 327 | m_pEdit->Backspace(false, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 328 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 331 | CFXEU_InsertReturn::CFXEU_InsertReturn(CFX_Edit* pEdit, |
| 332 | const CPVT_WordPlace& wpOldPlace, |
| 333 | const CPVT_WordPlace& wpNewPlace, |
| 334 | const CPVT_SecProps* pSecProps, |
| 335 | const CPVT_WordProps* pWordProps) |
| 336 | : m_pEdit(pEdit), |
| 337 | m_wpOld(wpOldPlace), |
| 338 | m_wpNew(wpNewPlace), |
| 339 | m_SecProps(), |
| 340 | m_WordProps() { |
| 341 | if (pSecProps) |
| 342 | m_SecProps = *pSecProps; |
| 343 | if (pWordProps) |
| 344 | m_WordProps = *pWordProps; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 347 | CFXEU_InsertReturn::~CFXEU_InsertReturn() {} |
| 348 | |
| 349 | void CFXEU_InsertReturn::Redo() { |
| 350 | if (m_pEdit) { |
| 351 | m_pEdit->SelectNone(); |
| 352 | m_pEdit->SetCaret(m_wpOld); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 353 | m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, false, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 354 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 357 | void CFXEU_InsertReturn::Undo() { |
| 358 | if (m_pEdit) { |
| 359 | m_pEdit->SelectNone(); |
| 360 | m_pEdit->SetCaret(m_wpNew); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 361 | m_pEdit->Backspace(false, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 362 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 365 | CFXEU_Backspace::CFXEU_Backspace(CFX_Edit* pEdit, |
| 366 | const CPVT_WordPlace& wpOldPlace, |
| 367 | const CPVT_WordPlace& wpNewPlace, |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 368 | uint16_t word, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 369 | int32_t charset, |
| 370 | const CPVT_SecProps& SecProps, |
| 371 | const CPVT_WordProps& WordProps) |
| 372 | : m_pEdit(pEdit), |
| 373 | m_wpOld(wpOldPlace), |
| 374 | m_wpNew(wpNewPlace), |
| 375 | m_Word(word), |
| 376 | m_nCharset(charset), |
| 377 | m_SecProps(SecProps), |
| 378 | m_WordProps(WordProps) {} |
| 379 | |
| 380 | CFXEU_Backspace::~CFXEU_Backspace() {} |
| 381 | |
| 382 | void CFXEU_Backspace::Redo() { |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 383 | if (!m_pEdit) |
| 384 | return; |
| 385 | |
| 386 | m_pEdit->SelectNone(); |
| 387 | m_pEdit->SetCaret(m_wpOld); |
| 388 | m_pEdit->Backspace(false, true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 391 | void CFXEU_Backspace::Undo() { |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 392 | if (!m_pEdit) |
| 393 | return; |
| 394 | |
| 395 | m_pEdit->SelectNone(); |
| 396 | m_pEdit->SetCaret(m_wpNew); |
| 397 | if (m_wpNew.nSecIndex != m_wpOld.nSecIndex) |
| 398 | m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, false, true); |
| 399 | else |
| 400 | m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, false, true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 403 | CFXEU_Delete::CFXEU_Delete(CFX_Edit* pEdit, |
| 404 | const CPVT_WordPlace& wpOldPlace, |
| 405 | const CPVT_WordPlace& wpNewPlace, |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 406 | uint16_t word, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 407 | int32_t charset, |
| 408 | const CPVT_SecProps& SecProps, |
| 409 | const CPVT_WordProps& WordProps, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 410 | bool bSecEnd) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 411 | : m_pEdit(pEdit), |
| 412 | m_wpOld(wpOldPlace), |
| 413 | m_wpNew(wpNewPlace), |
| 414 | m_Word(word), |
| 415 | m_nCharset(charset), |
| 416 | m_SecProps(SecProps), |
| 417 | m_WordProps(WordProps), |
| 418 | m_bSecEnd(bSecEnd) {} |
| 419 | |
| 420 | CFXEU_Delete::~CFXEU_Delete() {} |
| 421 | |
| 422 | void CFXEU_Delete::Redo() { |
| 423 | if (m_pEdit) { |
| 424 | m_pEdit->SelectNone(); |
| 425 | m_pEdit->SetCaret(m_wpOld); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 426 | m_pEdit->Delete(false, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 427 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 430 | void CFXEU_Delete::Undo() { |
| 431 | if (m_pEdit) { |
| 432 | m_pEdit->SelectNone(); |
| 433 | m_pEdit->SetCaret(m_wpNew); |
| 434 | if (m_bSecEnd) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 435 | m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, false, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 436 | } else { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 437 | m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, false, true); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 438 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 439 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 442 | CFXEU_Clear::CFXEU_Clear(CFX_Edit* pEdit, |
| 443 | const CPVT_WordRange& wrSel, |
| 444 | const CFX_WideString& swText) |
| 445 | : m_pEdit(pEdit), m_wrSel(wrSel), m_swText(swText) {} |
| 446 | |
| 447 | CFXEU_Clear::~CFXEU_Clear() {} |
| 448 | |
| 449 | void CFXEU_Clear::Redo() { |
| 450 | if (m_pEdit) { |
| 451 | m_pEdit->SelectNone(); |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 452 | m_pEdit->SetSelection(m_wrSel.BeginPos, m_wrSel.EndPos); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 453 | m_pEdit->Clear(false, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 454 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 457 | void CFXEU_Clear::Undo() { |
| 458 | if (m_pEdit) { |
| 459 | m_pEdit->SelectNone(); |
| 460 | m_pEdit->SetCaret(m_wrSel.BeginPos); |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 461 | m_pEdit->InsertText(m_swText, FX_CHARSET_Default, false, true); |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 462 | m_pEdit->SetSelection(m_wrSel.BeginPos, m_wrSel.EndPos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 463 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 466 | CFXEU_InsertText::CFXEU_InsertText(CFX_Edit* pEdit, |
| 467 | const CPVT_WordPlace& wpOldPlace, |
| 468 | const CPVT_WordPlace& wpNewPlace, |
| 469 | const CFX_WideString& swText, |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 470 | int32_t charset) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 471 | : m_pEdit(pEdit), |
| 472 | m_wpOld(wpOldPlace), |
| 473 | m_wpNew(wpNewPlace), |
| 474 | m_swText(swText), |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 475 | m_nCharset(charset) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 476 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 477 | CFXEU_InsertText::~CFXEU_InsertText() {} |
| 478 | |
| 479 | void CFXEU_InsertText::Redo() { |
| 480 | if (m_pEdit && IsLast()) { |
| 481 | m_pEdit->SelectNone(); |
| 482 | m_pEdit->SetCaret(m_wpOld); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 483 | m_pEdit->InsertText(m_swText, m_nCharset, false, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 484 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 487 | void CFXEU_InsertText::Undo() { |
| 488 | if (m_pEdit) { |
| 489 | m_pEdit->SelectNone(); |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 490 | m_pEdit->SetSelection(m_wpOld, m_wpNew); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 491 | m_pEdit->Clear(false, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 492 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 493 | } |
| 494 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 495 | // static |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 496 | void CFX_Edit::DrawEdit(CFX_RenderDevice* pDevice, |
| 497 | CFX_Matrix* pUser2Device, |
| 498 | CFX_Edit* pEdit, |
| 499 | FX_COLORREF crTextFill, |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 500 | const CFX_FloatRect& rcClip, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 501 | const CFX_PointF& ptOffset, |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 502 | const CPVT_WordRange* pRange, |
| 503 | CFX_SystemHandler* pSystemHandler, |
dsinclair | 8faac62 | 2016-09-15 12:41:50 -0700 | [diff] [blame] | 504 | CFFL_FormFiller* pFFLData) { |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 505 | const bool bContinuous = |
| 506 | pEdit->GetCharArray() == 0 && pEdit->GetCharSpace() <= 0.0f; |
| 507 | uint16_t SubWord = pEdit->GetPasswordChar(); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 508 | float fFontSize = pEdit->GetFontSize(); |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 509 | CPVT_WordRange wrSelect = pEdit->GetSelectWordRange(); |
| 510 | int32_t nHorzScale = pEdit->GetHorzScale(); |
| 511 | |
| 512 | FX_COLORREF crCurFill = crTextFill; |
| 513 | FX_COLORREF crOldFill = crCurFill; |
| 514 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 515 | bool bSelect = false; |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 516 | const FX_COLORREF crWhite = ArgbEncode(255, 255, 255, 255); |
| 517 | const FX_COLORREF crSelBK = ArgbEncode(255, 0, 51, 113); |
| 518 | |
Henrique Nakashima | 2e2da13 | 2017-06-27 13:43:22 -0400 | [diff] [blame] | 519 | std::ostringstream sTextBuf; |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 520 | int32_t nFontIndex = -1; |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 521 | CFX_PointF ptBT; |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 522 | CFX_RenderDevice::StateRestorer restorer(pDevice); |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 523 | if (!rcClip.IsEmpty()) { |
| 524 | CFX_FloatRect rcTemp = rcClip; |
| 525 | pUser2Device->TransformRect(rcTemp); |
| 526 | pDevice->SetClip_Rect(rcTemp.ToFxRect()); |
| 527 | } |
| 528 | |
| 529 | CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); |
| 530 | if (IPVT_FontMap* pFontMap = pEdit->GetFontMap()) { |
| 531 | if (pRange) |
| 532 | pIterator->SetAt(pRange->BeginPos); |
| 533 | else |
| 534 | pIterator->SetAt(0); |
| 535 | |
| 536 | CPVT_WordPlace oldplace; |
| 537 | while (pIterator->NextWord()) { |
| 538 | CPVT_WordPlace place = pIterator->GetAt(); |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 539 | if (pRange && place > pRange->EndPos) |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 540 | break; |
| 541 | |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 542 | if (!wrSelect.IsEmpty()) { |
| 543 | bSelect = place > wrSelect.BeginPos && place <= wrSelect.EndPos; |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 544 | crCurFill = bSelect ? crWhite : crTextFill; |
| 545 | } |
| 546 | if (pSystemHandler && pSystemHandler->IsSelectionImplemented()) { |
| 547 | crCurFill = crTextFill; |
| 548 | crOldFill = crCurFill; |
| 549 | } |
| 550 | CPVT_Word word; |
| 551 | if (pIterator->GetWord(word)) { |
| 552 | if (bSelect) { |
| 553 | CPVT_Line line; |
| 554 | pIterator->GetLine(line); |
| 555 | |
| 556 | if (pSystemHandler && pSystemHandler->IsSelectionImplemented()) { |
| 557 | CFX_FloatRect rc(word.ptWord.x, line.ptLine.y + line.fLineDescent, |
| 558 | word.ptWord.x + word.fWidth, |
| 559 | line.ptLine.y + line.fLineAscent); |
| 560 | rc.Intersect(rcClip); |
| 561 | pSystemHandler->OutputSelectedRect(pFFLData, rc); |
| 562 | } else { |
| 563 | CFX_PathData pathSelBK; |
| 564 | pathSelBK.AppendRect( |
| 565 | word.ptWord.x, line.ptLine.y + line.fLineDescent, |
| 566 | word.ptWord.x + word.fWidth, line.ptLine.y + line.fLineAscent); |
| 567 | |
| 568 | pDevice->DrawPath(&pathSelBK, pUser2Device, nullptr, crSelBK, 0, |
| 569 | FXFILL_WINDING); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | if (bContinuous) { |
| 574 | if (place.LineCmp(oldplace) != 0 || word.nFontIndex != nFontIndex || |
| 575 | crOldFill != crCurFill) { |
Henrique Nakashima | 2e2da13 | 2017-06-27 13:43:22 -0400 | [diff] [blame] | 576 | if (sTextBuf.tellp() > 0) { |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 577 | DrawTextString( |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 578 | pDevice, CFX_PointF(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 579 | pFontMap->GetPDFFont(nFontIndex), fFontSize, pUser2Device, |
Henrique Nakashima | 2e2da13 | 2017-06-27 13:43:22 -0400 | [diff] [blame] | 580 | CFX_ByteString(sTextBuf), crOldFill, nHorzScale); |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 581 | |
Henrique Nakashima | 2e2da13 | 2017-06-27 13:43:22 -0400 | [diff] [blame] | 582 | sTextBuf.str(""); |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 583 | } |
| 584 | nFontIndex = word.nFontIndex; |
| 585 | ptBT = word.ptWord; |
| 586 | crOldFill = crCurFill; |
| 587 | } |
| 588 | |
| 589 | sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, |
Henrique Nakashima | 2e2da13 | 2017-06-27 13:43:22 -0400 | [diff] [blame] | 590 | SubWord); |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 591 | } else { |
| 592 | DrawTextString( |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 593 | pDevice, CFX_PointF(word.ptWord.x + ptOffset.x, |
| 594 | word.ptWord.y + ptOffset.y), |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 595 | pFontMap->GetPDFFont(word.nFontIndex), fFontSize, pUser2Device, |
| 596 | GetPDFWordString(pFontMap, word.nFontIndex, word.Word, SubWord), |
Dan Sinclair | a0061af | 2017-02-23 09:25:17 -0500 | [diff] [blame] | 597 | crCurFill, nHorzScale); |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 598 | } |
| 599 | oldplace = place; |
| 600 | } |
| 601 | } |
| 602 | |
Henrique Nakashima | 2e2da13 | 2017-06-27 13:43:22 -0400 | [diff] [blame] | 603 | if (sTextBuf.tellp() > 0) { |
Dan Sinclair | a0061af | 2017-02-23 09:25:17 -0500 | [diff] [blame] | 604 | DrawTextString(pDevice, |
| 605 | CFX_PointF(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), |
| 606 | pFontMap->GetPDFFont(nFontIndex), fFontSize, pUser2Device, |
Henrique Nakashima | 2e2da13 | 2017-06-27 13:43:22 -0400 | [diff] [blame] | 607 | CFX_ByteString(sTextBuf), crOldFill, nHorzScale); |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 608 | } |
| 609 | } |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 610 | } |
| 611 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 612 | CFX_Edit::CFX_Edit() |
| 613 | : m_pVT(new CPDF_VariableText), |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 614 | m_pNotify(nullptr), |
| 615 | m_pOprNotify(nullptr), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 616 | m_wpCaret(-1, -1, -1), |
| 617 | m_wpOldCaret(-1, -1, -1), |
| 618 | m_SelState(), |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 619 | m_bEnableScroll(false), |
dsinclair | 8f4bf9a | 2016-05-04 13:51:51 -0700 | [diff] [blame] | 620 | m_Undo(kEditUndoMaxItems), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 621 | m_nAlignment(0), |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 622 | m_bNotifyFlag(false), |
| 623 | m_bEnableOverflow(false), |
| 624 | m_bEnableRefresh(true), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 625 | m_rcOldContent(0.0f, 0.0f, 0.0f, 0.0f), |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 626 | m_bEnableUndo(true), |
Lei Zhang | 1a89e36 | 2017-03-23 15:27:25 -0700 | [diff] [blame] | 627 | m_bOprNotify(false) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 628 | |
Lei Zhang | 1a89e36 | 2017-03-23 15:27:25 -0700 | [diff] [blame] | 629 | CFX_Edit::~CFX_Edit() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 630 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 631 | void CFX_Edit::Initialize() { |
| 632 | m_pVT->Initialize(); |
| 633 | SetCaret(m_pVT->GetBeginWordPlace()); |
| 634 | SetCaretOrigin(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 635 | } |
| 636 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 637 | void CFX_Edit::SetFontMap(IPVT_FontMap* pFontMap) { |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 638 | m_pVTProvider = pdfium::MakeUnique<CFX_Edit_Provider>(pFontMap); |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 639 | m_pVT->SetProvider(m_pVTProvider.get()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 640 | } |
| 641 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 642 | void CFX_Edit::SetNotify(CPWL_EditCtrl* pNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 643 | m_pNotify = pNotify; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 644 | } |
| 645 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 646 | void CFX_Edit::SetOprNotify(CPWL_Edit* pOprNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 647 | m_pOprNotify = pOprNotify; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 648 | } |
| 649 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 650 | CFX_Edit_Iterator* CFX_Edit::GetIterator() { |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 651 | if (!m_pIterator) { |
| 652 | m_pIterator = |
| 653 | pdfium::MakeUnique<CFX_Edit_Iterator>(this, m_pVT->GetIterator()); |
| 654 | } |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 655 | return m_pIterator.get(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 656 | } |
| 657 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 658 | IPVT_FontMap* CFX_Edit::GetFontMap() { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 659 | return m_pVTProvider ? m_pVTProvider->GetFontMap() : nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 660 | } |
| 661 | |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 662 | void CFX_Edit::SetPlateRect(const CFX_FloatRect& rect) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 663 | m_pVT->SetPlateRect(rect); |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 664 | m_ptScrollPos = CFX_PointF(rect.left, rect.top); |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 665 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 666 | } |
| 667 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 668 | void CFX_Edit::SetAlignmentH(int32_t nFormat, bool bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 669 | m_pVT->SetAlignment(nFormat); |
| 670 | if (bPaint) |
| 671 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 672 | } |
| 673 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 674 | void CFX_Edit::SetAlignmentV(int32_t nFormat, bool bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 675 | m_nAlignment = nFormat; |
| 676 | if (bPaint) |
| 677 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 678 | } |
| 679 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 680 | void CFX_Edit::SetPasswordChar(uint16_t wSubWord, bool bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 681 | m_pVT->SetPasswordChar(wSubWord); |
| 682 | if (bPaint) |
| 683 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 684 | } |
| 685 | |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 686 | void CFX_Edit::SetLimitChar(int32_t nLimitChar) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 687 | m_pVT->SetLimitChar(nLimitChar); |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 688 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 689 | } |
| 690 | |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 691 | void CFX_Edit::SetCharArray(int32_t nCharArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 692 | m_pVT->SetCharArray(nCharArray); |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 693 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 696 | void CFX_Edit::SetCharSpace(float fCharSpace) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 697 | m_pVT->SetCharSpace(fCharSpace); |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 698 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 699 | } |
| 700 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 701 | void CFX_Edit::SetMultiLine(bool bMultiLine, bool bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 702 | m_pVT->SetMultiLine(bMultiLine); |
| 703 | if (bPaint) |
| 704 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 705 | } |
| 706 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 707 | void CFX_Edit::SetAutoReturn(bool bAuto, bool bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 708 | m_pVT->SetAutoReturn(bAuto); |
| 709 | if (bPaint) |
| 710 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 711 | } |
| 712 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 713 | void CFX_Edit::SetAutoFontSize(bool bAuto, bool bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 714 | m_pVT->SetAutoFontSize(bAuto); |
| 715 | if (bPaint) |
| 716 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 719 | void CFX_Edit::SetFontSize(float fFontSize) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 720 | m_pVT->SetFontSize(fFontSize); |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 721 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 722 | } |
| 723 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 724 | void CFX_Edit::SetAutoScroll(bool bAuto, bool bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 725 | m_bEnableScroll = bAuto; |
| 726 | if (bPaint) |
| 727 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 728 | } |
| 729 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 730 | void CFX_Edit::SetTextOverflow(bool bAllowed, bool bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 731 | m_bEnableOverflow = bAllowed; |
| 732 | if (bPaint) |
| 733 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 734 | } |
| 735 | |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 736 | void CFX_Edit::SetSelection(int32_t nStartChar, int32_t nEndChar) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 737 | if (m_pVT->IsValid()) { |
| 738 | if (nStartChar == 0 && nEndChar < 0) { |
| 739 | SelectAll(); |
| 740 | } else if (nStartChar < 0) { |
| 741 | SelectNone(); |
| 742 | } else { |
| 743 | if (nStartChar < nEndChar) { |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 744 | SetSelection(m_pVT->WordIndexToWordPlace(nStartChar), |
| 745 | m_pVT->WordIndexToWordPlace(nEndChar)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 746 | } else { |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 747 | SetSelection(m_pVT->WordIndexToWordPlace(nEndChar), |
| 748 | m_pVT->WordIndexToWordPlace(nStartChar)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 749 | } |
| 750 | } |
| 751 | } |
| 752 | } |
| 753 | |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 754 | void CFX_Edit::SetSelection(const CPVT_WordPlace& begin, |
| 755 | const CPVT_WordPlace& end) { |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 756 | if (!m_pVT->IsValid()) |
| 757 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 758 | |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 759 | SelectNone(); |
| 760 | m_SelState.Set(begin, end); |
| 761 | SetCaret(m_SelState.EndPos); |
| 762 | ScrollToCaret(); |
| 763 | if (!m_SelState.IsEmpty()) |
| 764 | Refresh(); |
| 765 | SetCaretInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 768 | void CFX_Edit::GetSelection(int32_t& nStartChar, int32_t& nEndChar) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 769 | nStartChar = -1; |
| 770 | nEndChar = -1; |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 771 | if (!m_pVT->IsValid()) |
| 772 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 773 | |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 774 | if (m_SelState.IsEmpty()) { |
| 775 | nStartChar = m_pVT->WordPlaceToWordIndex(m_wpCaret); |
| 776 | nEndChar = m_pVT->WordPlaceToWordIndex(m_wpCaret); |
| 777 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 778 | } |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 779 | if (m_SelState.BeginPos < m_SelState.EndPos) { |
| 780 | nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos); |
| 781 | nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos); |
| 782 | return; |
| 783 | } |
| 784 | nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos); |
| 785 | nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | int32_t CFX_Edit::GetCaret() const { |
| 789 | if (m_pVT->IsValid()) |
| 790 | return m_pVT->WordPlaceToWordIndex(m_wpCaret); |
| 791 | |
| 792 | return -1; |
| 793 | } |
| 794 | |
| 795 | CPVT_WordPlace CFX_Edit::GetCaretWordPlace() const { |
| 796 | return m_wpCaret; |
| 797 | } |
| 798 | |
| 799 | CFX_WideString CFX_Edit::GetText() const { |
| 800 | CFX_WideString swRet; |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 801 | if (!m_pVT->IsValid()) |
| 802 | return swRet; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 803 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 804 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 805 | pIterator->SetAt(0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 806 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 807 | CPVT_Word wordinfo; |
| 808 | CPVT_WordPlace oldplace = pIterator->GetAt(); |
| 809 | while (pIterator->NextWord()) { |
| 810 | CPVT_WordPlace place = pIterator->GetAt(); |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 811 | if (pIterator->GetWord(wordinfo)) |
| 812 | swRet += wordinfo.Word; |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 813 | if (oldplace.nSecIndex != place.nSecIndex) |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 814 | swRet += L"\r\n"; |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 815 | oldplace = place; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 816 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 817 | return swRet; |
| 818 | } |
| 819 | |
| 820 | CFX_WideString CFX_Edit::GetRangeText(const CPVT_WordRange& range) const { |
| 821 | CFX_WideString swRet; |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 822 | if (!m_pVT->IsValid()) |
| 823 | return swRet; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 824 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 825 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 826 | CPVT_WordRange wrTemp = range; |
| 827 | m_pVT->UpdateWordPlace(wrTemp.BeginPos); |
| 828 | m_pVT->UpdateWordPlace(wrTemp.EndPos); |
| 829 | pIterator->SetAt(wrTemp.BeginPos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 830 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 831 | CPVT_Word wordinfo; |
| 832 | CPVT_WordPlace oldplace = wrTemp.BeginPos; |
| 833 | while (pIterator->NextWord()) { |
| 834 | CPVT_WordPlace place = pIterator->GetAt(); |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 835 | if (place > wrTemp.EndPos) |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 836 | break; |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 837 | if (pIterator->GetWord(wordinfo)) |
| 838 | swRet += wordinfo.Word; |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 839 | if (oldplace.nSecIndex != place.nSecIndex) |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 840 | swRet += L"\r\n"; |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 841 | oldplace = place; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 842 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 843 | return swRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 844 | } |
| 845 | |
Diana Gage | 89e6562 | 2017-07-20 18:09:31 -0700 | [diff] [blame^] | 846 | CFX_WideString CFX_Edit::GetSelectedText() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 847 | return GetRangeText(m_SelState.ConvertToWordRange()); |
| 848 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 849 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 850 | int32_t CFX_Edit::GetTotalLines() const { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 851 | int32_t nLines = 1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 852 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 853 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 854 | pIterator->SetAt(0); |
| 855 | while (pIterator->NextLine()) |
| 856 | ++nLines; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 857 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 858 | return nLines; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | CPVT_WordRange CFX_Edit::GetSelectWordRange() const { |
| 862 | return m_SelState.ConvertToWordRange(); |
| 863 | } |
| 864 | |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 865 | void CFX_Edit::SetText(const CFX_WideString& sText) { |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 866 | Empty(); |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 867 | DoInsertText(CPVT_WordPlace(0, 0, -1), sText, FX_CHARSET_Default); |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 868 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 869 | } |
| 870 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 871 | bool CFX_Edit::InsertWord(uint16_t word, int32_t charset) { |
| 872 | return InsertWord(word, charset, nullptr, true, true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 873 | } |
| 874 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 875 | bool CFX_Edit::InsertReturn() { |
| 876 | return InsertReturn(nullptr, nullptr, true, true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 877 | } |
| 878 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 879 | bool CFX_Edit::Backspace() { |
| 880 | return Backspace(true, true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 881 | } |
| 882 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 883 | bool CFX_Edit::Delete() { |
| 884 | return Delete(true, true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 885 | } |
| 886 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 887 | bool CFX_Edit::Clear() { |
| 888 | return Clear(true, true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 889 | } |
| 890 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 891 | bool CFX_Edit::InsertText(const CFX_WideString& sText, int32_t charset) { |
| 892 | return InsertText(sText, charset, true, true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 895 | float CFX_Edit::GetFontSize() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 896 | return m_pVT->GetFontSize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 899 | uint16_t CFX_Edit::GetPasswordChar() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 900 | return m_pVT->GetPasswordChar(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 901 | } |
| 902 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 903 | int32_t CFX_Edit::GetCharArray() const { |
| 904 | return m_pVT->GetCharArray(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 907 | CFX_FloatRect CFX_Edit::GetContentRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 908 | return VTToEdit(m_pVT->GetContentRect()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 911 | int32_t CFX_Edit::GetHorzScale() const { |
| 912 | return m_pVT->GetHorzScale(); |
| 913 | } |
| 914 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 915 | float CFX_Edit::GetCharSpace() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 916 | return m_pVT->GetCharSpace(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 919 | CPVT_WordRange CFX_Edit::GetWholeWordRange() const { |
| 920 | if (m_pVT->IsValid()) |
| 921 | return CPVT_WordRange(m_pVT->GetBeginWordPlace(), m_pVT->GetEndWordPlace()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 922 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 923 | return CPVT_WordRange(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 924 | } |
| 925 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 926 | CPVT_WordRange CFX_Edit::GetVisibleWordRange() const { |
| 927 | if (m_bEnableOverflow) |
| 928 | return GetWholeWordRange(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 929 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 930 | if (m_pVT->IsValid()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 931 | CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 932 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 933 | CPVT_WordPlace place1 = |
| 934 | m_pVT->SearchWordPlace(EditToVT(CFX_PointF(rcPlate.left, rcPlate.top))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 935 | CPVT_WordPlace place2 = m_pVT->SearchWordPlace( |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 936 | EditToVT(CFX_PointF(rcPlate.right, rcPlate.bottom))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 937 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 938 | return CPVT_WordRange(place1, place2); |
| 939 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 940 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 941 | return CPVT_WordRange(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 942 | } |
| 943 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 944 | CPVT_WordPlace CFX_Edit::SearchWordPlace(const CFX_PointF& point) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 945 | if (m_pVT->IsValid()) { |
| 946 | return m_pVT->SearchWordPlace(EditToVT(point)); |
| 947 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 948 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 949 | return CPVT_WordPlace(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 950 | } |
| 951 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 952 | void CFX_Edit::Paint() { |
| 953 | if (m_pVT->IsValid()) { |
| 954 | RearrangeAll(); |
| 955 | ScrollToCaret(); |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 956 | Refresh(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 957 | SetCaretOrigin(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 958 | SetCaretInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 959 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 962 | void CFX_Edit::RearrangeAll() { |
| 963 | if (m_pVT->IsValid()) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 964 | m_pVT->UpdateWordPlace(m_wpCaret); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 965 | m_pVT->RearrangeAll(); |
| 966 | m_pVT->UpdateWordPlace(m_wpCaret); |
| 967 | SetScrollInfo(); |
| 968 | SetContentChanged(); |
| 969 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 972 | void CFX_Edit::RearrangePart(const CPVT_WordRange& range) { |
| 973 | if (m_pVT->IsValid()) { |
| 974 | m_pVT->UpdateWordPlace(m_wpCaret); |
| 975 | m_pVT->RearrangePart(range); |
| 976 | m_pVT->UpdateWordPlace(m_wpCaret); |
| 977 | SetScrollInfo(); |
| 978 | SetContentChanged(); |
| 979 | } |
| 980 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 981 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 982 | void CFX_Edit::SetContentChanged() { |
dsinclair | a2919b3 | 2016-07-13 10:55:48 -0700 | [diff] [blame] | 983 | if (m_pNotify) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 984 | CFX_FloatRect rcContent = m_pVT->GetContentRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 985 | if (rcContent.Width() != m_rcOldContent.Width() || |
| 986 | rcContent.Height() != m_rcOldContent.Height()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 987 | m_rcOldContent = rcContent; |
| 988 | } |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | void CFX_Edit::SelectAll() { |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 993 | if (!m_pVT->IsValid()) |
| 994 | return; |
| 995 | m_SelState = CFX_Edit_Select(GetWholeWordRange()); |
| 996 | SetCaret(m_SelState.EndPos); |
| 997 | ScrollToCaret(); |
| 998 | Refresh(); |
| 999 | SetCaretInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | void CFX_Edit::SelectNone() { |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1003 | if (!m_pVT->IsValid() || m_SelState.IsEmpty()) |
| 1004 | return; |
| 1005 | |
| 1006 | m_SelState.Reset(); |
| 1007 | Refresh(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1010 | bool CFX_Edit::IsSelected() const { |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1011 | return !m_SelState.IsEmpty(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1014 | CFX_PointF CFX_Edit::VTToEdit(const CFX_PointF& point) const { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1015 | CFX_FloatRect rcContent = m_pVT->GetContentRect(); |
| 1016 | CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1017 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1018 | float fPadding = 0.0f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1019 | |
| 1020 | switch (m_nAlignment) { |
| 1021 | case 0: |
| 1022 | fPadding = 0.0f; |
| 1023 | break; |
| 1024 | case 1: |
| 1025 | fPadding = (rcPlate.Height() - rcContent.Height()) * 0.5f; |
| 1026 | break; |
| 1027 | case 2: |
| 1028 | fPadding = rcPlate.Height() - rcContent.Height(); |
| 1029 | break; |
| 1030 | } |
| 1031 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1032 | return CFX_PointF(point.x - (m_ptScrollPos.x - rcPlate.left), |
| 1033 | point.y - (m_ptScrollPos.y + fPadding - rcPlate.top)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1036 | CFX_PointF CFX_Edit::EditToVT(const CFX_PointF& point) const { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1037 | CFX_FloatRect rcContent = m_pVT->GetContentRect(); |
| 1038 | CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1039 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1040 | float fPadding = 0.0f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1041 | |
| 1042 | switch (m_nAlignment) { |
| 1043 | case 0: |
| 1044 | fPadding = 0.0f; |
| 1045 | break; |
| 1046 | case 1: |
| 1047 | fPadding = (rcPlate.Height() - rcContent.Height()) * 0.5f; |
| 1048 | break; |
| 1049 | case 2: |
| 1050 | fPadding = rcPlate.Height() - rcContent.Height(); |
| 1051 | break; |
| 1052 | } |
| 1053 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1054 | return CFX_PointF(point.x + (m_ptScrollPos.x - rcPlate.left), |
| 1055 | point.y + (m_ptScrollPos.y + fPadding - rcPlate.top)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1058 | CFX_FloatRect CFX_Edit::VTToEdit(const CFX_FloatRect& rect) const { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1059 | CFX_PointF ptLeftBottom = VTToEdit(CFX_PointF(rect.left, rect.bottom)); |
| 1060 | CFX_PointF ptRightTop = VTToEdit(CFX_PointF(rect.right, rect.top)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1061 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1062 | return CFX_FloatRect(ptLeftBottom.x, ptLeftBottom.y, ptRightTop.x, |
| 1063 | ptRightTop.y); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1066 | void CFX_Edit::SetScrollInfo() { |
Dan Sinclair | 0fdd1ae | 2017-07-05 16:00:48 -0400 | [diff] [blame] | 1067 | if (!m_pNotify) |
| 1068 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1069 | |
Dan Sinclair | 0fdd1ae | 2017-07-05 16:00:48 -0400 | [diff] [blame] | 1070 | CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
| 1071 | CFX_FloatRect rcContent = m_pVT->GetContentRect(); |
| 1072 | if (m_bNotifyFlag) |
| 1073 | return; |
| 1074 | |
| 1075 | CFX_AutoRestorer<bool> restorer(&m_bNotifyFlag); |
| 1076 | m_bNotifyFlag = true; |
| 1077 | |
| 1078 | PWL_SCROLL_INFO Info; |
| 1079 | Info.fPlateWidth = rcPlate.top - rcPlate.bottom; |
| 1080 | Info.fContentMin = rcContent.bottom; |
| 1081 | Info.fContentMax = rcContent.top; |
| 1082 | Info.fSmallStep = rcPlate.Height() / 3; |
| 1083 | Info.fBigStep = rcPlate.Height(); |
| 1084 | m_pNotify->SetScrollInfo(Info); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1087 | void CFX_Edit::SetScrollPosX(float fx) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1088 | if (!m_bEnableScroll) |
| 1089 | return; |
| 1090 | |
| 1091 | if (m_pVT->IsValid()) { |
dsinclair | 448c433 | 2016-08-02 12:07:35 -0700 | [diff] [blame] | 1092 | if (!IsFloatEqual(m_ptScrollPos.x, fx)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1093 | m_ptScrollPos.x = fx; |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1094 | Refresh(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1095 | } |
| 1096 | } |
| 1097 | } |
| 1098 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1099 | void CFX_Edit::SetScrollPosY(float fy) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1100 | if (!m_bEnableScroll) |
| 1101 | return; |
| 1102 | |
| 1103 | if (m_pVT->IsValid()) { |
dsinclair | 448c433 | 2016-08-02 12:07:35 -0700 | [diff] [blame] | 1104 | if (!IsFloatEqual(m_ptScrollPos.y, fy)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1105 | m_ptScrollPos.y = fy; |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1106 | Refresh(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1107 | |
dsinclair | a2919b3 | 2016-07-13 10:55:48 -0700 | [diff] [blame] | 1108 | if (m_pNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1109 | if (!m_bNotifyFlag) { |
Lei Zhang | a8c2b91 | 2017-03-22 17:41:02 -0700 | [diff] [blame] | 1110 | CFX_AutoRestorer<bool> restorer(&m_bNotifyFlag); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1111 | m_bNotifyFlag = true; |
Dan Sinclair | 0fdd1ae | 2017-07-05 16:00:48 -0400 | [diff] [blame] | 1112 | m_pNotify->SetScrollPosition(fy); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1119 | void CFX_Edit::SetScrollPos(const CFX_PointF& point) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1120 | SetScrollPosX(point.x); |
| 1121 | SetScrollPosY(point.y); |
| 1122 | SetScrollLimit(); |
| 1123 | SetCaretInfo(); |
| 1124 | } |
| 1125 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1126 | CFX_PointF CFX_Edit::GetScrollPos() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1127 | return m_ptScrollPos; |
| 1128 | } |
| 1129 | |
| 1130 | void CFX_Edit::SetScrollLimit() { |
| 1131 | if (m_pVT->IsValid()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1132 | CFX_FloatRect rcContent = m_pVT->GetContentRect(); |
| 1133 | CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1134 | |
| 1135 | if (rcPlate.Width() > rcContent.Width()) { |
| 1136 | SetScrollPosX(rcPlate.left); |
| 1137 | } else { |
dsinclair | 448c433 | 2016-08-02 12:07:35 -0700 | [diff] [blame] | 1138 | if (IsFloatSmaller(m_ptScrollPos.x, rcContent.left)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1139 | SetScrollPosX(rcContent.left); |
dsinclair | 448c433 | 2016-08-02 12:07:35 -0700 | [diff] [blame] | 1140 | } else if (IsFloatBigger(m_ptScrollPos.x, |
| 1141 | rcContent.right - rcPlate.Width())) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1142 | SetScrollPosX(rcContent.right - rcPlate.Width()); |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | if (rcPlate.Height() > rcContent.Height()) { |
| 1147 | SetScrollPosY(rcPlate.top); |
| 1148 | } else { |
dsinclair | 448c433 | 2016-08-02 12:07:35 -0700 | [diff] [blame] | 1149 | if (IsFloatSmaller(m_ptScrollPos.y, |
| 1150 | rcContent.bottom + rcPlate.Height())) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1151 | SetScrollPosY(rcContent.bottom + rcPlate.Height()); |
dsinclair | 448c433 | 2016-08-02 12:07:35 -0700 | [diff] [blame] | 1152 | } else if (IsFloatBigger(m_ptScrollPos.y, rcContent.top)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1153 | SetScrollPosY(rcContent.top); |
| 1154 | } |
| 1155 | } |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | void CFX_Edit::ScrollToCaret() { |
| 1160 | SetScrollLimit(); |
| 1161 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1162 | if (!m_pVT->IsValid()) |
| 1163 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1164 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1165 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 1166 | pIterator->SetAt(m_wpCaret); |
| 1167 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1168 | CFX_PointF ptHead; |
| 1169 | CFX_PointF ptFoot; |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1170 | CPVT_Word word; |
| 1171 | CPVT_Line line; |
| 1172 | if (pIterator->GetWord(word)) { |
| 1173 | ptHead.x = word.ptWord.x + word.fWidth; |
| 1174 | ptHead.y = word.ptWord.y + word.fAscent; |
| 1175 | ptFoot.x = word.ptWord.x + word.fWidth; |
| 1176 | ptFoot.y = word.ptWord.y + word.fDescent; |
| 1177 | } else if (pIterator->GetLine(line)) { |
| 1178 | ptHead.x = line.ptLine.x; |
| 1179 | ptHead.y = line.ptLine.y + line.fLineAscent; |
| 1180 | ptFoot.x = line.ptLine.x; |
| 1181 | ptFoot.y = line.ptLine.y + line.fLineDescent; |
| 1182 | } |
| 1183 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1184 | CFX_PointF ptHeadEdit = VTToEdit(ptHead); |
| 1185 | CFX_PointF ptFootEdit = VTToEdit(ptFoot); |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1186 | CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
dsinclair | 448c433 | 2016-08-02 12:07:35 -0700 | [diff] [blame] | 1187 | if (!IsFloatEqual(rcPlate.left, rcPlate.right)) { |
| 1188 | if (IsFloatSmaller(ptHeadEdit.x, rcPlate.left) || |
| 1189 | IsFloatEqual(ptHeadEdit.x, rcPlate.left)) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1190 | SetScrollPosX(ptHead.x); |
dsinclair | 448c433 | 2016-08-02 12:07:35 -0700 | [diff] [blame] | 1191 | } else if (IsFloatBigger(ptHeadEdit.x, rcPlate.right)) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1192 | SetScrollPosX(ptHead.x - rcPlate.Width()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1193 | } |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1194 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1195 | |
dsinclair | 448c433 | 2016-08-02 12:07:35 -0700 | [diff] [blame] | 1196 | if (!IsFloatEqual(rcPlate.top, rcPlate.bottom)) { |
| 1197 | if (IsFloatSmaller(ptFootEdit.y, rcPlate.bottom) || |
| 1198 | IsFloatEqual(ptFootEdit.y, rcPlate.bottom)) { |
| 1199 | if (IsFloatSmaller(ptHeadEdit.y, rcPlate.top)) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1200 | SetScrollPosY(ptFoot.y + rcPlate.Height()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1201 | } |
dsinclair | 448c433 | 2016-08-02 12:07:35 -0700 | [diff] [blame] | 1202 | } else if (IsFloatBigger(ptHeadEdit.y, rcPlate.top)) { |
| 1203 | if (IsFloatBigger(ptFootEdit.y, rcPlate.bottom)) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1204 | SetScrollPosY(ptHead.y); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1205 | } |
| 1206 | } |
| 1207 | } |
| 1208 | } |
| 1209 | |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1210 | void CFX_Edit::Refresh() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1211 | if (m_bEnableRefresh && m_pVT->IsValid()) { |
| 1212 | m_Refresh.BeginRefresh(); |
| 1213 | RefreshPushLineRects(GetVisibleWordRange()); |
| 1214 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1215 | m_Refresh.NoAnalyse(); |
| 1216 | m_ptRefreshScrollPos = m_ptScrollPos; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1217 | |
dsinclair | a2919b3 | 2016-07-13 10:55:48 -0700 | [diff] [blame] | 1218 | if (m_pNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1219 | if (!m_bNotifyFlag) { |
Lei Zhang | a8c2b91 | 2017-03-22 17:41:02 -0700 | [diff] [blame] | 1220 | CFX_AutoRestorer<bool> restorer(&m_bNotifyFlag); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1221 | m_bNotifyFlag = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1222 | if (const CFX_Edit_RectArray* pRects = m_Refresh.GetRefreshRects()) { |
| 1223 | for (int32_t i = 0, sz = pRects->GetSize(); i < sz; i++) |
Dan Sinclair | 0fdd1ae | 2017-07-05 16:00:48 -0400 | [diff] [blame] | 1224 | m_pNotify->InvalidateRect(pRects->GetAt(i)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1225 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | m_Refresh.EndRefresh(); |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | void CFX_Edit::RefreshPushLineRects(const CPVT_WordRange& wr) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1234 | if (!m_pVT->IsValid()) |
| 1235 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1236 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1237 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 1238 | CPVT_WordPlace wpBegin = wr.BeginPos; |
| 1239 | m_pVT->UpdateWordPlace(wpBegin); |
| 1240 | CPVT_WordPlace wpEnd = wr.EndPos; |
| 1241 | m_pVT->UpdateWordPlace(wpEnd); |
| 1242 | pIterator->SetAt(wpBegin); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1243 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1244 | CPVT_Line lineinfo; |
| 1245 | do { |
| 1246 | if (!pIterator->GetLine(lineinfo)) |
| 1247 | break; |
| 1248 | if (lineinfo.lineplace.LineCmp(wpEnd) > 0) |
| 1249 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1250 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1251 | CFX_FloatRect rcLine(lineinfo.ptLine.x, |
| 1252 | lineinfo.ptLine.y + lineinfo.fLineDescent, |
| 1253 | lineinfo.ptLine.x + lineinfo.fLineWidth, |
| 1254 | lineinfo.ptLine.y + lineinfo.fLineAscent); |
| 1255 | |
| 1256 | m_Refresh.Push(CPVT_WordRange(lineinfo.lineplace, lineinfo.lineEnd), |
| 1257 | VTToEdit(rcLine)); |
| 1258 | } while (pIterator->NextLine()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1261 | void CFX_Edit::RefreshWordRange(const CPVT_WordRange& wr) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1262 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 1263 | CPVT_WordRange wrTemp = wr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1264 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1265 | m_pVT->UpdateWordPlace(wrTemp.BeginPos); |
| 1266 | m_pVT->UpdateWordPlace(wrTemp.EndPos); |
| 1267 | pIterator->SetAt(wrTemp.BeginPos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1268 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1269 | CPVT_Word wordinfo; |
| 1270 | CPVT_Line lineinfo; |
| 1271 | CPVT_WordPlace place; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1272 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1273 | while (pIterator->NextWord()) { |
| 1274 | place = pIterator->GetAt(); |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1275 | if (place > wrTemp.EndPos) |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1276 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1277 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1278 | pIterator->GetWord(wordinfo); |
| 1279 | pIterator->GetLine(lineinfo); |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1280 | if (place.LineCmp(wrTemp.BeginPos) == 0 || |
| 1281 | place.LineCmp(wrTemp.EndPos) == 0) { |
| 1282 | CFX_FloatRect rcWord(wordinfo.ptWord.x, |
| 1283 | lineinfo.ptLine.y + lineinfo.fLineDescent, |
| 1284 | wordinfo.ptWord.x + wordinfo.fWidth, |
| 1285 | lineinfo.ptLine.y + lineinfo.fLineAscent); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1286 | |
dsinclair | a2919b3 | 2016-07-13 10:55:48 -0700 | [diff] [blame] | 1287 | if (m_pNotify) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1288 | if (!m_bNotifyFlag) { |
Lei Zhang | a8c2b91 | 2017-03-22 17:41:02 -0700 | [diff] [blame] | 1289 | CFX_AutoRestorer<bool> restorer(&m_bNotifyFlag); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1290 | m_bNotifyFlag = true; |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1291 | CFX_FloatRect rcRefresh = VTToEdit(rcWord); |
Dan Sinclair | 0fdd1ae | 2017-07-05 16:00:48 -0400 | [diff] [blame] | 1292 | m_pNotify->InvalidateRect(&rcRefresh); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1293 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1294 | } |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1295 | } else { |
| 1296 | CFX_FloatRect rcLine(lineinfo.ptLine.x, |
| 1297 | lineinfo.ptLine.y + lineinfo.fLineDescent, |
| 1298 | lineinfo.ptLine.x + lineinfo.fLineWidth, |
| 1299 | lineinfo.ptLine.y + lineinfo.fLineAscent); |
| 1300 | |
dsinclair | a2919b3 | 2016-07-13 10:55:48 -0700 | [diff] [blame] | 1301 | if (m_pNotify) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1302 | if (!m_bNotifyFlag) { |
Lei Zhang | a8c2b91 | 2017-03-22 17:41:02 -0700 | [diff] [blame] | 1303 | CFX_AutoRestorer<bool> restorer(&m_bNotifyFlag); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1304 | m_bNotifyFlag = true; |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1305 | CFX_FloatRect rcRefresh = VTToEdit(rcLine); |
Dan Sinclair | 0fdd1ae | 2017-07-05 16:00:48 -0400 | [diff] [blame] | 1306 | m_pNotify->InvalidateRect(&rcRefresh); |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | pIterator->NextLine(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1311 | } |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | void CFX_Edit::SetCaret(const CPVT_WordPlace& place) { |
| 1316 | m_wpOldCaret = m_wpCaret; |
| 1317 | m_wpCaret = place; |
| 1318 | } |
| 1319 | |
| 1320 | void CFX_Edit::SetCaretInfo() { |
dsinclair | a2919b3 | 2016-07-13 10:55:48 -0700 | [diff] [blame] | 1321 | if (m_pNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1322 | if (!m_bNotifyFlag) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1323 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 1324 | pIterator->SetAt(m_wpCaret); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 1325 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1326 | CFX_PointF ptHead; |
| 1327 | CFX_PointF ptFoot; |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1328 | CPVT_Word word; |
| 1329 | CPVT_Line line; |
| 1330 | if (pIterator->GetWord(word)) { |
| 1331 | ptHead.x = word.ptWord.x + word.fWidth; |
| 1332 | ptHead.y = word.ptWord.y + word.fAscent; |
| 1333 | ptFoot.x = word.ptWord.x + word.fWidth; |
| 1334 | ptFoot.y = word.ptWord.y + word.fDescent; |
| 1335 | } else if (pIterator->GetLine(line)) { |
| 1336 | ptHead.x = line.ptLine.x; |
| 1337 | ptHead.y = line.ptLine.y + line.fLineAscent; |
| 1338 | ptFoot.x = line.ptLine.x; |
| 1339 | ptFoot.y = line.ptLine.y + line.fLineDescent; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
Lei Zhang | a8c2b91 | 2017-03-22 17:41:02 -0700 | [diff] [blame] | 1342 | CFX_AutoRestorer<bool> restorer(&m_bNotifyFlag); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1343 | m_bNotifyFlag = true; |
Dan Sinclair | 0fdd1ae | 2017-07-05 16:00:48 -0400 | [diff] [blame] | 1344 | m_pNotify->SetCaret(m_SelState.IsEmpty(), VTToEdit(ptHead), |
| 1345 | VTToEdit(ptFoot)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1346 | } |
| 1347 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1350 | void CFX_Edit::OnMouseDown(const CFX_PointF& point, bool bShift, bool bCtrl) { |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1351 | if (!m_pVT->IsValid()) |
| 1352 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1353 | |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1354 | SelectNone(); |
| 1355 | SetCaret(m_pVT->SearchWordPlace(EditToVT(point))); |
| 1356 | m_SelState.Set(m_wpCaret, m_wpCaret); |
| 1357 | ScrollToCaret(); |
| 1358 | SetCaretOrigin(); |
| 1359 | SetCaretInfo(); |
| 1360 | } |
| 1361 | |
| 1362 | void CFX_Edit::OnMouseMove(const CFX_PointF& point, bool bShift, bool bCtrl) { |
| 1363 | if (!m_pVT->IsValid()) |
| 1364 | return; |
| 1365 | |
| 1366 | SetCaret(m_pVT->SearchWordPlace(EditToVT(point))); |
| 1367 | if (m_wpCaret == m_wpOldCaret) |
| 1368 | return; |
| 1369 | |
| 1370 | m_SelState.SetEndPos(m_wpCaret); |
| 1371 | ScrollToCaret(); |
| 1372 | Refresh(); |
| 1373 | SetCaretOrigin(); |
| 1374 | SetCaretInfo(); |
| 1375 | } |
| 1376 | |
| 1377 | void CFX_Edit::OnVK_UP(bool bShift, bool bCtrl) { |
| 1378 | if (!m_pVT->IsValid()) |
| 1379 | return; |
| 1380 | |
| 1381 | SetCaret(m_pVT->GetUpWordPlace(m_wpCaret, m_ptCaret)); |
| 1382 | if (bShift) { |
| 1383 | if (m_SelState.IsEmpty()) |
| 1384 | m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 1385 | else |
| 1386 | m_SelState.SetEndPos(m_wpCaret); |
| 1387 | |
| 1388 | if (m_wpOldCaret != m_wpCaret) { |
| 1389 | ScrollToCaret(); |
| 1390 | Refresh(); |
| 1391 | SetCaretInfo(); |
| 1392 | } |
| 1393 | } else { |
| 1394 | SelectNone(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1395 | ScrollToCaret(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1396 | SetCaretInfo(); |
| 1397 | } |
| 1398 | } |
| 1399 | |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1400 | void CFX_Edit::OnVK_DOWN(bool bShift, bool bCtrl) { |
| 1401 | if (!m_pVT->IsValid()) |
| 1402 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1403 | |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1404 | SetCaret(m_pVT->GetDownWordPlace(m_wpCaret, m_ptCaret)); |
| 1405 | if (bShift) { |
| 1406 | if (m_SelState.IsEmpty()) |
| 1407 | m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 1408 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1409 | m_SelState.SetEndPos(m_wpCaret); |
| 1410 | |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1411 | if (m_wpOldCaret != m_wpCaret) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1412 | ScrollToCaret(); |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1413 | Refresh(); |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1414 | SetCaretInfo(); |
| 1415 | } |
| 1416 | } else { |
| 1417 | SelectNone(); |
| 1418 | ScrollToCaret(); |
| 1419 | SetCaretInfo(); |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | void CFX_Edit::OnVK_LEFT(bool bShift, bool bCtrl) { |
| 1424 | if (!m_pVT->IsValid()) |
| 1425 | return; |
| 1426 | |
| 1427 | if (bShift) { |
| 1428 | if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) && |
| 1429 | m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret)) { |
| 1430 | SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); |
| 1431 | } |
| 1432 | SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); |
| 1433 | if (m_SelState.IsEmpty()) |
| 1434 | m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 1435 | else |
| 1436 | m_SelState.SetEndPos(m_wpCaret); |
| 1437 | |
| 1438 | if (m_wpOldCaret != m_wpCaret) { |
| 1439 | ScrollToCaret(); |
| 1440 | Refresh(); |
| 1441 | SetCaretInfo(); |
| 1442 | } |
| 1443 | } else { |
| 1444 | if (!m_SelState.IsEmpty()) { |
| 1445 | if (m_SelState.BeginPos < m_SelState.EndPos) |
| 1446 | SetCaret(m_SelState.BeginPos); |
| 1447 | else |
| 1448 | SetCaret(m_SelState.EndPos); |
| 1449 | |
| 1450 | SelectNone(); |
| 1451 | ScrollToCaret(); |
| 1452 | SetCaretInfo(); |
| 1453 | } else { |
| 1454 | if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) && |
| 1455 | m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret)) { |
| 1456 | SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); |
| 1457 | } |
| 1458 | SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); |
| 1459 | ScrollToCaret(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1460 | SetCaretOrigin(); |
| 1461 | SetCaretInfo(); |
| 1462 | } |
| 1463 | } |
| 1464 | } |
| 1465 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1466 | void CFX_Edit::OnVK_RIGHT(bool bShift, bool bCtrl) { |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1467 | if (!m_pVT->IsValid()) |
| 1468 | return; |
| 1469 | |
| 1470 | if (bShift) { |
| 1471 | SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); |
| 1472 | if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) && |
| 1473 | m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1474 | SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); |
| 1475 | |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1476 | if (m_SelState.IsEmpty()) |
| 1477 | m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 1478 | else |
| 1479 | m_SelState.SetEndPos(m_wpCaret); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1480 | |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1481 | if (m_wpOldCaret != m_wpCaret) { |
| 1482 | ScrollToCaret(); |
| 1483 | Refresh(); |
| 1484 | SetCaretInfo(); |
| 1485 | } |
| 1486 | } else { |
| 1487 | if (!m_SelState.IsEmpty()) { |
| 1488 | if (m_SelState.BeginPos > m_SelState.EndPos) |
| 1489 | SetCaret(m_SelState.BeginPos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1490 | else |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1491 | SetCaret(m_SelState.EndPos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1492 | |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1493 | SelectNone(); |
| 1494 | ScrollToCaret(); |
| 1495 | SetCaretInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1496 | } else { |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1497 | SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); |
| 1498 | if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) && |
| 1499 | m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1500 | SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1501 | } |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1502 | ScrollToCaret(); |
| 1503 | SetCaretOrigin(); |
| 1504 | SetCaretInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1505 | } |
| 1506 | } |
| 1507 | } |
| 1508 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1509 | void CFX_Edit::OnVK_HOME(bool bShift, bool bCtrl) { |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1510 | if (!m_pVT->IsValid()) |
| 1511 | return; |
| 1512 | |
| 1513 | if (bShift) { |
| 1514 | if (bCtrl) |
| 1515 | SetCaret(m_pVT->GetBeginWordPlace()); |
| 1516 | else |
| 1517 | SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret)); |
| 1518 | |
| 1519 | if (m_SelState.IsEmpty()) |
| 1520 | m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 1521 | else |
| 1522 | m_SelState.SetEndPos(m_wpCaret); |
| 1523 | |
| 1524 | ScrollToCaret(); |
| 1525 | Refresh(); |
| 1526 | SetCaretInfo(); |
| 1527 | } else { |
| 1528 | if (!m_SelState.IsEmpty()) { |
| 1529 | SetCaret(std::min(m_SelState.BeginPos, m_SelState.EndPos)); |
| 1530 | SelectNone(); |
| 1531 | ScrollToCaret(); |
| 1532 | SetCaretInfo(); |
| 1533 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1534 | if (bCtrl) |
| 1535 | SetCaret(m_pVT->GetBeginWordPlace()); |
| 1536 | else |
| 1537 | SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret)); |
| 1538 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1539 | ScrollToCaret(); |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1540 | SetCaretOrigin(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1541 | SetCaretInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1542 | } |
| 1543 | } |
| 1544 | } |
| 1545 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1546 | void CFX_Edit::OnVK_END(bool bShift, bool bCtrl) { |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1547 | if (!m_pVT->IsValid()) |
| 1548 | return; |
| 1549 | |
| 1550 | if (bShift) { |
| 1551 | if (bCtrl) |
| 1552 | SetCaret(m_pVT->GetEndWordPlace()); |
| 1553 | else |
| 1554 | SetCaret(m_pVT->GetLineEndPlace(m_wpCaret)); |
| 1555 | |
| 1556 | if (m_SelState.IsEmpty()) |
| 1557 | m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 1558 | else |
| 1559 | m_SelState.SetEndPos(m_wpCaret); |
| 1560 | |
| 1561 | ScrollToCaret(); |
| 1562 | Refresh(); |
| 1563 | SetCaretInfo(); |
| 1564 | } else { |
| 1565 | if (!m_SelState.IsEmpty()) { |
| 1566 | SetCaret(std::max(m_SelState.BeginPos, m_SelState.EndPos)); |
| 1567 | SelectNone(); |
| 1568 | ScrollToCaret(); |
| 1569 | SetCaretInfo(); |
| 1570 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1571 | if (bCtrl) |
| 1572 | SetCaret(m_pVT->GetEndWordPlace()); |
| 1573 | else |
| 1574 | SetCaret(m_pVT->GetLineEndPlace(m_wpCaret)); |
| 1575 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1576 | ScrollToCaret(); |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1577 | SetCaretOrigin(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1578 | SetCaretInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1579 | } |
| 1580 | } |
| 1581 | } |
| 1582 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1583 | bool CFX_Edit::InsertWord(uint16_t word, |
| 1584 | int32_t charset, |
| 1585 | const CPVT_WordProps* pWordProps, |
| 1586 | bool bAddUndo, |
| 1587 | bool bPaint) { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1588 | if (IsTextOverflow() || !m_pVT->IsValid()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1589 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1590 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1591 | m_pVT->UpdateWordPlace(m_wpCaret); |
| 1592 | SetCaret(m_pVT->InsertWord(m_wpCaret, word, |
| 1593 | GetCharSetFromUnicode(word, charset), pWordProps)); |
| 1594 | m_SelState.Set(m_wpCaret, m_wpCaret); |
| 1595 | if (m_wpCaret == m_wpOldCaret) |
| 1596 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1597 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1598 | if (bAddUndo && m_bEnableUndo) { |
| 1599 | AddEditUndoItem(pdfium::MakeUnique<CFXEU_InsertWord>( |
| 1600 | this, m_wpOldCaret, m_wpCaret, word, charset, pWordProps)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1601 | } |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1602 | if (bPaint) |
| 1603 | PaintInsertText(m_wpOldCaret, m_wpCaret); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1604 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1605 | if (m_bOprNotify && m_pOprNotify) |
| 1606 | m_pOprNotify->OnInsertWord(m_wpCaret, m_wpOldCaret); |
| 1607 | |
| 1608 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1609 | } |
| 1610 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1611 | bool CFX_Edit::InsertReturn(const CPVT_SecProps* pSecProps, |
| 1612 | const CPVT_WordProps* pWordProps, |
| 1613 | bool bAddUndo, |
| 1614 | bool bPaint) { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1615 | if (IsTextOverflow() || !m_pVT->IsValid()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1616 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1617 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1618 | m_pVT->UpdateWordPlace(m_wpCaret); |
| 1619 | SetCaret(m_pVT->InsertSection(m_wpCaret, pSecProps, pWordProps)); |
| 1620 | m_SelState.Set(m_wpCaret, m_wpCaret); |
| 1621 | if (m_wpCaret == m_wpOldCaret) |
| 1622 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1623 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1624 | if (bAddUndo && m_bEnableUndo) { |
| 1625 | AddEditUndoItem(pdfium::MakeUnique<CFXEU_InsertReturn>( |
| 1626 | this, m_wpOldCaret, m_wpCaret, pSecProps, pWordProps)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1627 | } |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1628 | if (bPaint) { |
| 1629 | RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret)); |
| 1630 | ScrollToCaret(); |
| 1631 | Refresh(); |
| 1632 | SetCaretOrigin(); |
| 1633 | SetCaretInfo(); |
| 1634 | } |
| 1635 | if (m_bOprNotify && m_pOprNotify) |
| 1636 | m_pOprNotify->OnInsertReturn(m_wpCaret, m_wpOldCaret); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1637 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1638 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1641 | bool CFX_Edit::Backspace(bool bAddUndo, bool bPaint) { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1642 | if (!m_pVT->IsValid() || m_wpCaret == m_pVT->GetBeginWordPlace()) |
| 1643 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1644 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1645 | CPVT_Section section; |
| 1646 | CPVT_Word word; |
| 1647 | if (bAddUndo) { |
| 1648 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 1649 | pIterator->SetAt(m_wpCaret); |
| 1650 | pIterator->GetSection(section); |
| 1651 | pIterator->GetWord(word); |
| 1652 | } |
| 1653 | m_pVT->UpdateWordPlace(m_wpCaret); |
| 1654 | SetCaret(m_pVT->BackSpaceWord(m_wpCaret)); |
| 1655 | m_SelState.Set(m_wpCaret, m_wpCaret); |
| 1656 | if (m_wpCaret == m_wpOldCaret) |
| 1657 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1658 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1659 | if (bAddUndo && m_bEnableUndo) { |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1660 | if (m_wpCaret.nSecIndex != m_wpOldCaret.nSecIndex) { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1661 | AddEditUndoItem(pdfium::MakeUnique<CFXEU_Backspace>( |
| 1662 | this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset, |
| 1663 | section.SecProps, section.WordProps)); |
| 1664 | } else { |
| 1665 | AddEditUndoItem(pdfium::MakeUnique<CFXEU_Backspace>( |
| 1666 | this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset, |
| 1667 | section.SecProps, word.WordProps)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1668 | } |
| 1669 | } |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1670 | if (bPaint) { |
| 1671 | RearrangePart(CPVT_WordRange(m_wpCaret, m_wpOldCaret)); |
| 1672 | ScrollToCaret(); |
| 1673 | Refresh(); |
| 1674 | SetCaretOrigin(); |
| 1675 | SetCaretInfo(); |
| 1676 | } |
| 1677 | if (m_bOprNotify && m_pOprNotify) |
| 1678 | m_pOprNotify->OnBackSpace(m_wpCaret, m_wpOldCaret); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1679 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1680 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1683 | bool CFX_Edit::Delete(bool bAddUndo, bool bPaint) { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1684 | if (!m_pVT->IsValid() || m_wpCaret == m_pVT->GetEndWordPlace()) |
| 1685 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1686 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1687 | CPVT_Section section; |
| 1688 | CPVT_Word word; |
| 1689 | if (bAddUndo) { |
| 1690 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 1691 | pIterator->SetAt(m_pVT->GetNextWordPlace(m_wpCaret)); |
| 1692 | pIterator->GetSection(section); |
| 1693 | pIterator->GetWord(word); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1694 | } |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1695 | m_pVT->UpdateWordPlace(m_wpCaret); |
| 1696 | bool bSecEnd = (m_wpCaret == m_pVT->GetSectionEndPlace(m_wpCaret)); |
| 1697 | SetCaret(m_pVT->DeleteWord(m_wpCaret)); |
| 1698 | m_SelState.Set(m_wpCaret, m_wpCaret); |
| 1699 | if (bAddUndo && m_bEnableUndo) { |
| 1700 | if (bSecEnd) { |
| 1701 | AddEditUndoItem(pdfium::MakeUnique<CFXEU_Delete>( |
| 1702 | this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset, |
| 1703 | section.SecProps, section.WordProps, bSecEnd)); |
| 1704 | } else { |
| 1705 | AddEditUndoItem(pdfium::MakeUnique<CFXEU_Delete>( |
| 1706 | this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset, |
| 1707 | section.SecProps, word.WordProps, bSecEnd)); |
| 1708 | } |
| 1709 | } |
| 1710 | if (bPaint) { |
| 1711 | RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret)); |
| 1712 | ScrollToCaret(); |
| 1713 | Refresh(); |
| 1714 | SetCaretOrigin(); |
| 1715 | SetCaretInfo(); |
| 1716 | } |
| 1717 | if (m_bOprNotify && m_pOprNotify) |
| 1718 | m_pOprNotify->OnDelete(m_wpCaret, m_wpOldCaret); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1719 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1720 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1723 | bool CFX_Edit::Empty() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1724 | if (m_pVT->IsValid()) { |
| 1725 | m_pVT->DeleteWords(GetWholeWordRange()); |
| 1726 | SetCaret(m_pVT->GetBeginWordPlace()); |
| 1727 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1728 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1729 | } |
| 1730 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1731 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1732 | } |
| 1733 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1734 | bool CFX_Edit::Clear(bool bAddUndo, bool bPaint) { |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1735 | if (!m_pVT->IsValid() || m_SelState.IsEmpty()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1736 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1737 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1738 | CPVT_WordRange range = m_SelState.ConvertToWordRange(); |
dsinclair | a2919b3 | 2016-07-13 10:55:48 -0700 | [diff] [blame] | 1739 | if (bAddUndo && m_bEnableUndo) |
Diana Gage | 89e6562 | 2017-07-20 18:09:31 -0700 | [diff] [blame^] | 1740 | AddEditUndoItem( |
| 1741 | pdfium::MakeUnique<CFXEU_Clear>(this, range, GetSelectedText())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1742 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1743 | SelectNone(); |
| 1744 | SetCaret(m_pVT->DeleteWords(range)); |
| 1745 | m_SelState.Set(m_wpCaret, m_wpCaret); |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1746 | if (bPaint) { |
| 1747 | RearrangePart(range); |
| 1748 | ScrollToCaret(); |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1749 | Refresh(); |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1750 | SetCaretOrigin(); |
| 1751 | SetCaretInfo(); |
| 1752 | } |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1753 | if (m_bOprNotify && m_pOprNotify) |
| 1754 | m_pOprNotify->OnClear(m_wpCaret, m_wpOldCaret); |
| 1755 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1756 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1759 | bool CFX_Edit::InsertText(const CFX_WideString& sText, |
| 1760 | int32_t charset, |
| 1761 | bool bAddUndo, |
| 1762 | bool bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1763 | if (IsTextOverflow()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1764 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1765 | |
| 1766 | m_pVT->UpdateWordPlace(m_wpCaret); |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1767 | SetCaret(DoInsertText(m_wpCaret, sText, charset)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1768 | m_SelState.Set(m_wpCaret, m_wpCaret); |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1769 | if (m_wpCaret == m_wpOldCaret) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1770 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1771 | |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1772 | if (bAddUndo && m_bEnableUndo) { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1773 | AddEditUndoItem(pdfium::MakeUnique<CFXEU_InsertText>( |
| 1774 | this, m_wpOldCaret, m_wpCaret, sText, charset)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1775 | } |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1776 | if (bPaint) |
| 1777 | PaintInsertText(m_wpOldCaret, m_wpCaret); |
| 1778 | |
| 1779 | if (m_bOprNotify && m_pOprNotify) |
| 1780 | m_pOprNotify->OnInsertText(m_wpCaret, m_wpOldCaret); |
| 1781 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1782 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | void CFX_Edit::PaintInsertText(const CPVT_WordPlace& wpOld, |
| 1786 | const CPVT_WordPlace& wpNew) { |
| 1787 | if (m_pVT->IsValid()) { |
| 1788 | RearrangePart(CPVT_WordRange(wpOld, wpNew)); |
| 1789 | ScrollToCaret(); |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1790 | Refresh(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1791 | SetCaretOrigin(); |
| 1792 | SetCaretInfo(); |
| 1793 | } |
| 1794 | } |
| 1795 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1796 | bool CFX_Edit::Redo() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1797 | if (m_bEnableUndo) { |
| 1798 | if (m_Undo.CanRedo()) { |
| 1799 | m_Undo.Redo(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1800 | return true; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1801 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1804 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1807 | bool CFX_Edit::Undo() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1808 | if (m_bEnableUndo) { |
| 1809 | if (m_Undo.CanUndo()) { |
| 1810 | m_Undo.Undo(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1811 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1812 | } |
| 1813 | } |
| 1814 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1815 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | void CFX_Edit::SetCaretOrigin() { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1819 | if (!m_pVT->IsValid()) |
| 1820 | return; |
| 1821 | |
| 1822 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 1823 | pIterator->SetAt(m_wpCaret); |
| 1824 | CPVT_Word word; |
| 1825 | CPVT_Line line; |
| 1826 | if (pIterator->GetWord(word)) { |
| 1827 | m_ptCaret.x = word.ptWord.x + word.fWidth; |
| 1828 | m_ptCaret.y = word.ptWord.y; |
| 1829 | } else if (pIterator->GetLine(line)) { |
| 1830 | m_ptCaret.x = line.ptLine.x; |
| 1831 | m_ptCaret.y = line.ptLine.y; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1832 | } |
| 1833 | } |
| 1834 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1835 | CPVT_WordPlace CFX_Edit::WordIndexToWordPlace(int32_t index) const { |
| 1836 | if (m_pVT->IsValid()) |
| 1837 | return m_pVT->WordIndexToWordPlace(index); |
| 1838 | |
| 1839 | return CPVT_WordPlace(); |
| 1840 | } |
| 1841 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1842 | bool CFX_Edit::IsTextFull() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1843 | int32_t nTotalWords = m_pVT->GetTotalWords(); |
| 1844 | int32_t nLimitChar = m_pVT->GetLimitChar(); |
| 1845 | int32_t nCharArray = m_pVT->GetCharArray(); |
| 1846 | |
| 1847 | return IsTextOverflow() || (nLimitChar > 0 && nTotalWords >= nLimitChar) || |
| 1848 | (nCharArray > 0 && nTotalWords >= nCharArray); |
| 1849 | } |
| 1850 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1851 | bool CFX_Edit::IsTextOverflow() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1852 | if (!m_bEnableScroll && !m_bEnableOverflow) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1853 | CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
| 1854 | CFX_FloatRect rcContent = m_pVT->GetContentRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1855 | |
dsinclair | 448c433 | 2016-08-02 12:07:35 -0700 | [diff] [blame] | 1856 | if (m_pVT->IsMultiLine() && GetTotalLines() > 1 && |
| 1857 | IsFloatBigger(rcContent.Height(), rcPlate.Height())) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1858 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
dsinclair | 448c433 | 2016-08-02 12:07:35 -0700 | [diff] [blame] | 1861 | if (IsFloatBigger(rcContent.Width(), rcPlate.Width())) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1862 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1865 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1868 | bool CFX_Edit::CanUndo() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1869 | if (m_bEnableUndo) { |
| 1870 | return m_Undo.CanUndo(); |
| 1871 | } |
| 1872 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1873 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1874 | } |
| 1875 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1876 | bool CFX_Edit::CanRedo() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1877 | if (m_bEnableUndo) { |
| 1878 | return m_Undo.CanRedo(); |
| 1879 | } |
| 1880 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1881 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1882 | } |
| 1883 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1884 | void CFX_Edit::EnableRefresh(bool bRefresh) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1885 | m_bEnableRefresh = bRefresh; |
| 1886 | } |
| 1887 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1888 | void CFX_Edit::EnableUndo(bool bUndo) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1889 | m_bEnableUndo = bUndo; |
| 1890 | } |
| 1891 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1892 | void CFX_Edit::EnableOprNotify(bool bNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1893 | m_bOprNotify = bNotify; |
| 1894 | } |
| 1895 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1896 | CPVT_WordPlace CFX_Edit::DoInsertText(const CPVT_WordPlace& place, |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1897 | const CFX_WideString& sText, |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1898 | int32_t charset) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1899 | CPVT_WordPlace wp = place; |
| 1900 | |
| 1901 | if (m_pVT->IsValid()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1902 | for (int32_t i = 0, sz = sText.GetLength(); i < sz; i++) { |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 1903 | uint16_t word = sText[i]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1904 | switch (word) { |
| 1905 | case 0x0D: |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1906 | wp = m_pVT->InsertSection(wp, nullptr, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1907 | if (sText[i + 1] == 0x0A) |
| 1908 | i++; |
| 1909 | break; |
| 1910 | case 0x0A: |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1911 | wp = m_pVT->InsertSection(wp, nullptr, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1912 | if (sText[i + 1] == 0x0D) |
| 1913 | i++; |
| 1914 | break; |
| 1915 | case 0x09: |
| 1916 | word = 0x20; |
| 1917 | default: |
| 1918 | wp = m_pVT->InsertWord(wp, word, GetCharSetFromUnicode(word, charset), |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1919 | nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1920 | break; |
| 1921 | } |
| 1922 | } |
| 1923 | } |
| 1924 | |
| 1925 | return wp; |
| 1926 | } |
| 1927 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 1928 | int32_t CFX_Edit::GetCharSetFromUnicode(uint16_t word, int32_t nOldCharset) { |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 1929 | if (IPVT_FontMap* pFontMap = GetFontMap()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1930 | return pFontMap->CharSetFromUnicode(word, nOldCharset); |
| 1931 | return nOldCharset; |
| 1932 | } |
| 1933 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1934 | void CFX_Edit::AddEditUndoItem( |
| 1935 | std::unique_ptr<CFX_Edit_UndoItem> pEditUndoItem) { |
Lei Zhang | 1a89e36 | 2017-03-23 15:27:25 -0700 | [diff] [blame] | 1936 | m_Undo.AddItem(std::move(pEditUndoItem)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1939 | CFX_Edit_LineRectArray::CFX_Edit_LineRectArray() {} |
| 1940 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1941 | CFX_Edit_LineRectArray::~CFX_Edit_LineRectArray() {} |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1942 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1943 | void CFX_Edit_LineRectArray::operator=(CFX_Edit_LineRectArray&& that) { |
| 1944 | m_LineRects = std::move(that.m_LineRects); |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | void CFX_Edit_LineRectArray::Add(const CPVT_WordRange& wrLine, |
| 1948 | const CFX_FloatRect& rcLine) { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1949 | m_LineRects.push_back(pdfium::MakeUnique<CFX_Edit_LineRect>(wrLine, rcLine)); |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | int32_t CFX_Edit_LineRectArray::GetSize() const { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1953 | return pdfium::CollectionSize<int32_t>(m_LineRects); |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | CFX_Edit_LineRect* CFX_Edit_LineRectArray::GetAt(int32_t nIndex) const { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1957 | if (nIndex < 0 || nIndex >= GetSize()) |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1958 | return nullptr; |
| 1959 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1960 | return m_LineRects[nIndex].get(); |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | CFX_Edit_Select::CFX_Edit_Select() {} |
| 1964 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1965 | CFX_Edit_Select::CFX_Edit_Select(const CPVT_WordRange& range) { |
| 1966 | Set(range.BeginPos, range.EndPos); |
| 1967 | } |
| 1968 | |
| 1969 | CPVT_WordRange CFX_Edit_Select::ConvertToWordRange() const { |
| 1970 | return CPVT_WordRange(BeginPos, EndPos); |
| 1971 | } |
| 1972 | |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1973 | void CFX_Edit_Select::Reset() { |
| 1974 | BeginPos.Reset(); |
| 1975 | EndPos.Reset(); |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | void CFX_Edit_Select::Set(const CPVT_WordPlace& begin, |
| 1979 | const CPVT_WordPlace& end) { |
| 1980 | BeginPos = begin; |
| 1981 | EndPos = end; |
| 1982 | } |
| 1983 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1984 | void CFX_Edit_Select::SetEndPos(const CPVT_WordPlace& end) { |
| 1985 | EndPos = end; |
| 1986 | } |
| 1987 | |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 1988 | bool CFX_Edit_Select::IsEmpty() const { |
| 1989 | return BeginPos == EndPos; |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1990 | } |
| 1991 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1992 | CFX_Edit_RectArray::CFX_Edit_RectArray() {} |
| 1993 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1994 | CFX_Edit_RectArray::~CFX_Edit_RectArray() {} |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1995 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 1996 | void CFX_Edit_RectArray::Clear() { |
| 1997 | m_Rects.clear(); |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | void CFX_Edit_RectArray::Add(const CFX_FloatRect& rect) { |
| 2001 | // check for overlapped area |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 2002 | for (const auto& pRect : m_Rects) { |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 2003 | if (pRect && pRect->Contains(rect)) |
| 2004 | return; |
| 2005 | } |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 2006 | m_Rects.push_back(pdfium::MakeUnique<CFX_FloatRect>(rect)); |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | int32_t CFX_Edit_RectArray::GetSize() const { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 2010 | return pdfium::CollectionSize<int32_t>(m_Rects); |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | CFX_FloatRect* CFX_Edit_RectArray::GetAt(int32_t nIndex) const { |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 2014 | if (nIndex < 0 || nIndex >= GetSize()) |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 2015 | return nullptr; |
| 2016 | |
Tom Sepez | 3509d16 | 2017-01-30 13:22:02 -0800 | [diff] [blame] | 2017 | return m_Rects[nIndex].get(); |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 2018 | } |