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