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