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