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