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