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 | 89bdd08 | 2016-04-06 10:47:54 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/fxedit/include/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> |
| 10 | |
dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame] | 11 | #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 12 | #include "core/fpdfdoc/include/cpvt_section.h" |
| 13 | #include "core/fpdfdoc/include/cpvt_word.h" |
| 14 | #include "core/fpdfdoc/include/ipvt_fontmap.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 15 | |
dsinclair | 8f4bf9a | 2016-05-04 13:51:51 -0700 | [diff] [blame] | 16 | namespace { |
| 17 | |
| 18 | const int kEditUndoMaxItems = 10000; |
| 19 | |
| 20 | } // namespace |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 21 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 22 | CFX_Edit_Iterator::CFX_Edit_Iterator(CFX_Edit* pEdit, |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 23 | CPDF_VariableText::Iterator* pVTIterator) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 24 | : m_pEdit(pEdit), m_pVTIterator(pVTIterator) {} |
| 25 | |
| 26 | CFX_Edit_Iterator::~CFX_Edit_Iterator() {} |
| 27 | |
| 28 | FX_BOOL CFX_Edit_Iterator::NextWord() { |
| 29 | return m_pVTIterator->NextWord(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 32 | FX_BOOL CFX_Edit_Iterator::NextLine() { |
| 33 | return m_pVTIterator->NextLine(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 36 | FX_BOOL CFX_Edit_Iterator::NextSection() { |
| 37 | return m_pVTIterator->NextSection(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 40 | FX_BOOL CFX_Edit_Iterator::PrevWord() { |
| 41 | return m_pVTIterator->PrevWord(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 44 | FX_BOOL CFX_Edit_Iterator::PrevLine() { |
| 45 | return m_pVTIterator->PrevLine(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | FX_BOOL CFX_Edit_Iterator::PrevSection() { |
| 49 | return m_pVTIterator->PrevSection(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | FX_BOOL CFX_Edit_Iterator::GetWord(CPVT_Word& word) const { |
| 53 | ASSERT(m_pEdit); |
| 54 | |
| 55 | if (m_pVTIterator->GetWord(word)) { |
| 56 | word.ptWord = m_pEdit->VTToEdit(word.ptWord); |
| 57 | return TRUE; |
| 58 | } |
| 59 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 62 | FX_BOOL CFX_Edit_Iterator::GetLine(CPVT_Line& line) const { |
| 63 | ASSERT(m_pEdit); |
| 64 | |
| 65 | if (m_pVTIterator->GetLine(line)) { |
| 66 | line.ptLine = m_pEdit->VTToEdit(line.ptLine); |
| 67 | return TRUE; |
| 68 | } |
| 69 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 72 | FX_BOOL CFX_Edit_Iterator::GetSection(CPVT_Section& section) const { |
| 73 | ASSERT(m_pEdit); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 74 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | if (m_pVTIterator->GetSection(section)) { |
| 76 | section.rcSection = m_pEdit->VTToEdit(section.rcSection); |
| 77 | return TRUE; |
| 78 | } |
| 79 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 82 | void CFX_Edit_Iterator::SetAt(int32_t nWordIndex) { |
| 83 | m_pVTIterator->SetAt(nWordIndex); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 86 | void CFX_Edit_Iterator::SetAt(const CPVT_WordPlace& place) { |
| 87 | m_pVTIterator->SetAt(place); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 90 | const CPVT_WordPlace& CFX_Edit_Iterator::GetAt() const { |
| 91 | return m_pVTIterator->GetAt(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | IFX_Edit* CFX_Edit_Iterator::GetEdit() const { |
| 95 | return m_pEdit; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 96 | } |
| 97 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 98 | CFX_Edit_Provider::CFX_Edit_Provider(IPVT_FontMap* pFontMap) |
| 99 | : CPDF_VariableText::Provider(pFontMap), m_pFontMap(pFontMap) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 100 | ASSERT(m_pFontMap); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 103 | CFX_Edit_Provider::~CFX_Edit_Provider() {} |
| 104 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 105 | IPVT_FontMap* CFX_Edit_Provider::GetFontMap() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 106 | return m_pFontMap; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 109 | int32_t CFX_Edit_Provider::GetCharWidth(int32_t nFontIndex, |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 110 | uint16_t word, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 111 | int32_t nWordStyle) { |
| 112 | if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 113 | uint32_t charcode = word; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 114 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 115 | if (pPDFFont->IsUnicodeCompatible()) |
| 116 | charcode = pPDFFont->CharCodeFromUnicode(word); |
| 117 | else |
| 118 | charcode = m_pFontMap->CharCodeFromUnicode(nFontIndex, word); |
| 119 | |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 120 | if (charcode != CPDF_Font::kInvalidCharCode) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 121 | return pPDFFont->GetCharWidthF(charcode); |
| 122 | } |
| 123 | |
| 124 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 127 | int32_t CFX_Edit_Provider::GetTypeAscent(int32_t nFontIndex) { |
| 128 | if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) |
| 129 | return pPDFFont->GetTypeAscent(); |
| 130 | |
| 131 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 134 | int32_t CFX_Edit_Provider::GetTypeDescent(int32_t nFontIndex) { |
| 135 | if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) |
| 136 | return pPDFFont->GetTypeDescent(); |
| 137 | |
| 138 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 141 | int32_t CFX_Edit_Provider::GetWordFontIndex(uint16_t word, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 142 | int32_t charset, |
| 143 | int32_t nFontIndex) { |
| 144 | return m_pFontMap->GetWordFontIndex(word, charset, nFontIndex); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 147 | int32_t CFX_Edit_Provider::GetDefaultFontIndex() { |
| 148 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 151 | FX_BOOL CFX_Edit_Provider::IsLatinWord(uint16_t word) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 152 | return FX_EDIT_ISLATINWORD(word); |
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_Refresh::CFX_Edit_Refresh() {} |
| 156 | |
| 157 | CFX_Edit_Refresh::~CFX_Edit_Refresh() {} |
| 158 | |
| 159 | void CFX_Edit_Refresh::BeginRefresh() { |
| 160 | m_RefreshRects.Empty(); |
| 161 | m_OldLineRects = m_NewLineRects; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 164 | void CFX_Edit_Refresh::Push(const CPVT_WordRange& linerange, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 165 | const CFX_FloatRect& rect) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 166 | m_NewLineRects.Add(linerange, rect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 169 | void CFX_Edit_Refresh::NoAnalyse() { |
| 170 | { |
| 171 | for (int32_t i = 0, sz = m_OldLineRects.GetSize(); i < sz; i++) |
| 172 | if (CFX_Edit_LineRect* pOldRect = m_OldLineRects.GetAt(i)) |
| 173 | m_RefreshRects.Add(pOldRect->m_rcLine); |
| 174 | } |
| 175 | |
| 176 | { |
| 177 | for (int32_t i = 0, sz = m_NewLineRects.GetSize(); i < sz; i++) |
| 178 | if (CFX_Edit_LineRect* pNewRect = m_NewLineRects.GetAt(i)) |
| 179 | m_RefreshRects.Add(pNewRect->m_rcLine); |
| 180 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 183 | void CFX_Edit_Refresh::Analyse(int32_t nAlignment) { |
| 184 | FX_BOOL bLineTopChanged = FALSE; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 185 | CFX_FloatRect rcResult; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 186 | FX_FLOAT fWidthDiff; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 187 | |
Lei Zhang | 375a864 | 2016-01-11 11:59:17 -0800 | [diff] [blame] | 188 | int32_t szMax = std::max(m_OldLineRects.GetSize(), m_NewLineRects.GetSize()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 189 | int32_t i = 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 190 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 191 | while (i < szMax) { |
| 192 | CFX_Edit_LineRect* pOldRect = m_OldLineRects.GetAt(i); |
| 193 | CFX_Edit_LineRect* pNewRect = m_NewLineRects.GetAt(i); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 194 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 195 | if (pOldRect) { |
| 196 | if (pNewRect) { |
| 197 | if (bLineTopChanged) { |
| 198 | rcResult = pOldRect->m_rcLine; |
| 199 | rcResult.Union(pNewRect->m_rcLine); |
| 200 | m_RefreshRects.Add(rcResult); |
| 201 | } else { |
| 202 | if (*pNewRect != *pOldRect) { |
| 203 | if (!pNewRect->IsSameTop(*pOldRect) || |
| 204 | !pNewRect->IsSameHeight(*pOldRect)) { |
| 205 | bLineTopChanged = TRUE; |
| 206 | continue; |
| 207 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 208 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 209 | if (nAlignment == 0) { |
| 210 | if (pNewRect->m_wrLine.BeginPos != pOldRect->m_wrLine.BeginPos) { |
| 211 | rcResult = pOldRect->m_rcLine; |
| 212 | rcResult.Union(pNewRect->m_rcLine); |
| 213 | m_RefreshRects.Add(rcResult); |
| 214 | } else { |
| 215 | if (!pNewRect->IsSameLeft(*pOldRect)) { |
| 216 | rcResult = pOldRect->m_rcLine; |
| 217 | rcResult.Union(pNewRect->m_rcLine); |
| 218 | } else { |
| 219 | fWidthDiff = |
| 220 | pNewRect->m_rcLine.Width() - pOldRect->m_rcLine.Width(); |
| 221 | rcResult = pNewRect->m_rcLine; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 222 | if (fWidthDiff > 0.0f) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 223 | rcResult.left = rcResult.right - fWidthDiff; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 224 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 225 | rcResult.left = rcResult.right; |
thestig | 8c32dfa | 2016-04-29 18:14:37 -0700 | [diff] [blame] | 226 | rcResult.right -= fWidthDiff; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 227 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 228 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 229 | m_RefreshRects.Add(rcResult); |
| 230 | } |
| 231 | } else { |
| 232 | rcResult = pOldRect->m_rcLine; |
| 233 | rcResult.Union(pNewRect->m_rcLine); |
| 234 | m_RefreshRects.Add(rcResult); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 235 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 236 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 237 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 238 | } else { |
| 239 | m_RefreshRects.Add(pOldRect->m_rcLine); |
| 240 | } |
| 241 | } else { |
| 242 | if (pNewRect) { |
| 243 | m_RefreshRects.Add(pNewRect->m_rcLine); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 244 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 245 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 246 | i++; |
| 247 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 250 | void CFX_Edit_Refresh::AddRefresh(const CFX_FloatRect& rect) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 251 | m_RefreshRects.Add(rect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 254 | const CFX_Edit_RectArray* CFX_Edit_Refresh::GetRefreshRects() const { |
| 255 | return &m_RefreshRects; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 258 | void CFX_Edit_Refresh::EndRefresh() { |
| 259 | m_RefreshRects.Empty(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 262 | CFX_Edit_Undo::CFX_Edit_Undo(int32_t nBufsize) |
| 263 | : m_nCurUndoPos(0), |
| 264 | m_nBufSize(nBufsize), |
| 265 | m_bModified(FALSE), |
| 266 | m_bVirgin(TRUE), |
| 267 | m_bWorking(FALSE) {} |
| 268 | |
| 269 | CFX_Edit_Undo::~CFX_Edit_Undo() { |
| 270 | Reset(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 273 | FX_BOOL CFX_Edit_Undo::CanUndo() const { |
| 274 | return m_nCurUndoPos > 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 277 | void CFX_Edit_Undo::Undo() { |
| 278 | m_bWorking = TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 279 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 280 | if (m_nCurUndoPos > 0) { |
| 281 | IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(m_nCurUndoPos - 1); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 282 | pItem->Undo(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 283 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 284 | m_nCurUndoPos--; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 285 | m_bModified = (m_nCurUndoPos != 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | m_bWorking = FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 291 | FX_BOOL CFX_Edit_Undo::CanRedo() const { |
| 292 | return m_nCurUndoPos < m_UndoItemStack.GetSize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 295 | void CFX_Edit_Undo::Redo() { |
| 296 | m_bWorking = TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 297 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 298 | int32_t nStackSize = m_UndoItemStack.GetSize(); |
| 299 | |
| 300 | if (m_nCurUndoPos < nStackSize) { |
| 301 | IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(m_nCurUndoPos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 302 | pItem->Redo(); |
| 303 | |
| 304 | m_nCurUndoPos++; |
| 305 | m_bModified = (m_nCurUndoPos != 0); |
| 306 | } |
| 307 | |
| 308 | m_bWorking = FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 311 | FX_BOOL CFX_Edit_Undo::IsWorking() const { |
| 312 | return m_bWorking; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 315 | void CFX_Edit_Undo::AddItem(IFX_Edit_UndoItem* pItem) { |
| 316 | ASSERT(!m_bWorking); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 317 | ASSERT(pItem); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 318 | ASSERT(m_nBufSize > 1); |
| 319 | |
| 320 | if (m_nCurUndoPos < m_UndoItemStack.GetSize()) |
| 321 | RemoveTails(); |
| 322 | |
| 323 | if (m_UndoItemStack.GetSize() >= m_nBufSize) { |
| 324 | RemoveHeads(); |
| 325 | m_bVirgin = FALSE; |
| 326 | } |
| 327 | |
| 328 | m_UndoItemStack.Add(pItem); |
| 329 | m_nCurUndoPos = m_UndoItemStack.GetSize(); |
| 330 | |
| 331 | m_bModified = (m_nCurUndoPos != 0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 334 | FX_BOOL CFX_Edit_Undo::IsModified() const { |
| 335 | return m_bVirgin ? m_bModified : TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 338 | IFX_Edit_UndoItem* CFX_Edit_Undo::GetItem(int32_t nIndex) { |
| 339 | if (nIndex >= 0 && nIndex < m_UndoItemStack.GetSize()) |
| 340 | return m_UndoItemStack.GetAt(nIndex); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 341 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 342 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 345 | void CFX_Edit_Undo::RemoveHeads() { |
| 346 | ASSERT(m_UndoItemStack.GetSize() > 1); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 347 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 348 | delete m_UndoItemStack.GetAt(0); |
| 349 | m_UndoItemStack.RemoveAt(0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 352 | void CFX_Edit_Undo::RemoveTails() { |
| 353 | for (int32_t i = m_UndoItemStack.GetSize() - 1; i >= m_nCurUndoPos; i--) { |
| 354 | delete m_UndoItemStack.GetAt(i); |
| 355 | m_UndoItemStack.RemoveAt(i); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | void CFX_Edit_Undo::Reset() { |
| 360 | for (int32_t i = 0, sz = m_UndoItemStack.GetSize(); i < sz; i++) { |
| 361 | delete m_UndoItemStack.GetAt(i); |
| 362 | } |
| 363 | m_nCurUndoPos = 0; |
| 364 | m_UndoItemStack.RemoveAll(); |
| 365 | } |
| 366 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame^] | 367 | CFX_Edit_UndoItem::CFX_Edit_UndoItem() : m_bFirst(TRUE), m_bLast(TRUE) {} |
| 368 | |
| 369 | CFX_Edit_UndoItem::~CFX_Edit_UndoItem() {} |
| 370 | |
| 371 | CFX_WideString CFX_Edit_UndoItem::GetUndoTitle() { |
| 372 | return L""; |
| 373 | } |
| 374 | |
| 375 | void CFX_Edit_UndoItem::SetFirst(FX_BOOL bFirst) { |
| 376 | m_bFirst = bFirst; |
| 377 | } |
| 378 | |
| 379 | FX_BOOL CFX_Edit_UndoItem::IsFirst() { |
| 380 | return m_bFirst; |
| 381 | } |
| 382 | |
| 383 | void CFX_Edit_UndoItem::SetLast(FX_BOOL bLast) { |
| 384 | m_bLast = bLast; |
| 385 | } |
| 386 | |
| 387 | FX_BOOL CFX_Edit_UndoItem::IsLast() { |
| 388 | return m_bLast; |
| 389 | } |
| 390 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 391 | CFX_Edit_GroupUndoItem::CFX_Edit_GroupUndoItem(const CFX_WideString& sTitle) |
| 392 | : m_sTitle(sTitle) {} |
| 393 | |
| 394 | CFX_Edit_GroupUndoItem::~CFX_Edit_GroupUndoItem() { |
| 395 | for (int i = 0, sz = m_Items.GetSize(); i < sz; i++) { |
| 396 | delete m_Items[i]; |
| 397 | } |
| 398 | |
| 399 | m_Items.RemoveAll(); |
| 400 | } |
| 401 | |
| 402 | void CFX_Edit_GroupUndoItem::AddUndoItem(CFX_Edit_UndoItem* pUndoItem) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 403 | pUndoItem->SetFirst(FALSE); |
| 404 | pUndoItem->SetLast(FALSE); |
| 405 | |
| 406 | m_Items.Add(pUndoItem); |
| 407 | |
| 408 | if (m_sTitle.IsEmpty()) |
| 409 | m_sTitle = pUndoItem->GetUndoTitle(); |
| 410 | } |
| 411 | |
| 412 | void CFX_Edit_GroupUndoItem::UpdateItems() { |
| 413 | if (m_Items.GetSize() > 0) { |
| 414 | CFX_Edit_UndoItem* pFirstItem = m_Items[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 415 | pFirstItem->SetFirst(TRUE); |
| 416 | |
| 417 | CFX_Edit_UndoItem* pLastItem = m_Items[m_Items.GetSize() - 1]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 418 | pLastItem->SetLast(TRUE); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | void CFX_Edit_GroupUndoItem::Undo() { |
| 423 | for (int i = m_Items.GetSize() - 1; i >= 0; i--) { |
| 424 | CFX_Edit_UndoItem* pUndoItem = m_Items[i]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 425 | pUndoItem->Undo(); |
| 426 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 427 | } |
| 428 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 429 | void CFX_Edit_GroupUndoItem::Redo() { |
| 430 | for (int i = 0, sz = m_Items.GetSize(); i < sz; i++) { |
| 431 | CFX_Edit_UndoItem* pUndoItem = m_Items[i]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 432 | pUndoItem->Redo(); |
| 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 | CFX_WideString CFX_Edit_GroupUndoItem::GetUndoTitle() { |
| 437 | return m_sTitle; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 440 | CFXEU_InsertWord::CFXEU_InsertWord(CFX_Edit* pEdit, |
| 441 | const CPVT_WordPlace& wpOldPlace, |
| 442 | const CPVT_WordPlace& wpNewPlace, |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 443 | uint16_t word, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 444 | int32_t charset, |
| 445 | const CPVT_WordProps* pWordProps) |
| 446 | : m_pEdit(pEdit), |
| 447 | m_wpOld(wpOldPlace), |
| 448 | m_wpNew(wpNewPlace), |
| 449 | m_Word(word), |
| 450 | m_nCharset(charset), |
| 451 | m_WordProps() { |
| 452 | if (pWordProps) |
| 453 | m_WordProps = *pWordProps; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 456 | CFXEU_InsertWord::~CFXEU_InsertWord() {} |
| 457 | |
| 458 | void CFXEU_InsertWord::Redo() { |
| 459 | if (m_pEdit) { |
| 460 | m_pEdit->SelectNone(); |
| 461 | m_pEdit->SetCaret(m_wpOld); |
| 462 | m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, FALSE, TRUE); |
| 463 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 466 | void CFXEU_InsertWord::Undo() { |
| 467 | if (m_pEdit) { |
| 468 | m_pEdit->SelectNone(); |
| 469 | m_pEdit->SetCaret(m_wpNew); |
| 470 | m_pEdit->Backspace(FALSE, TRUE); |
| 471 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 474 | CFXEU_InsertReturn::CFXEU_InsertReturn(CFX_Edit* pEdit, |
| 475 | const CPVT_WordPlace& wpOldPlace, |
| 476 | const CPVT_WordPlace& wpNewPlace, |
| 477 | const CPVT_SecProps* pSecProps, |
| 478 | const CPVT_WordProps* pWordProps) |
| 479 | : m_pEdit(pEdit), |
| 480 | m_wpOld(wpOldPlace), |
| 481 | m_wpNew(wpNewPlace), |
| 482 | m_SecProps(), |
| 483 | m_WordProps() { |
| 484 | if (pSecProps) |
| 485 | m_SecProps = *pSecProps; |
| 486 | if (pWordProps) |
| 487 | m_WordProps = *pWordProps; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 490 | CFXEU_InsertReturn::~CFXEU_InsertReturn() {} |
| 491 | |
| 492 | void CFXEU_InsertReturn::Redo() { |
| 493 | if (m_pEdit) { |
| 494 | m_pEdit->SelectNone(); |
| 495 | m_pEdit->SetCaret(m_wpOld); |
| 496 | m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, FALSE, TRUE); |
| 497 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 500 | void CFXEU_InsertReturn::Undo() { |
| 501 | if (m_pEdit) { |
| 502 | m_pEdit->SelectNone(); |
| 503 | m_pEdit->SetCaret(m_wpNew); |
| 504 | m_pEdit->Backspace(FALSE, TRUE); |
| 505 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 508 | CFXEU_Backspace::CFXEU_Backspace(CFX_Edit* pEdit, |
| 509 | const CPVT_WordPlace& wpOldPlace, |
| 510 | const CPVT_WordPlace& wpNewPlace, |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 511 | uint16_t word, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 512 | int32_t charset, |
| 513 | const CPVT_SecProps& SecProps, |
| 514 | const CPVT_WordProps& WordProps) |
| 515 | : m_pEdit(pEdit), |
| 516 | m_wpOld(wpOldPlace), |
| 517 | m_wpNew(wpNewPlace), |
| 518 | m_Word(word), |
| 519 | m_nCharset(charset), |
| 520 | m_SecProps(SecProps), |
| 521 | m_WordProps(WordProps) {} |
| 522 | |
| 523 | CFXEU_Backspace::~CFXEU_Backspace() {} |
| 524 | |
| 525 | void CFXEU_Backspace::Redo() { |
| 526 | if (m_pEdit) { |
| 527 | m_pEdit->SelectNone(); |
| 528 | m_pEdit->SetCaret(m_wpOld); |
| 529 | m_pEdit->Backspace(FALSE, TRUE); |
| 530 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 533 | void CFXEU_Backspace::Undo() { |
| 534 | if (m_pEdit) { |
| 535 | m_pEdit->SelectNone(); |
| 536 | m_pEdit->SetCaret(m_wpNew); |
| 537 | if (m_wpNew.SecCmp(m_wpOld) != 0) { |
| 538 | m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, FALSE, TRUE); |
| 539 | } else { |
| 540 | m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, FALSE, TRUE); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 541 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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_Delete::CFXEU_Delete(CFX_Edit* pEdit, |
| 546 | const CPVT_WordPlace& wpOldPlace, |
| 547 | const CPVT_WordPlace& wpNewPlace, |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 548 | uint16_t word, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 549 | int32_t charset, |
| 550 | const CPVT_SecProps& SecProps, |
| 551 | const CPVT_WordProps& WordProps, |
| 552 | FX_BOOL bSecEnd) |
| 553 | : m_pEdit(pEdit), |
| 554 | m_wpOld(wpOldPlace), |
| 555 | m_wpNew(wpNewPlace), |
| 556 | m_Word(word), |
| 557 | m_nCharset(charset), |
| 558 | m_SecProps(SecProps), |
| 559 | m_WordProps(WordProps), |
| 560 | m_bSecEnd(bSecEnd) {} |
| 561 | |
| 562 | CFXEU_Delete::~CFXEU_Delete() {} |
| 563 | |
| 564 | void CFXEU_Delete::Redo() { |
| 565 | if (m_pEdit) { |
| 566 | m_pEdit->SelectNone(); |
| 567 | m_pEdit->SetCaret(m_wpOld); |
| 568 | m_pEdit->Delete(FALSE, TRUE); |
| 569 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 572 | void CFXEU_Delete::Undo() { |
| 573 | if (m_pEdit) { |
| 574 | m_pEdit->SelectNone(); |
| 575 | m_pEdit->SetCaret(m_wpNew); |
| 576 | if (m_bSecEnd) { |
| 577 | m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, FALSE, TRUE); |
| 578 | } else { |
| 579 | m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, FALSE, TRUE); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 580 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 581 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 584 | CFXEU_Clear::CFXEU_Clear(CFX_Edit* pEdit, |
| 585 | const CPVT_WordRange& wrSel, |
| 586 | const CFX_WideString& swText) |
| 587 | : m_pEdit(pEdit), m_wrSel(wrSel), m_swText(swText) {} |
| 588 | |
| 589 | CFXEU_Clear::~CFXEU_Clear() {} |
| 590 | |
| 591 | void CFXEU_Clear::Redo() { |
| 592 | if (m_pEdit) { |
| 593 | m_pEdit->SelectNone(); |
| 594 | m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos); |
| 595 | m_pEdit->Clear(FALSE, TRUE); |
| 596 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 599 | void CFXEU_Clear::Undo() { |
| 600 | if (m_pEdit) { |
| 601 | m_pEdit->SelectNone(); |
| 602 | m_pEdit->SetCaret(m_wrSel.BeginPos); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 603 | m_pEdit->InsertText(m_swText.c_str(), DEFAULT_CHARSET, nullptr, nullptr, |
| 604 | FALSE, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 605 | m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos); |
| 606 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 609 | CFXEU_ClearRich::CFXEU_ClearRich(CFX_Edit* pEdit, |
| 610 | const CPVT_WordPlace& wpOldPlace, |
| 611 | const CPVT_WordPlace& wpNewPlace, |
| 612 | const CPVT_WordRange& wrSel, |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 613 | uint16_t word, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 614 | int32_t charset, |
| 615 | const CPVT_SecProps& SecProps, |
| 616 | const CPVT_WordProps& WordProps) |
| 617 | : m_pEdit(pEdit), |
| 618 | m_wpOld(wpOldPlace), |
| 619 | m_wpNew(wpNewPlace), |
| 620 | m_wrSel(wrSel), |
| 621 | m_Word(word), |
| 622 | m_nCharset(charset), |
| 623 | m_SecProps(SecProps), |
| 624 | m_WordProps(WordProps) {} |
| 625 | |
| 626 | CFXEU_ClearRich::~CFXEU_ClearRich() {} |
| 627 | |
| 628 | void CFXEU_ClearRich::Redo() { |
| 629 | if (m_pEdit && IsLast()) { |
| 630 | m_pEdit->SelectNone(); |
| 631 | m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos); |
| 632 | m_pEdit->Clear(FALSE, TRUE); |
| 633 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 634 | } |
| 635 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 636 | void CFXEU_ClearRich::Undo() { |
| 637 | if (m_pEdit) { |
| 638 | m_pEdit->SelectNone(); |
| 639 | m_pEdit->SetCaret(m_wpOld); |
| 640 | if (m_wpNew.SecCmp(m_wpOld) != 0) { |
| 641 | m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, FALSE, FALSE); |
| 642 | } else { |
| 643 | m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, FALSE, FALSE); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 644 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 645 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 646 | if (IsFirst()) { |
| 647 | m_pEdit->PaintInsertText(m_wrSel.BeginPos, m_wrSel.EndPos); |
| 648 | m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 649 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 650 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 651 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 652 | CFXEU_InsertText::CFXEU_InsertText(CFX_Edit* pEdit, |
| 653 | const CPVT_WordPlace& wpOldPlace, |
| 654 | const CPVT_WordPlace& wpNewPlace, |
| 655 | const CFX_WideString& swText, |
| 656 | int32_t charset, |
| 657 | const CPVT_SecProps* pSecProps, |
| 658 | const CPVT_WordProps* pWordProps) |
| 659 | : m_pEdit(pEdit), |
| 660 | m_wpOld(wpOldPlace), |
| 661 | m_wpNew(wpNewPlace), |
| 662 | m_swText(swText), |
| 663 | m_nCharset(charset), |
| 664 | m_SecProps(), |
| 665 | m_WordProps() { |
| 666 | if (pSecProps) |
| 667 | m_SecProps = *pSecProps; |
| 668 | if (pWordProps) |
| 669 | m_WordProps = *pWordProps; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 672 | CFXEU_InsertText::~CFXEU_InsertText() {} |
| 673 | |
| 674 | void CFXEU_InsertText::Redo() { |
| 675 | if (m_pEdit && IsLast()) { |
| 676 | m_pEdit->SelectNone(); |
| 677 | m_pEdit->SetCaret(m_wpOld); |
| 678 | m_pEdit->InsertText(m_swText.c_str(), m_nCharset, &m_SecProps, &m_WordProps, |
| 679 | FALSE, TRUE); |
| 680 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 683 | void CFXEU_InsertText::Undo() { |
| 684 | if (m_pEdit) { |
| 685 | m_pEdit->SelectNone(); |
| 686 | m_pEdit->SetSel(m_wpOld, m_wpNew); |
| 687 | m_pEdit->Clear(FALSE, TRUE); |
| 688 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 691 | CFXEU_SetSecProps::CFXEU_SetSecProps(CFX_Edit* pEdit, |
| 692 | const CPVT_WordPlace& place, |
| 693 | EDIT_PROPS_E ep, |
| 694 | const CPVT_SecProps& oldsecprops, |
| 695 | const CPVT_WordProps& oldwordprops, |
| 696 | const CPVT_SecProps& newsecprops, |
| 697 | const CPVT_WordProps& newwordprops, |
| 698 | const CPVT_WordRange& range) |
| 699 | : m_pEdit(pEdit), |
| 700 | m_wpPlace(place), |
| 701 | m_wrPlace(range), |
| 702 | m_eProps(ep), |
| 703 | m_OldSecProps(oldsecprops), |
| 704 | m_NewSecProps(newsecprops), |
| 705 | m_OldWordProps(oldwordprops), |
| 706 | m_NewWordProps(newwordprops) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 707 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 708 | CFXEU_SetSecProps::~CFXEU_SetSecProps() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 709 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 710 | void CFXEU_SetSecProps::Redo() { |
| 711 | if (m_pEdit) { |
| 712 | m_pEdit->SetSecProps(m_eProps, m_wpPlace, &m_NewSecProps, &m_NewWordProps, |
| 713 | m_wrPlace, FALSE); |
| 714 | if (IsLast()) { |
| 715 | m_pEdit->SelectNone(); |
| 716 | m_pEdit->PaintSetProps(m_eProps, m_wrPlace); |
| 717 | m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 718 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 719 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 722 | void CFXEU_SetSecProps::Undo() { |
| 723 | if (m_pEdit) { |
| 724 | m_pEdit->SetSecProps(m_eProps, m_wpPlace, &m_OldSecProps, &m_OldWordProps, |
| 725 | m_wrPlace, FALSE); |
| 726 | if (IsFirst()) { |
| 727 | m_pEdit->SelectNone(); |
| 728 | m_pEdit->PaintSetProps(m_eProps, m_wrPlace); |
| 729 | m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 730 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 731 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 734 | CFXEU_SetWordProps::CFXEU_SetWordProps(CFX_Edit* pEdit, |
| 735 | const CPVT_WordPlace& place, |
| 736 | EDIT_PROPS_E ep, |
| 737 | const CPVT_WordProps& oldprops, |
| 738 | const CPVT_WordProps& newprops, |
| 739 | const CPVT_WordRange& range) |
| 740 | : m_pEdit(pEdit), |
| 741 | m_wpPlace(place), |
| 742 | m_wrPlace(range), |
| 743 | m_eProps(ep), |
| 744 | m_OldWordProps(oldprops), |
| 745 | m_NewWordProps(newprops) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 746 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 747 | CFXEU_SetWordProps::~CFXEU_SetWordProps() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 748 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 749 | void CFXEU_SetWordProps::Redo() { |
| 750 | if (m_pEdit) { |
| 751 | m_pEdit->SetWordProps(m_eProps, m_wpPlace, &m_NewWordProps, m_wrPlace, |
| 752 | FALSE); |
| 753 | if (IsLast()) { |
| 754 | m_pEdit->SelectNone(); |
| 755 | m_pEdit->PaintSetProps(m_eProps, m_wrPlace); |
| 756 | m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 757 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 758 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 761 | void CFXEU_SetWordProps::Undo() { |
| 762 | if (m_pEdit) { |
| 763 | m_pEdit->SetWordProps(m_eProps, m_wpPlace, &m_OldWordProps, m_wrPlace, |
| 764 | FALSE); |
| 765 | if (IsFirst()) { |
| 766 | m_pEdit->SelectNone(); |
| 767 | m_pEdit->PaintSetProps(m_eProps, m_wrPlace); |
| 768 | m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 769 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 770 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 771 | } |
| 772 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 773 | CFX_Edit::CFX_Edit(CPDF_VariableText* pVT) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 774 | : m_pVT(pVT), |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 775 | m_pNotify(nullptr), |
| 776 | m_pOprNotify(nullptr), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 777 | m_wpCaret(-1, -1, -1), |
| 778 | m_wpOldCaret(-1, -1, -1), |
| 779 | m_SelState(), |
| 780 | m_ptScrollPos(0, 0), |
| 781 | m_ptRefreshScrollPos(0, 0), |
| 782 | m_bEnableScroll(FALSE), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 783 | m_ptCaret(0.0f, 0.0f), |
dsinclair | 8f4bf9a | 2016-05-04 13:51:51 -0700 | [diff] [blame] | 784 | m_Undo(kEditUndoMaxItems), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 785 | m_nAlignment(0), |
| 786 | m_bNotifyFlag(FALSE), |
| 787 | m_bEnableOverflow(FALSE), |
| 788 | m_bEnableRefresh(TRUE), |
| 789 | m_rcOldContent(0.0f, 0.0f, 0.0f, 0.0f), |
| 790 | m_bEnableUndo(TRUE), |
| 791 | m_bNotify(TRUE), |
| 792 | m_bOprNotify(FALSE), |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 793 | m_pGroupUndoItem(nullptr) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 794 | ASSERT(pVT); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 795 | } |
| 796 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 797 | CFX_Edit::~CFX_Edit() { |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 798 | ASSERT(!m_pGroupUndoItem); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 801 | void CFX_Edit::Initialize() { |
| 802 | m_pVT->Initialize(); |
| 803 | SetCaret(m_pVT->GetBeginWordPlace()); |
| 804 | SetCaretOrigin(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 805 | } |
| 806 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 807 | void CFX_Edit::SetFontMap(IPVT_FontMap* pFontMap) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 808 | m_pVTProvider.reset(new CFX_Edit_Provider(pFontMap)); |
| 809 | m_pVT->SetProvider(m_pVTProvider.get()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 812 | void CFX_Edit::SetNotify(IFX_Edit_Notify* pNotify) { |
| 813 | m_pNotify = pNotify; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 816 | void CFX_Edit::SetOprNotify(IFX_Edit_OprNotify* pOprNotify) { |
| 817 | m_pOprNotify = pOprNotify; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 820 | IFX_Edit_Iterator* CFX_Edit::GetIterator() { |
| 821 | if (!m_pIterator) |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 822 | m_pIterator.reset(new CFX_Edit_Iterator(this, m_pVT->GetIterator())); |
| 823 | return m_pIterator.get(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 824 | } |
| 825 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 826 | CPDF_VariableText* CFX_Edit::GetVariableText() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 827 | return m_pVT; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 828 | } |
| 829 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 830 | IPVT_FontMap* CFX_Edit::GetFontMap() { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 831 | return m_pVTProvider ? m_pVTProvider->GetFontMap() : nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 832 | } |
| 833 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 834 | void CFX_Edit::SetPlateRect(const CFX_FloatRect& rect, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 835 | m_pVT->SetPlateRect(rect); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 836 | m_ptScrollPos = CFX_FloatPoint(rect.left, rect.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 837 | if (bPaint) |
| 838 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 841 | void CFX_Edit::SetAlignmentH(int32_t nFormat, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 842 | m_pVT->SetAlignment(nFormat); |
| 843 | if (bPaint) |
| 844 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 845 | } |
| 846 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 847 | void CFX_Edit::SetAlignmentV(int32_t nFormat, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 848 | m_nAlignment = nFormat; |
| 849 | if (bPaint) |
| 850 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 851 | } |
| 852 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 853 | void CFX_Edit::SetPasswordChar(uint16_t wSubWord, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 854 | m_pVT->SetPasswordChar(wSubWord); |
| 855 | if (bPaint) |
| 856 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 859 | void CFX_Edit::SetLimitChar(int32_t nLimitChar, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 860 | m_pVT->SetLimitChar(nLimitChar); |
| 861 | if (bPaint) |
| 862 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 863 | } |
| 864 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 865 | void CFX_Edit::SetCharArray(int32_t nCharArray, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 866 | m_pVT->SetCharArray(nCharArray); |
| 867 | if (bPaint) |
| 868 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 871 | void CFX_Edit::SetCharSpace(FX_FLOAT fCharSpace, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 872 | m_pVT->SetCharSpace(fCharSpace); |
| 873 | if (bPaint) |
| 874 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 877 | void CFX_Edit::SetHorzScale(int32_t nHorzScale, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 878 | m_pVT->SetHorzScale(nHorzScale); |
| 879 | if (bPaint) |
| 880 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 881 | } |
| 882 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 883 | void CFX_Edit::SetMultiLine(FX_BOOL bMultiLine, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 884 | m_pVT->SetMultiLine(bMultiLine); |
| 885 | if (bPaint) |
| 886 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 889 | void CFX_Edit::SetAutoReturn(FX_BOOL bAuto, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 890 | m_pVT->SetAutoReturn(bAuto); |
| 891 | if (bPaint) |
| 892 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 895 | void CFX_Edit::SetLineLeading(FX_FLOAT fLineLeading, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 896 | m_pVT->SetLineLeading(fLineLeading); |
| 897 | if (bPaint) |
| 898 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 899 | } |
| 900 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 901 | void CFX_Edit::SetAutoFontSize(FX_BOOL bAuto, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 902 | m_pVT->SetAutoFontSize(bAuto); |
| 903 | if (bPaint) |
| 904 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 907 | void CFX_Edit::SetFontSize(FX_FLOAT fFontSize, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 908 | m_pVT->SetFontSize(fFontSize); |
| 909 | if (bPaint) |
| 910 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 911 | } |
| 912 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 913 | void CFX_Edit::SetAutoScroll(FX_BOOL bAuto, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 914 | m_bEnableScroll = bAuto; |
| 915 | if (bPaint) |
| 916 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 919 | void CFX_Edit::SetTextOverflow(FX_BOOL bAllowed, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 920 | m_bEnableOverflow = bAllowed; |
| 921 | if (bPaint) |
| 922 | Paint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 925 | void CFX_Edit::SetSel(int32_t nStartChar, int32_t nEndChar) { |
| 926 | if (m_pVT->IsValid()) { |
| 927 | if (nStartChar == 0 && nEndChar < 0) { |
| 928 | SelectAll(); |
| 929 | } else if (nStartChar < 0) { |
| 930 | SelectNone(); |
| 931 | } else { |
| 932 | if (nStartChar < nEndChar) { |
| 933 | SetSel(m_pVT->WordIndexToWordPlace(nStartChar), |
| 934 | m_pVT->WordIndexToWordPlace(nEndChar)); |
| 935 | } else { |
| 936 | SetSel(m_pVT->WordIndexToWordPlace(nEndChar), |
| 937 | m_pVT->WordIndexToWordPlace(nStartChar)); |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | void CFX_Edit::SetSel(const CPVT_WordPlace& begin, const CPVT_WordPlace& end) { |
| 944 | if (m_pVT->IsValid()) { |
| 945 | SelectNone(); |
| 946 | |
| 947 | m_SelState.Set(begin, end); |
| 948 | |
| 949 | SetCaret(m_SelState.EndPos); |
| 950 | |
| 951 | if (m_SelState.IsExist()) { |
| 952 | ScrollToCaret(); |
| 953 | CPVT_WordRange wr(m_SelState.BeginPos, m_SelState.EndPos); |
| 954 | Refresh(RP_OPTIONAL, &wr); |
| 955 | SetCaretInfo(); |
| 956 | } else { |
| 957 | ScrollToCaret(); |
| 958 | SetCaretInfo(); |
| 959 | } |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | void CFX_Edit::GetSel(int32_t& nStartChar, int32_t& nEndChar) const { |
| 964 | nStartChar = -1; |
| 965 | nEndChar = -1; |
| 966 | |
| 967 | if (m_pVT->IsValid()) { |
| 968 | if (m_SelState.IsExist()) { |
| 969 | if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) < 0) { |
| 970 | nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos); |
| 971 | nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos); |
| 972 | } else { |
| 973 | nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos); |
| 974 | nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos); |
| 975 | } |
| 976 | } else { |
| 977 | nStartChar = m_pVT->WordPlaceToWordIndex(m_wpCaret); |
| 978 | nEndChar = m_pVT->WordPlaceToWordIndex(m_wpCaret); |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | int32_t CFX_Edit::GetCaret() const { |
| 984 | if (m_pVT->IsValid()) |
| 985 | return m_pVT->WordPlaceToWordIndex(m_wpCaret); |
| 986 | |
| 987 | return -1; |
| 988 | } |
| 989 | |
| 990 | CPVT_WordPlace CFX_Edit::GetCaretWordPlace() const { |
| 991 | return m_wpCaret; |
| 992 | } |
| 993 | |
| 994 | CFX_WideString CFX_Edit::GetText() const { |
| 995 | CFX_WideString swRet; |
| 996 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 997 | if (!m_pVT->IsValid()) |
| 998 | return swRet; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 999 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1000 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 1001 | pIterator->SetAt(0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1002 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1003 | CPVT_Word wordinfo; |
| 1004 | CPVT_WordPlace oldplace = pIterator->GetAt(); |
| 1005 | while (pIterator->NextWord()) { |
| 1006 | CPVT_WordPlace place = pIterator->GetAt(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1007 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1008 | if (pIterator->GetWord(wordinfo)) |
| 1009 | swRet += wordinfo.Word; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1010 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1011 | if (oldplace.SecCmp(place) != 0) |
| 1012 | swRet += L"\r\n"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1013 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1014 | oldplace = place; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | return swRet; |
| 1018 | } |
| 1019 | |
| 1020 | CFX_WideString CFX_Edit::GetRangeText(const CPVT_WordRange& range) const { |
| 1021 | CFX_WideString swRet; |
| 1022 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1023 | if (!m_pVT->IsValid()) |
| 1024 | return swRet; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1025 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1026 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 1027 | CPVT_WordRange wrTemp = range; |
| 1028 | m_pVT->UpdateWordPlace(wrTemp.BeginPos); |
| 1029 | m_pVT->UpdateWordPlace(wrTemp.EndPos); |
| 1030 | pIterator->SetAt(wrTemp.BeginPos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1031 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1032 | CPVT_Word wordinfo; |
| 1033 | CPVT_WordPlace oldplace = wrTemp.BeginPos; |
| 1034 | while (pIterator->NextWord()) { |
| 1035 | CPVT_WordPlace place = pIterator->GetAt(); |
| 1036 | if (place.WordCmp(wrTemp.EndPos) > 0) |
| 1037 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1038 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1039 | if (pIterator->GetWord(wordinfo)) |
| 1040 | swRet += wordinfo.Word; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1041 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1042 | if (oldplace.SecCmp(place) != 0) |
| 1043 | swRet += L"\r\n"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1044 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1045 | oldplace = place; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | return swRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1051 | CFX_WideString CFX_Edit::GetSelText() const { |
| 1052 | return GetRangeText(m_SelState.ConvertToWordRange()); |
| 1053 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1054 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1055 | int32_t CFX_Edit::GetTotalWords() const { |
| 1056 | return m_pVT->GetTotalWords(); |
| 1057 | } |
| 1058 | |
| 1059 | int32_t CFX_Edit::GetTotalLines() const { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1060 | int32_t nLines = 1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1061 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1062 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 1063 | pIterator->SetAt(0); |
| 1064 | while (pIterator->NextLine()) |
| 1065 | ++nLines; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1066 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1067 | return nLines; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | CPVT_WordRange CFX_Edit::GetSelectWordRange() const { |
| 1071 | return m_SelState.ConvertToWordRange(); |
| 1072 | } |
| 1073 | |
| 1074 | CPVT_WordRange CFX_Edit::CombineWordRange(const CPVT_WordRange& wr1, |
| 1075 | const CPVT_WordRange& wr2) { |
| 1076 | CPVT_WordRange wrRet; |
| 1077 | |
| 1078 | if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) { |
| 1079 | wrRet.BeginPos = wr1.BeginPos; |
| 1080 | } else { |
| 1081 | wrRet.BeginPos = wr2.BeginPos; |
| 1082 | } |
| 1083 | |
| 1084 | if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) { |
| 1085 | wrRet.EndPos = wr2.EndPos; |
| 1086 | } else { |
| 1087 | wrRet.EndPos = wr1.EndPos; |
| 1088 | } |
| 1089 | |
| 1090 | return wrRet; |
| 1091 | } |
| 1092 | |
| 1093 | FX_BOOL CFX_Edit::IsRichText() const { |
| 1094 | return m_pVT->IsRichText(); |
| 1095 | } |
| 1096 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1097 | void CFX_Edit::SetRichText(FX_BOOL bRichText, FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1098 | m_pVT->SetRichText(bRichText); |
| 1099 | if (bPaint) |
| 1100 | Paint(); |
| 1101 | } |
| 1102 | |
| 1103 | FX_BOOL CFX_Edit::SetRichFontIndex(int32_t nFontIndex) { |
| 1104 | CPVT_WordProps WordProps; |
| 1105 | WordProps.nFontIndex = nFontIndex; |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 1106 | return SetRichTextProps(EP_FONTINDEX, nullptr, &WordProps); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | FX_BOOL CFX_Edit::SetRichFontSize(FX_FLOAT fFontSize) { |
| 1110 | CPVT_WordProps WordProps; |
| 1111 | WordProps.fFontSize = fFontSize; |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 1112 | return SetRichTextProps(EP_FONTSIZE, nullptr, &WordProps); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | FX_BOOL CFX_Edit::SetRichTextColor(FX_COLORREF dwColor) { |
| 1116 | CPVT_WordProps WordProps; |
| 1117 | WordProps.dwWordColor = dwColor; |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 1118 | return SetRichTextProps(EP_WORDCOLOR, nullptr, &WordProps); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 1121 | FX_BOOL CFX_Edit::SetRichTextScript(CPDF_VariableText::ScriptType nScriptType) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1122 | CPVT_WordProps WordProps; |
| 1123 | WordProps.nScriptType = nScriptType; |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 1124 | return SetRichTextProps(EP_SCRIPTTYPE, nullptr, &WordProps); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | FX_BOOL CFX_Edit::SetRichTextBold(FX_BOOL bBold) { |
| 1128 | CPVT_WordProps WordProps; |
| 1129 | if (bBold) |
| 1130 | WordProps.nWordStyle |= PVTWORD_STYLE_BOLD; |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 1131 | return SetRichTextProps(EP_BOLD, nullptr, &WordProps); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | FX_BOOL CFX_Edit::SetRichTextItalic(FX_BOOL bItalic) { |
| 1135 | CPVT_WordProps WordProps; |
| 1136 | if (bItalic) |
| 1137 | WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC; |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 1138 | return SetRichTextProps(EP_ITALIC, nullptr, &WordProps); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | FX_BOOL CFX_Edit::SetRichTextUnderline(FX_BOOL bUnderline) { |
| 1142 | CPVT_WordProps WordProps; |
| 1143 | if (bUnderline) |
| 1144 | WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE; |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 1145 | return SetRichTextProps(EP_UNDERLINE, nullptr, &WordProps); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | FX_BOOL CFX_Edit::SetRichTextCrossout(FX_BOOL bCrossout) { |
| 1149 | CPVT_WordProps WordProps; |
| 1150 | if (bCrossout) |
| 1151 | WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT; |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 1152 | return SetRichTextProps(EP_CROSSOUT, nullptr, &WordProps); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | FX_BOOL CFX_Edit::SetRichTextCharSpace(FX_FLOAT fCharSpace) { |
| 1156 | CPVT_WordProps WordProps; |
| 1157 | WordProps.fCharSpace = fCharSpace; |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 1158 | return SetRichTextProps(EP_CHARSPACE, nullptr, &WordProps); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1161 | FX_BOOL CFX_Edit::SetRichTextHorzScale(int32_t nHorzScale) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1162 | CPVT_WordProps WordProps; |
| 1163 | WordProps.nHorzScale = nHorzScale; |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 1164 | return SetRichTextProps(EP_HORZSCALE, nullptr, &WordProps); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | FX_BOOL CFX_Edit::SetRichTextLineLeading(FX_FLOAT fLineLeading) { |
| 1168 | CPVT_SecProps SecProps; |
| 1169 | SecProps.fLineLeading = fLineLeading; |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 1170 | return SetRichTextProps(EP_LINELEADING, &SecProps, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | FX_BOOL CFX_Edit::SetRichTextLineIndent(FX_FLOAT fLineIndent) { |
| 1174 | CPVT_SecProps SecProps; |
| 1175 | SecProps.fLineIndent = fLineIndent; |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 1176 | return SetRichTextProps(EP_LINEINDENT, &SecProps, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | FX_BOOL CFX_Edit::SetRichTextAlignment(int32_t nAlignment) { |
| 1180 | CPVT_SecProps SecProps; |
| 1181 | SecProps.nAlignment = nAlignment; |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 1182 | return SetRichTextProps(EP_ALIGNMENT, &SecProps, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | FX_BOOL CFX_Edit::SetRichTextProps(EDIT_PROPS_E eProps, |
| 1186 | const CPVT_SecProps* pSecProps, |
| 1187 | const CPVT_WordProps* pWordProps) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1188 | if (!m_pVT->IsValid() || !m_pVT->IsRichText()) |
| 1189 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1190 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1191 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 1192 | CPVT_WordRange wrTemp = m_SelState.ConvertToWordRange(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1193 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1194 | m_pVT->UpdateWordPlace(wrTemp.BeginPos); |
| 1195 | m_pVT->UpdateWordPlace(wrTemp.EndPos); |
| 1196 | pIterator->SetAt(wrTemp.BeginPos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1197 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1198 | BeginGroupUndo(L""); |
| 1199 | FX_BOOL bSet = |
| 1200 | SetSecProps(eProps, wrTemp.BeginPos, pSecProps, pWordProps, wrTemp, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1201 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1202 | while (pIterator->NextWord()) { |
| 1203 | CPVT_WordPlace place = pIterator->GetAt(); |
| 1204 | if (place.WordCmp(wrTemp.EndPos) > 0) |
| 1205 | break; |
| 1206 | FX_BOOL bSet1 = |
| 1207 | SetSecProps(eProps, place, pSecProps, pWordProps, wrTemp, TRUE); |
| 1208 | FX_BOOL bSet2 = SetWordProps(eProps, place, pWordProps, wrTemp, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1209 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1210 | if (!bSet) |
| 1211 | bSet = (bSet1 || bSet2); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1214 | EndGroupUndo(); |
| 1215 | |
| 1216 | if (bSet) |
| 1217 | PaintSetProps(eProps, wrTemp); |
| 1218 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1219 | return bSet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1222 | void CFX_Edit::PaintSetProps(EDIT_PROPS_E eProps, const CPVT_WordRange& wr) { |
| 1223 | switch (eProps) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1224 | case EP_LINELEADING: |
| 1225 | case EP_LINEINDENT: |
| 1226 | case EP_ALIGNMENT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1227 | RearrangePart(wr); |
| 1228 | ScrollToCaret(); |
| 1229 | Refresh(RP_ANALYSE); |
| 1230 | SetCaretOrigin(); |
| 1231 | SetCaretInfo(); |
| 1232 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1233 | case EP_WORDCOLOR: |
| 1234 | case EP_UNDERLINE: |
| 1235 | case EP_CROSSOUT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1236 | Refresh(RP_OPTIONAL, &wr); |
| 1237 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1238 | case EP_FONTINDEX: |
| 1239 | case EP_FONTSIZE: |
| 1240 | case EP_SCRIPTTYPE: |
| 1241 | case EP_CHARSPACE: |
| 1242 | case EP_HORZSCALE: |
| 1243 | case EP_BOLD: |
| 1244 | case EP_ITALIC: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1245 | RearrangePart(wr); |
| 1246 | ScrollToCaret(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1247 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1248 | CPVT_WordRange wrRefresh(m_pVT->GetSectionBeginPlace(wr.BeginPos), |
| 1249 | m_pVT->GetSectionEndPlace(wr.EndPos)); |
| 1250 | Refresh(RP_ANALYSE, &wrRefresh); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1251 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1252 | SetCaretOrigin(); |
| 1253 | SetCaretInfo(); |
| 1254 | break; |
| 1255 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1256 | } |
| 1257 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1258 | FX_BOOL CFX_Edit::SetSecProps(EDIT_PROPS_E eProps, |
| 1259 | const CPVT_WordPlace& place, |
| 1260 | const CPVT_SecProps* pSecProps, |
| 1261 | const CPVT_WordProps* pWordProps, |
| 1262 | const CPVT_WordRange& wr, |
| 1263 | FX_BOOL bAddUndo) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1264 | if (!m_pVT->IsValid() || !m_pVT->IsRichText()) |
| 1265 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1266 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1267 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 1268 | FX_BOOL bSet = FALSE; |
| 1269 | CPVT_Section secinfo; |
| 1270 | CPVT_Section OldSecinfo; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1271 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1272 | CPVT_WordPlace oldplace = pIterator->GetAt(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1273 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1274 | if (eProps == EP_LINELEADING || eProps == EP_LINEINDENT || |
| 1275 | eProps == EP_ALIGNMENT) { |
| 1276 | if (pSecProps) { |
| 1277 | pIterator->SetAt(place); |
| 1278 | if (pIterator->GetSection(secinfo)) { |
| 1279 | if (bAddUndo) |
| 1280 | OldSecinfo = secinfo; |
| 1281 | |
| 1282 | switch (eProps) { |
| 1283 | case EP_LINELEADING: |
| 1284 | if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineLeading, |
| 1285 | pSecProps->fLineLeading)) { |
| 1286 | secinfo.SecProps.fLineLeading = pSecProps->fLineLeading; |
| 1287 | bSet = TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1288 | } |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1289 | break; |
| 1290 | case EP_LINEINDENT: |
| 1291 | if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineIndent, |
| 1292 | pSecProps->fLineIndent)) { |
| 1293 | secinfo.SecProps.fLineIndent = pSecProps->fLineIndent; |
| 1294 | bSet = TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1295 | } |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1296 | break; |
| 1297 | case EP_ALIGNMENT: |
| 1298 | if (secinfo.SecProps.nAlignment != pSecProps->nAlignment) { |
| 1299 | secinfo.SecProps.nAlignment = pSecProps->nAlignment; |
| 1300 | bSet = TRUE; |
| 1301 | } |
| 1302 | break; |
| 1303 | default: |
| 1304 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1305 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1306 | } |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1307 | } |
| 1308 | } else { |
| 1309 | if (pWordProps && place == m_pVT->GetSectionBeginPlace(place)) { |
| 1310 | pIterator->SetAt(place); |
| 1311 | if (pIterator->GetSection(secinfo)) { |
| 1312 | if (bAddUndo) |
| 1313 | OldSecinfo = secinfo; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1314 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1315 | switch (eProps) { |
| 1316 | case EP_FONTINDEX: |
| 1317 | if (secinfo.WordProps.nFontIndex != pWordProps->nFontIndex) { |
| 1318 | secinfo.WordProps.nFontIndex = pWordProps->nFontIndex; |
| 1319 | bSet = TRUE; |
| 1320 | } |
| 1321 | break; |
| 1322 | case EP_FONTSIZE: |
| 1323 | if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fFontSize, |
| 1324 | pWordProps->fFontSize)) { |
| 1325 | secinfo.WordProps.fFontSize = pWordProps->fFontSize; |
| 1326 | bSet = TRUE; |
| 1327 | } |
| 1328 | break; |
| 1329 | case EP_WORDCOLOR: |
| 1330 | if (secinfo.WordProps.dwWordColor != pWordProps->dwWordColor) { |
| 1331 | secinfo.WordProps.dwWordColor = pWordProps->dwWordColor; |
| 1332 | bSet = TRUE; |
| 1333 | } |
| 1334 | break; |
| 1335 | case EP_SCRIPTTYPE: |
| 1336 | if (secinfo.WordProps.nScriptType != pWordProps->nScriptType) { |
| 1337 | secinfo.WordProps.nScriptType = pWordProps->nScriptType; |
| 1338 | bSet = TRUE; |
| 1339 | } |
| 1340 | break; |
| 1341 | case EP_CHARSPACE: |
| 1342 | if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fCharSpace, |
| 1343 | pWordProps->fCharSpace)) { |
| 1344 | secinfo.WordProps.fCharSpace = pWordProps->fCharSpace; |
| 1345 | bSet = TRUE; |
| 1346 | } |
| 1347 | break; |
| 1348 | case EP_HORZSCALE: |
| 1349 | if (secinfo.WordProps.nHorzScale != pWordProps->nHorzScale) { |
| 1350 | secinfo.WordProps.nHorzScale = pWordProps->nHorzScale; |
| 1351 | bSet = TRUE; |
| 1352 | } |
| 1353 | break; |
| 1354 | case EP_UNDERLINE: |
| 1355 | if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE) { |
| 1356 | if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) == |
| 1357 | 0) { |
| 1358 | secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE; |
| 1359 | bSet = TRUE; |
| 1360 | } |
| 1361 | } else { |
| 1362 | if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) != |
| 1363 | 0) { |
| 1364 | secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_UNDERLINE; |
| 1365 | bSet = TRUE; |
| 1366 | } |
| 1367 | } |
| 1368 | break; |
| 1369 | case EP_CROSSOUT: |
| 1370 | if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT) { |
| 1371 | if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) == |
| 1372 | 0) { |
| 1373 | secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT; |
| 1374 | bSet = TRUE; |
| 1375 | } |
| 1376 | } else { |
| 1377 | if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) != |
| 1378 | 0) { |
| 1379 | secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_CROSSOUT; |
| 1380 | bSet = TRUE; |
| 1381 | } |
| 1382 | } |
| 1383 | break; |
| 1384 | case EP_BOLD: |
| 1385 | if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD) { |
| 1386 | if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) == 0) { |
| 1387 | secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_BOLD; |
| 1388 | bSet = TRUE; |
| 1389 | } |
| 1390 | } else { |
| 1391 | if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) != 0) { |
| 1392 | secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_BOLD; |
| 1393 | bSet = TRUE; |
| 1394 | } |
| 1395 | } |
| 1396 | break; |
| 1397 | case EP_ITALIC: |
| 1398 | if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC) { |
| 1399 | if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) == 0) { |
| 1400 | secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC; |
| 1401 | bSet = TRUE; |
| 1402 | } |
| 1403 | } else { |
| 1404 | if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) != 0) { |
| 1405 | secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_ITALIC; |
| 1406 | bSet = TRUE; |
| 1407 | } |
| 1408 | } |
| 1409 | break; |
| 1410 | default: |
| 1411 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1412 | } |
| 1413 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1414 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1415 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1416 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1417 | if (bSet) { |
| 1418 | pIterator->SetSection(secinfo); |
| 1419 | |
| 1420 | if (bAddUndo && m_bEnableUndo) { |
| 1421 | AddEditUndoItem(new CFXEU_SetSecProps( |
| 1422 | this, place, eProps, OldSecinfo.SecProps, OldSecinfo.WordProps, |
| 1423 | secinfo.SecProps, secinfo.WordProps, wr)); |
| 1424 | } |
| 1425 | } |
| 1426 | |
| 1427 | pIterator->SetAt(oldplace); |
| 1428 | |
| 1429 | return bSet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1432 | FX_BOOL CFX_Edit::SetWordProps(EDIT_PROPS_E eProps, |
| 1433 | const CPVT_WordPlace& place, |
| 1434 | const CPVT_WordProps* pWordProps, |
| 1435 | const CPVT_WordRange& wr, |
| 1436 | FX_BOOL bAddUndo) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1437 | if (!m_pVT->IsValid() || !m_pVT->IsRichText()) |
| 1438 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1439 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1440 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 1441 | FX_BOOL bSet = FALSE; |
| 1442 | CPVT_Word wordinfo; |
| 1443 | CPVT_Word OldWordinfo; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1444 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1445 | CPVT_WordPlace oldplace = pIterator->GetAt(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1446 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1447 | if (pWordProps) { |
| 1448 | pIterator->SetAt(place); |
| 1449 | if (pIterator->GetWord(wordinfo)) { |
| 1450 | if (bAddUndo) |
| 1451 | OldWordinfo = wordinfo; |
| 1452 | |
| 1453 | switch (eProps) { |
| 1454 | case EP_FONTINDEX: |
| 1455 | if (wordinfo.WordProps.nFontIndex != pWordProps->nFontIndex) { |
| 1456 | if (IPVT_FontMap* pFontMap = GetFontMap()) { |
| 1457 | wordinfo.WordProps.nFontIndex = pFontMap->GetWordFontIndex( |
| 1458 | wordinfo.Word, wordinfo.nCharset, pWordProps->nFontIndex); |
| 1459 | } |
| 1460 | bSet = TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1461 | } |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1462 | break; |
| 1463 | case EP_FONTSIZE: |
| 1464 | if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fFontSize, |
| 1465 | pWordProps->fFontSize)) { |
| 1466 | wordinfo.WordProps.fFontSize = pWordProps->fFontSize; |
| 1467 | bSet = TRUE; |
| 1468 | } |
| 1469 | break; |
| 1470 | case EP_WORDCOLOR: |
| 1471 | if (wordinfo.WordProps.dwWordColor != pWordProps->dwWordColor) { |
| 1472 | wordinfo.WordProps.dwWordColor = pWordProps->dwWordColor; |
| 1473 | bSet = TRUE; |
| 1474 | } |
| 1475 | break; |
| 1476 | case EP_SCRIPTTYPE: |
| 1477 | if (wordinfo.WordProps.nScriptType != pWordProps->nScriptType) { |
| 1478 | wordinfo.WordProps.nScriptType = pWordProps->nScriptType; |
| 1479 | bSet = TRUE; |
| 1480 | } |
| 1481 | break; |
| 1482 | case EP_CHARSPACE: |
| 1483 | if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fCharSpace, |
| 1484 | pWordProps->fCharSpace)) { |
| 1485 | wordinfo.WordProps.fCharSpace = pWordProps->fCharSpace; |
| 1486 | bSet = TRUE; |
| 1487 | } |
| 1488 | break; |
| 1489 | case EP_HORZSCALE: |
| 1490 | if (wordinfo.WordProps.nHorzScale != pWordProps->nHorzScale) { |
| 1491 | wordinfo.WordProps.nHorzScale = pWordProps->nHorzScale; |
| 1492 | bSet = TRUE; |
| 1493 | } |
| 1494 | break; |
| 1495 | case EP_UNDERLINE: |
| 1496 | if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE) { |
| 1497 | if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) == |
| 1498 | 0) { |
| 1499 | wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE; |
| 1500 | bSet = TRUE; |
| 1501 | } |
| 1502 | } else { |
| 1503 | if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) != |
| 1504 | 0) { |
| 1505 | wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_UNDERLINE; |
| 1506 | bSet = TRUE; |
| 1507 | } |
| 1508 | } |
| 1509 | break; |
| 1510 | case EP_CROSSOUT: |
| 1511 | if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT) { |
| 1512 | if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) == 0) { |
| 1513 | wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT; |
| 1514 | bSet = TRUE; |
| 1515 | } |
| 1516 | } else { |
| 1517 | if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) != 0) { |
| 1518 | wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_CROSSOUT; |
| 1519 | bSet = TRUE; |
| 1520 | } |
| 1521 | } |
| 1522 | break; |
| 1523 | case EP_BOLD: |
| 1524 | if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD) { |
| 1525 | if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) == 0) { |
| 1526 | wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_BOLD; |
| 1527 | bSet = TRUE; |
| 1528 | } |
| 1529 | } else { |
| 1530 | if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) != 0) { |
| 1531 | wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_BOLD; |
| 1532 | bSet = TRUE; |
| 1533 | } |
| 1534 | } |
| 1535 | break; |
| 1536 | case EP_ITALIC: |
| 1537 | if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC) { |
| 1538 | if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) == 0) { |
| 1539 | wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC; |
| 1540 | bSet = TRUE; |
| 1541 | } |
| 1542 | } else { |
| 1543 | if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) != 0) { |
| 1544 | wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_ITALIC; |
| 1545 | bSet = TRUE; |
| 1546 | } |
| 1547 | } |
| 1548 | break; |
| 1549 | default: |
| 1550 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1551 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1552 | } |
| 1553 | } |
| 1554 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1555 | if (bSet) { |
| 1556 | pIterator->SetWord(wordinfo); |
| 1557 | |
| 1558 | if (bAddUndo && m_bEnableUndo) { |
| 1559 | AddEditUndoItem(new CFXEU_SetWordProps( |
| 1560 | this, place, eProps, OldWordinfo.WordProps, wordinfo.WordProps, wr)); |
| 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | pIterator->SetAt(oldplace); |
| 1565 | return bSet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1568 | void CFX_Edit::SetText(const FX_WCHAR* text, |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1569 | int32_t charset, |
| 1570 | const CPVT_SecProps* pSecProps, |
| 1571 | const CPVT_WordProps* pWordProps) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1572 | SetText(text, charset, pSecProps, pWordProps, TRUE, TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1573 | } |
| 1574 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 1575 | FX_BOOL CFX_Edit::InsertWord(uint16_t word, |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1576 | int32_t charset, |
| 1577 | const CPVT_WordProps* pWordProps) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1578 | return InsertWord(word, charset, pWordProps, TRUE, TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1581 | FX_BOOL CFX_Edit::InsertReturn(const CPVT_SecProps* pSecProps, |
| 1582 | const CPVT_WordProps* pWordProps) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1583 | return InsertReturn(pSecProps, pWordProps, TRUE, TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1586 | FX_BOOL CFX_Edit::Backspace() { |
| 1587 | return Backspace(TRUE, TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1590 | FX_BOOL CFX_Edit::Delete() { |
| 1591 | return Delete(TRUE, TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1594 | FX_BOOL CFX_Edit::Clear() { |
| 1595 | return Clear(TRUE, TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1596 | } |
| 1597 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1598 | FX_BOOL CFX_Edit::InsertText(const FX_WCHAR* text, |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1599 | int32_t charset, |
| 1600 | const CPVT_SecProps* pSecProps, |
| 1601 | const CPVT_WordProps* pWordProps) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1602 | return InsertText(text, charset, pSecProps, pWordProps, TRUE, TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1603 | } |
| 1604 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1605 | FX_FLOAT CFX_Edit::GetFontSize() const { |
| 1606 | return m_pVT->GetFontSize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 1609 | uint16_t CFX_Edit::GetPasswordChar() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1610 | return m_pVT->GetPasswordChar(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1611 | } |
| 1612 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1613 | int32_t CFX_Edit::GetCharArray() const { |
| 1614 | return m_pVT->GetCharArray(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1615 | } |
| 1616 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1617 | CFX_FloatRect CFX_Edit::GetPlateRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1618 | return m_pVT->GetPlateRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1619 | } |
| 1620 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1621 | CFX_FloatRect CFX_Edit::GetContentRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1622 | return VTToEdit(m_pVT->GetContentRect()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1623 | } |
| 1624 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1625 | int32_t CFX_Edit::GetHorzScale() const { |
| 1626 | return m_pVT->GetHorzScale(); |
| 1627 | } |
| 1628 | |
| 1629 | FX_FLOAT CFX_Edit::GetCharSpace() const { |
| 1630 | return m_pVT->GetCharSpace(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1631 | } |
| 1632 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1633 | CPVT_WordRange CFX_Edit::GetWholeWordRange() const { |
| 1634 | if (m_pVT->IsValid()) |
| 1635 | return CPVT_WordRange(m_pVT->GetBeginWordPlace(), m_pVT->GetEndWordPlace()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1636 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1637 | return CPVT_WordRange(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1638 | } |
| 1639 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1640 | CPVT_WordRange CFX_Edit::GetVisibleWordRange() const { |
| 1641 | if (m_bEnableOverflow) |
| 1642 | return GetWholeWordRange(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1643 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1644 | if (m_pVT->IsValid()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1645 | CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1646 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1647 | CPVT_WordPlace place1 = m_pVT->SearchWordPlace( |
| 1648 | EditToVT(CFX_FloatPoint(rcPlate.left, rcPlate.top))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1649 | CPVT_WordPlace place2 = m_pVT->SearchWordPlace( |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1650 | EditToVT(CFX_FloatPoint(rcPlate.right, rcPlate.bottom))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1651 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1652 | return CPVT_WordRange(place1, place2); |
| 1653 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 1654 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1655 | return CPVT_WordRange(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1658 | CPVT_WordPlace CFX_Edit::SearchWordPlace(const CFX_FloatPoint& point) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1659 | if (m_pVT->IsValid()) { |
| 1660 | return m_pVT->SearchWordPlace(EditToVT(point)); |
| 1661 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1662 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1663 | return CPVT_WordPlace(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1664 | } |
| 1665 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1666 | void CFX_Edit::Paint() { |
| 1667 | if (m_pVT->IsValid()) { |
| 1668 | RearrangeAll(); |
| 1669 | ScrollToCaret(); |
| 1670 | Refresh(RP_NOANALYSE); |
| 1671 | SetCaretOrigin(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1672 | SetCaretInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1673 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1676 | void CFX_Edit::RearrangeAll() { |
| 1677 | if (m_pVT->IsValid()) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1678 | m_pVT->UpdateWordPlace(m_wpCaret); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1679 | m_pVT->RearrangeAll(); |
| 1680 | m_pVT->UpdateWordPlace(m_wpCaret); |
| 1681 | SetScrollInfo(); |
| 1682 | SetContentChanged(); |
| 1683 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1684 | } |
| 1685 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1686 | void CFX_Edit::RearrangePart(const CPVT_WordRange& range) { |
| 1687 | if (m_pVT->IsValid()) { |
| 1688 | m_pVT->UpdateWordPlace(m_wpCaret); |
| 1689 | m_pVT->RearrangePart(range); |
| 1690 | m_pVT->UpdateWordPlace(m_wpCaret); |
| 1691 | SetScrollInfo(); |
| 1692 | SetContentChanged(); |
| 1693 | } |
| 1694 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 1695 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1696 | void CFX_Edit::SetContentChanged() { |
| 1697 | if (m_bNotify && m_pNotify) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1698 | CFX_FloatRect rcContent = m_pVT->GetContentRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1699 | if (rcContent.Width() != m_rcOldContent.Width() || |
| 1700 | rcContent.Height() != m_rcOldContent.Height()) { |
| 1701 | if (!m_bNotifyFlag) { |
| 1702 | m_bNotifyFlag = TRUE; |
| 1703 | m_pNotify->IOnContentChange(rcContent); |
| 1704 | m_bNotifyFlag = FALSE; |
| 1705 | } |
| 1706 | m_rcOldContent = rcContent; |
| 1707 | } |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | void CFX_Edit::SelectAll() { |
| 1712 | if (m_pVT->IsValid()) { |
Lei Zhang | 375a864 | 2016-01-11 11:59:17 -0800 | [diff] [blame] | 1713 | m_SelState = CFX_Edit_Select(GetWholeWordRange()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1714 | SetCaret(m_SelState.EndPos); |
| 1715 | |
| 1716 | ScrollToCaret(); |
| 1717 | CPVT_WordRange wrVisible = GetVisibleWordRange(); |
| 1718 | Refresh(RP_OPTIONAL, &wrVisible); |
| 1719 | SetCaretInfo(); |
| 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | void CFX_Edit::SelectNone() { |
| 1724 | if (m_pVT->IsValid()) { |
| 1725 | if (m_SelState.IsExist()) { |
| 1726 | CPVT_WordRange wrTemp = m_SelState.ConvertToWordRange(); |
| 1727 | m_SelState.Default(); |
| 1728 | Refresh(RP_OPTIONAL, &wrTemp); |
| 1729 | } |
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | FX_BOOL CFX_Edit::IsSelected() const { |
| 1734 | return m_SelState.IsExist(); |
| 1735 | } |
| 1736 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1737 | CFX_FloatPoint CFX_Edit::VTToEdit(const CFX_FloatPoint& point) const { |
| 1738 | CFX_FloatRect rcContent = m_pVT->GetContentRect(); |
| 1739 | CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1740 | |
| 1741 | FX_FLOAT fPadding = 0.0f; |
| 1742 | |
| 1743 | switch (m_nAlignment) { |
| 1744 | case 0: |
| 1745 | fPadding = 0.0f; |
| 1746 | break; |
| 1747 | case 1: |
| 1748 | fPadding = (rcPlate.Height() - rcContent.Height()) * 0.5f; |
| 1749 | break; |
| 1750 | case 2: |
| 1751 | fPadding = rcPlate.Height() - rcContent.Height(); |
| 1752 | break; |
| 1753 | } |
| 1754 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1755 | return CFX_FloatPoint(point.x - (m_ptScrollPos.x - rcPlate.left), |
| 1756 | point.y - (m_ptScrollPos.y + fPadding - rcPlate.top)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1759 | CFX_FloatPoint CFX_Edit::EditToVT(const CFX_FloatPoint& point) const { |
| 1760 | CFX_FloatRect rcContent = m_pVT->GetContentRect(); |
| 1761 | CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1762 | |
| 1763 | FX_FLOAT fPadding = 0.0f; |
| 1764 | |
| 1765 | switch (m_nAlignment) { |
| 1766 | case 0: |
| 1767 | fPadding = 0.0f; |
| 1768 | break; |
| 1769 | case 1: |
| 1770 | fPadding = (rcPlate.Height() - rcContent.Height()) * 0.5f; |
| 1771 | break; |
| 1772 | case 2: |
| 1773 | fPadding = rcPlate.Height() - rcContent.Height(); |
| 1774 | break; |
| 1775 | } |
| 1776 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1777 | return CFX_FloatPoint(point.x + (m_ptScrollPos.x - rcPlate.left), |
| 1778 | point.y + (m_ptScrollPos.y + fPadding - rcPlate.top)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1781 | CFX_FloatRect CFX_Edit::VTToEdit(const CFX_FloatRect& rect) const { |
| 1782 | CFX_FloatPoint ptLeftBottom = |
| 1783 | VTToEdit(CFX_FloatPoint(rect.left, rect.bottom)); |
| 1784 | CFX_FloatPoint ptRightTop = VTToEdit(CFX_FloatPoint(rect.right, rect.top)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1785 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1786 | return CFX_FloatRect(ptLeftBottom.x, ptLeftBottom.y, ptRightTop.x, |
| 1787 | ptRightTop.y); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1788 | } |
| 1789 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1790 | CFX_FloatRect CFX_Edit::EditToVT(const CFX_FloatRect& rect) const { |
| 1791 | CFX_FloatPoint ptLeftBottom = |
| 1792 | EditToVT(CFX_FloatPoint(rect.left, rect.bottom)); |
| 1793 | CFX_FloatPoint ptRightTop = EditToVT(CFX_FloatPoint(rect.right, rect.top)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1794 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1795 | return CFX_FloatRect(ptLeftBottom.x, ptLeftBottom.y, ptRightTop.x, |
| 1796 | ptRightTop.y); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | void CFX_Edit::SetScrollInfo() { |
| 1800 | if (m_bNotify && m_pNotify) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1801 | CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
| 1802 | CFX_FloatRect rcContent = m_pVT->GetContentRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1803 | |
| 1804 | if (!m_bNotifyFlag) { |
| 1805 | m_bNotifyFlag = TRUE; |
| 1806 | m_pNotify->IOnSetScrollInfoX(rcPlate.left, rcPlate.right, rcContent.left, |
| 1807 | rcContent.right, rcPlate.Width() / 3, |
| 1808 | rcPlate.Width()); |
| 1809 | |
| 1810 | m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top, |
| 1811 | rcContent.bottom, rcContent.top, |
| 1812 | rcPlate.Height() / 3, rcPlate.Height()); |
| 1813 | m_bNotifyFlag = FALSE; |
| 1814 | } |
| 1815 | } |
| 1816 | } |
| 1817 | |
| 1818 | void CFX_Edit::SetScrollPosX(FX_FLOAT fx) { |
| 1819 | if (!m_bEnableScroll) |
| 1820 | return; |
| 1821 | |
| 1822 | if (m_pVT->IsValid()) { |
| 1823 | if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.x, fx)) { |
| 1824 | m_ptScrollPos.x = fx; |
| 1825 | Refresh(RP_NOANALYSE); |
| 1826 | |
| 1827 | if (m_bNotify && m_pNotify) { |
| 1828 | if (!m_bNotifyFlag) { |
| 1829 | m_bNotifyFlag = TRUE; |
| 1830 | m_pNotify->IOnSetScrollPosX(fx); |
| 1831 | m_bNotifyFlag = FALSE; |
| 1832 | } |
| 1833 | } |
| 1834 | } |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | void CFX_Edit::SetScrollPosY(FX_FLOAT fy) { |
| 1839 | if (!m_bEnableScroll) |
| 1840 | return; |
| 1841 | |
| 1842 | if (m_pVT->IsValid()) { |
| 1843 | if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y, fy)) { |
| 1844 | m_ptScrollPos.y = fy; |
| 1845 | Refresh(RP_NOANALYSE); |
| 1846 | |
| 1847 | if (m_bNotify && m_pNotify) { |
| 1848 | if (!m_bNotifyFlag) { |
| 1849 | m_bNotifyFlag = TRUE; |
| 1850 | m_pNotify->IOnSetScrollPosY(fy); |
| 1851 | m_bNotifyFlag = FALSE; |
| 1852 | } |
| 1853 | } |
| 1854 | } |
| 1855 | } |
| 1856 | } |
| 1857 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1858 | void CFX_Edit::SetScrollPos(const CFX_FloatPoint& point) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1859 | SetScrollPosX(point.x); |
| 1860 | SetScrollPosY(point.y); |
| 1861 | SetScrollLimit(); |
| 1862 | SetCaretInfo(); |
| 1863 | } |
| 1864 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1865 | CFX_FloatPoint CFX_Edit::GetScrollPos() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1866 | return m_ptScrollPos; |
| 1867 | } |
| 1868 | |
| 1869 | void CFX_Edit::SetScrollLimit() { |
| 1870 | if (m_pVT->IsValid()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1871 | CFX_FloatRect rcContent = m_pVT->GetContentRect(); |
| 1872 | CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1873 | |
| 1874 | if (rcPlate.Width() > rcContent.Width()) { |
| 1875 | SetScrollPosX(rcPlate.left); |
| 1876 | } else { |
| 1877 | if (FX_EDIT_IsFloatSmaller(m_ptScrollPos.x, rcContent.left)) { |
| 1878 | SetScrollPosX(rcContent.left); |
| 1879 | } else if (FX_EDIT_IsFloatBigger(m_ptScrollPos.x, |
| 1880 | rcContent.right - rcPlate.Width())) { |
| 1881 | SetScrollPosX(rcContent.right - rcPlate.Width()); |
| 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | if (rcPlate.Height() > rcContent.Height()) { |
| 1886 | SetScrollPosY(rcPlate.top); |
| 1887 | } else { |
| 1888 | if (FX_EDIT_IsFloatSmaller(m_ptScrollPos.y, |
| 1889 | rcContent.bottom + rcPlate.Height())) { |
| 1890 | SetScrollPosY(rcContent.bottom + rcPlate.Height()); |
| 1891 | } else if (FX_EDIT_IsFloatBigger(m_ptScrollPos.y, rcContent.top)) { |
| 1892 | SetScrollPosY(rcContent.top); |
| 1893 | } |
| 1894 | } |
| 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | void CFX_Edit::ScrollToCaret() { |
| 1899 | SetScrollLimit(); |
| 1900 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1901 | if (!m_pVT->IsValid()) |
| 1902 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1903 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1904 | CFX_FloatPoint ptHead(0, 0); |
| 1905 | CFX_FloatPoint ptFoot(0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1906 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1907 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 1908 | pIterator->SetAt(m_wpCaret); |
| 1909 | |
| 1910 | CPVT_Word word; |
| 1911 | CPVT_Line line; |
| 1912 | if (pIterator->GetWord(word)) { |
| 1913 | ptHead.x = word.ptWord.x + word.fWidth; |
| 1914 | ptHead.y = word.ptWord.y + word.fAscent; |
| 1915 | ptFoot.x = word.ptWord.x + word.fWidth; |
| 1916 | ptFoot.y = word.ptWord.y + word.fDescent; |
| 1917 | } else if (pIterator->GetLine(line)) { |
| 1918 | ptHead.x = line.ptLine.x; |
| 1919 | ptHead.y = line.ptLine.y + line.fLineAscent; |
| 1920 | ptFoot.x = line.ptLine.x; |
| 1921 | ptFoot.y = line.ptLine.y + line.fLineDescent; |
| 1922 | } |
| 1923 | |
| 1924 | CFX_FloatPoint ptHeadEdit = VTToEdit(ptHead); |
| 1925 | CFX_FloatPoint ptFootEdit = VTToEdit(ptFoot); |
| 1926 | |
| 1927 | CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
| 1928 | |
| 1929 | if (!FX_EDIT_IsFloatEqual(rcPlate.left, rcPlate.right)) { |
| 1930 | if (FX_EDIT_IsFloatSmaller(ptHeadEdit.x, rcPlate.left) || |
| 1931 | FX_EDIT_IsFloatEqual(ptHeadEdit.x, rcPlate.left)) { |
| 1932 | SetScrollPosX(ptHead.x); |
| 1933 | } else if (FX_EDIT_IsFloatBigger(ptHeadEdit.x, rcPlate.right)) { |
| 1934 | SetScrollPosX(ptHead.x - rcPlate.Width()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1935 | } |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1936 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1937 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1938 | if (!FX_EDIT_IsFloatEqual(rcPlate.top, rcPlate.bottom)) { |
| 1939 | if (FX_EDIT_IsFloatSmaller(ptFootEdit.y, rcPlate.bottom) || |
| 1940 | FX_EDIT_IsFloatEqual(ptFootEdit.y, rcPlate.bottom)) { |
| 1941 | if (FX_EDIT_IsFloatSmaller(ptHeadEdit.y, rcPlate.top)) { |
| 1942 | SetScrollPosY(ptFoot.y + rcPlate.Height()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1943 | } |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1944 | } else if (FX_EDIT_IsFloatBigger(ptHeadEdit.y, rcPlate.top)) { |
| 1945 | if (FX_EDIT_IsFloatBigger(ptFootEdit.y, rcPlate.bottom)) { |
| 1946 | SetScrollPosY(ptHead.y); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1947 | } |
| 1948 | } |
| 1949 | } |
| 1950 | } |
| 1951 | |
| 1952 | void CFX_Edit::Refresh(REFRESH_PLAN_E ePlan, |
| 1953 | const CPVT_WordRange* pRange1, |
| 1954 | const CPVT_WordRange* pRange2) { |
| 1955 | if (m_bEnableRefresh && m_pVT->IsValid()) { |
| 1956 | m_Refresh.BeginRefresh(); |
| 1957 | RefreshPushLineRects(GetVisibleWordRange()); |
| 1958 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1959 | m_Refresh.NoAnalyse(); |
| 1960 | m_ptRefreshScrollPos = m_ptScrollPos; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1961 | |
| 1962 | if (m_bNotify && m_pNotify) { |
| 1963 | if (!m_bNotifyFlag) { |
| 1964 | m_bNotifyFlag = TRUE; |
| 1965 | if (const CFX_Edit_RectArray* pRects = m_Refresh.GetRefreshRects()) { |
| 1966 | for (int32_t i = 0, sz = pRects->GetSize(); i < sz; i++) |
| 1967 | m_pNotify->IOnInvalidateRect(pRects->GetAt(i)); |
| 1968 | } |
| 1969 | m_bNotifyFlag = FALSE; |
| 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | m_Refresh.EndRefresh(); |
| 1974 | } |
| 1975 | } |
| 1976 | |
| 1977 | void CFX_Edit::RefreshPushLineRects(const CPVT_WordRange& wr) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1978 | if (!m_pVT->IsValid()) |
| 1979 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1980 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1981 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 1982 | CPVT_WordPlace wpBegin = wr.BeginPos; |
| 1983 | m_pVT->UpdateWordPlace(wpBegin); |
| 1984 | CPVT_WordPlace wpEnd = wr.EndPos; |
| 1985 | m_pVT->UpdateWordPlace(wpEnd); |
| 1986 | pIterator->SetAt(wpBegin); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1987 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1988 | CPVT_Line lineinfo; |
| 1989 | do { |
| 1990 | if (!pIterator->GetLine(lineinfo)) |
| 1991 | break; |
| 1992 | if (lineinfo.lineplace.LineCmp(wpEnd) > 0) |
| 1993 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1994 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 1995 | CFX_FloatRect rcLine(lineinfo.ptLine.x, |
| 1996 | lineinfo.ptLine.y + lineinfo.fLineDescent, |
| 1997 | lineinfo.ptLine.x + lineinfo.fLineWidth, |
| 1998 | lineinfo.ptLine.y + lineinfo.fLineAscent); |
| 1999 | |
| 2000 | m_Refresh.Push(CPVT_WordRange(lineinfo.lineplace, lineinfo.lineEnd), |
| 2001 | VTToEdit(rcLine)); |
| 2002 | } while (pIterator->NextLine()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | void CFX_Edit::RefreshPushRandomRects(const CPVT_WordRange& wr) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2006 | if (!m_pVT->IsValid()) |
| 2007 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2008 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2009 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 2010 | CPVT_WordRange wrTemp = wr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2011 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2012 | m_pVT->UpdateWordPlace(wrTemp.BeginPos); |
| 2013 | m_pVT->UpdateWordPlace(wrTemp.EndPos); |
| 2014 | pIterator->SetAt(wrTemp.BeginPos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2015 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2016 | CPVT_Word wordinfo; |
| 2017 | CPVT_Line lineinfo; |
| 2018 | CPVT_WordPlace place; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2019 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2020 | while (pIterator->NextWord()) { |
| 2021 | place = pIterator->GetAt(); |
| 2022 | if (place.WordCmp(wrTemp.EndPos) > 0) |
| 2023 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2024 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2025 | pIterator->GetWord(wordinfo); |
| 2026 | pIterator->GetLine(lineinfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2027 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2028 | if (place.LineCmp(wrTemp.BeginPos) == 0 || |
| 2029 | place.LineCmp(wrTemp.EndPos) == 0) { |
| 2030 | CFX_FloatRect rcWord(wordinfo.ptWord.x, |
| 2031 | lineinfo.ptLine.y + lineinfo.fLineDescent, |
| 2032 | wordinfo.ptWord.x + wordinfo.fWidth, |
| 2033 | lineinfo.ptLine.y + lineinfo.fLineAscent); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2034 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2035 | m_Refresh.AddRefresh(VTToEdit(rcWord)); |
| 2036 | } else { |
| 2037 | CFX_FloatRect rcLine(lineinfo.ptLine.x, |
| 2038 | lineinfo.ptLine.y + lineinfo.fLineDescent, |
| 2039 | lineinfo.ptLine.x + lineinfo.fLineWidth, |
| 2040 | lineinfo.ptLine.y + lineinfo.fLineAscent); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2041 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2042 | m_Refresh.AddRefresh(VTToEdit(rcLine)); |
| 2043 | |
| 2044 | pIterator->NextLine(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2045 | } |
| 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | void CFX_Edit::RefreshWordRange(const CPVT_WordRange& wr) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2050 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 2051 | CPVT_WordRange wrTemp = wr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2052 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2053 | m_pVT->UpdateWordPlace(wrTemp.BeginPos); |
| 2054 | m_pVT->UpdateWordPlace(wrTemp.EndPos); |
| 2055 | pIterator->SetAt(wrTemp.BeginPos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2056 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2057 | CPVT_Word wordinfo; |
| 2058 | CPVT_Line lineinfo; |
| 2059 | CPVT_WordPlace place; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2060 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2061 | while (pIterator->NextWord()) { |
| 2062 | place = pIterator->GetAt(); |
| 2063 | if (place.WordCmp(wrTemp.EndPos) > 0) |
| 2064 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2065 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2066 | pIterator->GetWord(wordinfo); |
| 2067 | pIterator->GetLine(lineinfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2068 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2069 | if (place.LineCmp(wrTemp.BeginPos) == 0 || |
| 2070 | place.LineCmp(wrTemp.EndPos) == 0) { |
| 2071 | CFX_FloatRect rcWord(wordinfo.ptWord.x, |
| 2072 | lineinfo.ptLine.y + lineinfo.fLineDescent, |
| 2073 | wordinfo.ptWord.x + wordinfo.fWidth, |
| 2074 | lineinfo.ptLine.y + lineinfo.fLineAscent); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2075 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2076 | if (m_bNotify && m_pNotify) { |
| 2077 | if (!m_bNotifyFlag) { |
| 2078 | m_bNotifyFlag = TRUE; |
| 2079 | CFX_FloatRect rcRefresh = VTToEdit(rcWord); |
| 2080 | m_pNotify->IOnInvalidateRect(&rcRefresh); |
| 2081 | m_bNotifyFlag = FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2082 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2083 | } |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2084 | } else { |
| 2085 | CFX_FloatRect rcLine(lineinfo.ptLine.x, |
| 2086 | lineinfo.ptLine.y + lineinfo.fLineDescent, |
| 2087 | lineinfo.ptLine.x + lineinfo.fLineWidth, |
| 2088 | lineinfo.ptLine.y + lineinfo.fLineAscent); |
| 2089 | |
| 2090 | if (m_bNotify && m_pNotify) { |
| 2091 | if (!m_bNotifyFlag) { |
| 2092 | m_bNotifyFlag = TRUE; |
| 2093 | CFX_FloatRect rcRefresh = VTToEdit(rcLine); |
| 2094 | m_pNotify->IOnInvalidateRect(&rcRefresh); |
| 2095 | m_bNotifyFlag = FALSE; |
| 2096 | } |
| 2097 | } |
| 2098 | |
| 2099 | pIterator->NextLine(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2100 | } |
| 2101 | } |
| 2102 | } |
| 2103 | |
| 2104 | void CFX_Edit::SetCaret(const CPVT_WordPlace& place) { |
| 2105 | m_wpOldCaret = m_wpCaret; |
| 2106 | m_wpCaret = place; |
| 2107 | } |
| 2108 | |
| 2109 | void CFX_Edit::SetCaretInfo() { |
| 2110 | if (m_bNotify && m_pNotify) { |
| 2111 | if (!m_bNotifyFlag) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2112 | CFX_FloatPoint ptHead(0.0f, 0.0f), ptFoot(0.0f, 0.0f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2113 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2114 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 2115 | pIterator->SetAt(m_wpCaret); |
| 2116 | CPVT_Word word; |
| 2117 | CPVT_Line line; |
| 2118 | if (pIterator->GetWord(word)) { |
| 2119 | ptHead.x = word.ptWord.x + word.fWidth; |
| 2120 | ptHead.y = word.ptWord.y + word.fAscent; |
| 2121 | ptFoot.x = word.ptWord.x + word.fWidth; |
| 2122 | ptFoot.y = word.ptWord.y + word.fDescent; |
| 2123 | } else if (pIterator->GetLine(line)) { |
| 2124 | ptHead.x = line.ptLine.x; |
| 2125 | ptHead.y = line.ptLine.y + line.fLineAscent; |
| 2126 | ptFoot.x = line.ptLine.x; |
| 2127 | ptFoot.y = line.ptLine.y + line.fLineDescent; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2128 | } |
| 2129 | |
| 2130 | m_bNotifyFlag = TRUE; |
| 2131 | m_pNotify->IOnSetCaret(!m_SelState.IsExist(), VTToEdit(ptHead), |
| 2132 | VTToEdit(ptFoot), m_wpCaret); |
| 2133 | m_bNotifyFlag = FALSE; |
| 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | SetCaretChange(); |
| 2138 | } |
| 2139 | |
| 2140 | void CFX_Edit::SetCaretChange() { |
| 2141 | if (m_wpCaret == m_wpOldCaret) |
| 2142 | return; |
| 2143 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2144 | if (!m_bNotify || !m_pVT->IsRichText() || !m_pNotify) |
| 2145 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2146 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2147 | CPVT_SecProps SecProps; |
| 2148 | CPVT_WordProps WordProps; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2149 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2150 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 2151 | pIterator->SetAt(m_wpCaret); |
| 2152 | CPVT_Word word; |
| 2153 | CPVT_Section section; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2154 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2155 | if (pIterator->GetSection(section)) { |
| 2156 | SecProps = section.SecProps; |
| 2157 | WordProps = section.WordProps; |
| 2158 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2159 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2160 | if (pIterator->GetWord(word)) |
| 2161 | WordProps = word.WordProps; |
| 2162 | |
| 2163 | if (!m_bNotifyFlag) { |
| 2164 | m_bNotifyFlag = TRUE; |
| 2165 | m_pNotify->IOnCaretChange(SecProps, WordProps); |
| 2166 | m_bNotifyFlag = FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | void CFX_Edit::SetCaret(int32_t nPos) { |
| 2171 | if (m_pVT->IsValid()) { |
| 2172 | SelectNone(); |
| 2173 | SetCaret(m_pVT->WordIndexToWordPlace(nPos)); |
| 2174 | m_SelState.Set(m_wpCaret, m_wpCaret); |
| 2175 | |
| 2176 | ScrollToCaret(); |
| 2177 | SetCaretOrigin(); |
| 2178 | SetCaretInfo(); |
| 2179 | } |
| 2180 | } |
| 2181 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2182 | void CFX_Edit::OnMouseDown(const CFX_FloatPoint& point, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2183 | FX_BOOL bShift, |
| 2184 | FX_BOOL bCtrl) { |
| 2185 | if (m_pVT->IsValid()) { |
| 2186 | SelectNone(); |
| 2187 | SetCaret(m_pVT->SearchWordPlace(EditToVT(point))); |
| 2188 | m_SelState.Set(m_wpCaret, m_wpCaret); |
| 2189 | |
| 2190 | ScrollToCaret(); |
| 2191 | SetCaretOrigin(); |
| 2192 | SetCaretInfo(); |
| 2193 | } |
| 2194 | } |
| 2195 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2196 | void CFX_Edit::OnMouseMove(const CFX_FloatPoint& point, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2197 | FX_BOOL bShift, |
| 2198 | FX_BOOL bCtrl) { |
| 2199 | if (m_pVT->IsValid()) { |
| 2200 | SetCaret(m_pVT->SearchWordPlace(EditToVT(point))); |
| 2201 | |
| 2202 | if (m_wpCaret != m_wpOldCaret) { |
| 2203 | m_SelState.SetEndPos(m_wpCaret); |
| 2204 | |
| 2205 | ScrollToCaret(); |
| 2206 | CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); |
| 2207 | Refresh(RP_OPTIONAL, &wr); |
| 2208 | SetCaretOrigin(); |
| 2209 | SetCaretInfo(); |
| 2210 | } |
| 2211 | } |
| 2212 | } |
| 2213 | |
| 2214 | void CFX_Edit::OnVK_UP(FX_BOOL bShift, FX_BOOL bCtrl) { |
| 2215 | if (m_pVT->IsValid()) { |
| 2216 | SetCaret(m_pVT->GetUpWordPlace(m_wpCaret, m_ptCaret)); |
| 2217 | |
| 2218 | if (bShift) { |
| 2219 | if (m_SelState.IsExist()) |
| 2220 | m_SelState.SetEndPos(m_wpCaret); |
| 2221 | else |
| 2222 | m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 2223 | |
| 2224 | if (m_wpOldCaret != m_wpCaret) { |
| 2225 | ScrollToCaret(); |
| 2226 | CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); |
| 2227 | Refresh(RP_OPTIONAL, &wr); |
| 2228 | SetCaretInfo(); |
| 2229 | } |
| 2230 | } else { |
| 2231 | SelectNone(); |
| 2232 | |
| 2233 | ScrollToCaret(); |
| 2234 | SetCaretInfo(); |
| 2235 | } |
| 2236 | } |
| 2237 | } |
| 2238 | |
| 2239 | void CFX_Edit::OnVK_DOWN(FX_BOOL bShift, FX_BOOL bCtrl) { |
| 2240 | if (m_pVT->IsValid()) { |
| 2241 | SetCaret(m_pVT->GetDownWordPlace(m_wpCaret, m_ptCaret)); |
| 2242 | |
| 2243 | if (bShift) { |
| 2244 | if (m_SelState.IsExist()) |
| 2245 | m_SelState.SetEndPos(m_wpCaret); |
| 2246 | else |
| 2247 | m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 2248 | |
| 2249 | if (m_wpOldCaret != m_wpCaret) { |
| 2250 | ScrollToCaret(); |
| 2251 | CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); |
| 2252 | Refresh(RP_OPTIONAL, &wr); |
| 2253 | SetCaretInfo(); |
| 2254 | } |
| 2255 | } else { |
| 2256 | SelectNone(); |
| 2257 | |
| 2258 | ScrollToCaret(); |
| 2259 | SetCaretInfo(); |
| 2260 | } |
| 2261 | } |
| 2262 | } |
| 2263 | |
| 2264 | void CFX_Edit::OnVK_LEFT(FX_BOOL bShift, FX_BOOL bCtrl) { |
| 2265 | if (m_pVT->IsValid()) { |
| 2266 | if (bShift) { |
| 2267 | if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) && |
| 2268 | m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret)) |
| 2269 | SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); |
| 2270 | |
| 2271 | SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); |
| 2272 | |
| 2273 | if (m_SelState.IsExist()) |
| 2274 | m_SelState.SetEndPos(m_wpCaret); |
| 2275 | else |
| 2276 | m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 2277 | |
| 2278 | if (m_wpOldCaret != m_wpCaret) { |
| 2279 | ScrollToCaret(); |
| 2280 | CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); |
| 2281 | Refresh(RP_OPTIONAL, &wr); |
| 2282 | SetCaretInfo(); |
| 2283 | } |
| 2284 | } else { |
| 2285 | if (m_SelState.IsExist()) { |
| 2286 | if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) < 0) |
| 2287 | SetCaret(m_SelState.BeginPos); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2288 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2289 | SetCaret(m_SelState.EndPos); |
| 2290 | |
| 2291 | SelectNone(); |
| 2292 | ScrollToCaret(); |
| 2293 | SetCaretInfo(); |
| 2294 | } else { |
| 2295 | if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) && |
| 2296 | m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret)) |
| 2297 | SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); |
| 2298 | |
| 2299 | SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); |
| 2300 | |
| 2301 | ScrollToCaret(); |
| 2302 | SetCaretOrigin(); |
| 2303 | SetCaretInfo(); |
| 2304 | } |
| 2305 | } |
| 2306 | } |
| 2307 | } |
| 2308 | |
| 2309 | void CFX_Edit::OnVK_RIGHT(FX_BOOL bShift, FX_BOOL bCtrl) { |
| 2310 | if (m_pVT->IsValid()) { |
| 2311 | if (bShift) { |
| 2312 | SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); |
| 2313 | |
| 2314 | if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) && |
| 2315 | m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret)) |
| 2316 | SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); |
| 2317 | |
| 2318 | if (m_SelState.IsExist()) |
| 2319 | m_SelState.SetEndPos(m_wpCaret); |
| 2320 | else |
| 2321 | m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 2322 | |
| 2323 | if (m_wpOldCaret != m_wpCaret) { |
| 2324 | ScrollToCaret(); |
| 2325 | CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); |
| 2326 | Refresh(RP_OPTIONAL, &wr); |
| 2327 | SetCaretInfo(); |
| 2328 | } |
| 2329 | } else { |
| 2330 | if (m_SelState.IsExist()) { |
| 2331 | if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) > 0) |
| 2332 | SetCaret(m_SelState.BeginPos); |
| 2333 | else |
| 2334 | SetCaret(m_SelState.EndPos); |
| 2335 | |
| 2336 | SelectNone(); |
| 2337 | ScrollToCaret(); |
| 2338 | SetCaretInfo(); |
| 2339 | } else { |
| 2340 | SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); |
| 2341 | |
| 2342 | if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) && |
| 2343 | m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret)) |
| 2344 | SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); |
| 2345 | |
| 2346 | ScrollToCaret(); |
| 2347 | SetCaretOrigin(); |
| 2348 | SetCaretInfo(); |
| 2349 | } |
| 2350 | } |
| 2351 | } |
| 2352 | } |
| 2353 | |
| 2354 | void CFX_Edit::OnVK_HOME(FX_BOOL bShift, FX_BOOL bCtrl) { |
| 2355 | if (m_pVT->IsValid()) { |
| 2356 | if (bShift) { |
| 2357 | if (bCtrl) |
| 2358 | SetCaret(m_pVT->GetBeginWordPlace()); |
| 2359 | else |
| 2360 | SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret)); |
| 2361 | |
| 2362 | if (m_SelState.IsExist()) |
| 2363 | m_SelState.SetEndPos(m_wpCaret); |
| 2364 | else |
| 2365 | m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 2366 | |
| 2367 | ScrollToCaret(); |
| 2368 | CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); |
| 2369 | Refresh(RP_OPTIONAL, &wr); |
| 2370 | SetCaretInfo(); |
| 2371 | } else { |
| 2372 | if (m_SelState.IsExist()) { |
| 2373 | if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) < 0) |
| 2374 | SetCaret(m_SelState.BeginPos); |
| 2375 | else |
| 2376 | SetCaret(m_SelState.EndPos); |
| 2377 | |
| 2378 | SelectNone(); |
| 2379 | ScrollToCaret(); |
| 2380 | SetCaretInfo(); |
| 2381 | } else { |
| 2382 | if (bCtrl) |
| 2383 | SetCaret(m_pVT->GetBeginWordPlace()); |
| 2384 | else |
| 2385 | SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret)); |
| 2386 | |
| 2387 | ScrollToCaret(); |
| 2388 | SetCaretOrigin(); |
| 2389 | SetCaretInfo(); |
| 2390 | } |
| 2391 | } |
| 2392 | } |
| 2393 | } |
| 2394 | |
| 2395 | void CFX_Edit::OnVK_END(FX_BOOL bShift, FX_BOOL bCtrl) { |
| 2396 | if (m_pVT->IsValid()) { |
| 2397 | if (bShift) { |
| 2398 | if (bCtrl) |
| 2399 | SetCaret(m_pVT->GetEndWordPlace()); |
| 2400 | else |
| 2401 | SetCaret(m_pVT->GetLineEndPlace(m_wpCaret)); |
| 2402 | |
| 2403 | if (m_SelState.IsExist()) |
| 2404 | m_SelState.SetEndPos(m_wpCaret); |
| 2405 | else |
| 2406 | m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 2407 | |
| 2408 | ScrollToCaret(); |
| 2409 | CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); |
| 2410 | Refresh(RP_OPTIONAL, &wr); |
| 2411 | SetCaretInfo(); |
| 2412 | } else { |
| 2413 | if (m_SelState.IsExist()) { |
| 2414 | if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) > 0) |
| 2415 | SetCaret(m_SelState.BeginPos); |
| 2416 | else |
| 2417 | SetCaret(m_SelState.EndPos); |
| 2418 | |
| 2419 | SelectNone(); |
| 2420 | ScrollToCaret(); |
| 2421 | SetCaretInfo(); |
| 2422 | } else { |
| 2423 | if (bCtrl) |
| 2424 | SetCaret(m_pVT->GetEndWordPlace()); |
| 2425 | else |
| 2426 | SetCaret(m_pVT->GetLineEndPlace(m_wpCaret)); |
| 2427 | |
| 2428 | ScrollToCaret(); |
| 2429 | SetCaretOrigin(); |
| 2430 | SetCaretInfo(); |
| 2431 | } |
| 2432 | } |
| 2433 | } |
| 2434 | } |
| 2435 | |
| 2436 | void CFX_Edit::SetText(const FX_WCHAR* text, |
| 2437 | int32_t charset, |
| 2438 | const CPVT_SecProps* pSecProps, |
| 2439 | const CPVT_WordProps* pWordProps, |
| 2440 | FX_BOOL bAddUndo, |
| 2441 | FX_BOOL bPaint) { |
| 2442 | Empty(); |
| 2443 | DoInsertText(CPVT_WordPlace(0, 0, -1), text, charset, pSecProps, pWordProps); |
| 2444 | if (bPaint) |
| 2445 | Paint(); |
| 2446 | if (m_bOprNotify && m_pOprNotify) |
| 2447 | m_pOprNotify->OnSetText(m_wpCaret, m_wpOldCaret); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2448 | } |
| 2449 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 2450 | FX_BOOL CFX_Edit::InsertWord(uint16_t word, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2451 | int32_t charset, |
| 2452 | const CPVT_WordProps* pWordProps, |
| 2453 | FX_BOOL bAddUndo, |
| 2454 | FX_BOOL bPaint) { |
| 2455 | if (IsTextOverflow()) |
| 2456 | return FALSE; |
| 2457 | |
| 2458 | if (m_pVT->IsValid()) { |
| 2459 | m_pVT->UpdateWordPlace(m_wpCaret); |
| 2460 | |
| 2461 | SetCaret(m_pVT->InsertWord( |
| 2462 | m_wpCaret, word, GetCharSetFromUnicode(word, charset), pWordProps)); |
| 2463 | m_SelState.Set(m_wpCaret, m_wpCaret); |
| 2464 | |
| 2465 | if (m_wpCaret != m_wpOldCaret) { |
| 2466 | if (bAddUndo && m_bEnableUndo) { |
| 2467 | AddEditUndoItem(new CFXEU_InsertWord(this, m_wpOldCaret, m_wpCaret, |
| 2468 | word, charset, pWordProps)); |
| 2469 | } |
| 2470 | |
| 2471 | if (bPaint) |
| 2472 | PaintInsertText(m_wpOldCaret, m_wpCaret); |
| 2473 | |
| 2474 | if (m_bOprNotify && m_pOprNotify) |
| 2475 | m_pOprNotify->OnInsertWord(m_wpCaret, m_wpOldCaret); |
| 2476 | |
| 2477 | return TRUE; |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | return FALSE; |
| 2482 | } |
| 2483 | |
| 2484 | FX_BOOL CFX_Edit::InsertReturn(const CPVT_SecProps* pSecProps, |
| 2485 | const CPVT_WordProps* pWordProps, |
| 2486 | FX_BOOL bAddUndo, |
| 2487 | FX_BOOL bPaint) { |
| 2488 | if (IsTextOverflow()) |
| 2489 | return FALSE; |
| 2490 | |
| 2491 | if (m_pVT->IsValid()) { |
| 2492 | m_pVT->UpdateWordPlace(m_wpCaret); |
| 2493 | SetCaret(m_pVT->InsertSection(m_wpCaret, pSecProps, pWordProps)); |
| 2494 | m_SelState.Set(m_wpCaret, m_wpCaret); |
| 2495 | |
| 2496 | if (m_wpCaret != m_wpOldCaret) { |
| 2497 | if (bAddUndo && m_bEnableUndo) { |
| 2498 | AddEditUndoItem(new CFXEU_InsertReturn(this, m_wpOldCaret, m_wpCaret, |
| 2499 | pSecProps, pWordProps)); |
| 2500 | } |
| 2501 | |
| 2502 | if (bPaint) { |
| 2503 | RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret)); |
| 2504 | ScrollToCaret(); |
| 2505 | CPVT_WordRange wr(m_wpOldCaret, GetVisibleWordRange().EndPos); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2506 | Refresh(RP_ANALYSE, &wr); |
| 2507 | SetCaretOrigin(); |
| 2508 | SetCaretInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2509 | } |
| 2510 | |
| 2511 | if (m_bOprNotify && m_pOprNotify) |
| 2512 | m_pOprNotify->OnInsertReturn(m_wpCaret, m_wpOldCaret); |
| 2513 | |
| 2514 | return TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2515 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2521 | FX_BOOL CFX_Edit::Backspace(FX_BOOL bAddUndo, FX_BOOL bPaint) { |
| 2522 | if (m_pVT->IsValid()) { |
| 2523 | if (m_wpCaret == m_pVT->GetBeginWordPlace()) |
| 2524 | return FALSE; |
| 2525 | |
| 2526 | CPVT_Section section; |
| 2527 | CPVT_Word word; |
| 2528 | |
| 2529 | if (bAddUndo) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2530 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 2531 | pIterator->SetAt(m_wpCaret); |
| 2532 | pIterator->GetSection(section); |
| 2533 | pIterator->GetWord(word); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2534 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2535 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2536 | m_pVT->UpdateWordPlace(m_wpCaret); |
| 2537 | SetCaret(m_pVT->BackSpaceWord(m_wpCaret)); |
| 2538 | m_SelState.Set(m_wpCaret, m_wpCaret); |
| 2539 | |
| 2540 | if (m_wpCaret != m_wpOldCaret) { |
| 2541 | if (bAddUndo && m_bEnableUndo) { |
| 2542 | if (m_wpCaret.SecCmp(m_wpOldCaret) != 0) |
| 2543 | AddEditUndoItem(new CFXEU_Backspace( |
| 2544 | this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset, |
| 2545 | section.SecProps, section.WordProps)); |
| 2546 | else |
| 2547 | AddEditUndoItem(new CFXEU_Backspace( |
| 2548 | this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset, |
| 2549 | section.SecProps, word.WordProps)); |
| 2550 | } |
| 2551 | |
| 2552 | if (bPaint) { |
| 2553 | RearrangePart(CPVT_WordRange(m_wpCaret, m_wpOldCaret)); |
| 2554 | ScrollToCaret(); |
| 2555 | |
| 2556 | CPVT_WordRange wr; |
| 2557 | if (m_wpCaret.SecCmp(m_wpOldCaret) != 0) |
| 2558 | wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpCaret), |
| 2559 | GetVisibleWordRange().EndPos); |
| 2560 | else if (m_wpCaret.LineCmp(m_wpOldCaret) != 0) |
| 2561 | wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(m_wpCaret), |
| 2562 | m_pVT->GetSectionEndPlace(m_wpCaret)); |
| 2563 | else |
| 2564 | wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpCaret), |
| 2565 | m_pVT->GetSectionEndPlace(m_wpCaret)); |
| 2566 | |
| 2567 | Refresh(RP_ANALYSE, &wr); |
| 2568 | |
| 2569 | SetCaretOrigin(); |
| 2570 | SetCaretInfo(); |
| 2571 | } |
| 2572 | |
| 2573 | if (m_bOprNotify && m_pOprNotify) |
| 2574 | m_pOprNotify->OnBackSpace(m_wpCaret, m_wpOldCaret); |
| 2575 | |
| 2576 | return TRUE; |
| 2577 | } |
| 2578 | } |
| 2579 | |
| 2580 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2581 | } |
| 2582 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2583 | FX_BOOL CFX_Edit::Delete(FX_BOOL bAddUndo, FX_BOOL bPaint) { |
| 2584 | if (m_pVT->IsValid()) { |
| 2585 | if (m_wpCaret == m_pVT->GetEndWordPlace()) |
| 2586 | return FALSE; |
| 2587 | |
| 2588 | CPVT_Section section; |
| 2589 | CPVT_Word word; |
| 2590 | |
| 2591 | if (bAddUndo) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2592 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 2593 | pIterator->SetAt(m_pVT->GetNextWordPlace(m_wpCaret)); |
| 2594 | pIterator->GetSection(section); |
| 2595 | pIterator->GetWord(word); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2596 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2597 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2598 | m_pVT->UpdateWordPlace(m_wpCaret); |
| 2599 | FX_BOOL bSecEnd = (m_wpCaret == m_pVT->GetSectionEndPlace(m_wpCaret)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2600 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2601 | SetCaret(m_pVT->DeleteWord(m_wpCaret)); |
| 2602 | m_SelState.Set(m_wpCaret, m_wpCaret); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2603 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2604 | if (bAddUndo && m_bEnableUndo) { |
| 2605 | if (bSecEnd) |
| 2606 | AddEditUndoItem(new CFXEU_Delete( |
| 2607 | this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset, |
| 2608 | section.SecProps, section.WordProps, bSecEnd)); |
| 2609 | else |
| 2610 | AddEditUndoItem(new CFXEU_Delete( |
| 2611 | this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset, |
| 2612 | section.SecProps, word.WordProps, bSecEnd)); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2613 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2614 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2615 | if (bPaint) { |
| 2616 | RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret)); |
| 2617 | ScrollToCaret(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2618 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2619 | CPVT_WordRange wr; |
| 2620 | if (bSecEnd) |
| 2621 | wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpOldCaret), |
| 2622 | GetVisibleWordRange().EndPos); |
| 2623 | else if (m_wpCaret.LineCmp(m_wpOldCaret) != 0) |
| 2624 | wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(m_wpCaret), |
| 2625 | m_pVT->GetSectionEndPlace(m_wpCaret)); |
| 2626 | else |
| 2627 | wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpOldCaret), |
| 2628 | m_pVT->GetSectionEndPlace(m_wpCaret)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2629 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2630 | Refresh(RP_ANALYSE, &wr); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2631 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2632 | SetCaretOrigin(); |
| 2633 | SetCaretInfo(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2634 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2635 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2636 | if (m_bOprNotify && m_pOprNotify) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2637 | m_pOprNotify->OnDelete(m_wpCaret, m_wpOldCaret); |
| 2638 | |
| 2639 | return TRUE; |
| 2640 | } |
| 2641 | |
| 2642 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2643 | } |
| 2644 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2645 | FX_BOOL CFX_Edit::Empty() { |
| 2646 | if (m_pVT->IsValid()) { |
| 2647 | m_pVT->DeleteWords(GetWholeWordRange()); |
| 2648 | SetCaret(m_pVT->GetBeginWordPlace()); |
| 2649 | |
| 2650 | return TRUE; |
| 2651 | } |
| 2652 | |
| 2653 | return FALSE; |
| 2654 | } |
| 2655 | |
| 2656 | FX_BOOL CFX_Edit::Clear(FX_BOOL bAddUndo, FX_BOOL bPaint) { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2657 | if (!m_pVT->IsValid()) |
| 2658 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2659 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2660 | if (!m_SelState.IsExist()) |
| 2661 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2662 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2663 | CPVT_WordRange range = m_SelState.ConvertToWordRange(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2664 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2665 | if (bAddUndo && m_bEnableUndo) { |
| 2666 | if (m_pVT->IsRichText()) { |
| 2667 | BeginGroupUndo(L""); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2668 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2669 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 2670 | pIterator->SetAt(range.EndPos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2671 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2672 | CPVT_Word wordinfo; |
| 2673 | CPVT_Section secinfo; |
| 2674 | do { |
| 2675 | CPVT_WordPlace place = pIterator->GetAt(); |
| 2676 | if (place.WordCmp(range.BeginPos) <= 0) |
| 2677 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2678 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2679 | CPVT_WordPlace oldplace = m_pVT->GetPrevWordPlace(place); |
| 2680 | |
| 2681 | if (oldplace.SecCmp(place) != 0) { |
| 2682 | if (pIterator->GetSection(secinfo)) { |
| 2683 | AddEditUndoItem(new CFXEU_ClearRich( |
| 2684 | this, oldplace, place, range, wordinfo.Word, wordinfo.nCharset, |
| 2685 | secinfo.SecProps, secinfo.WordProps)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2686 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2687 | } else { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2688 | if (pIterator->GetWord(wordinfo)) { |
| 2689 | oldplace = m_pVT->AdjustLineHeader(oldplace, TRUE); |
| 2690 | place = m_pVT->AdjustLineHeader(place, TRUE); |
| 2691 | |
| 2692 | AddEditUndoItem(new CFXEU_ClearRich( |
| 2693 | this, oldplace, place, range, wordinfo.Word, wordinfo.nCharset, |
| 2694 | secinfo.SecProps, wordinfo.WordProps)); |
| 2695 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2696 | } |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2697 | } while (pIterator->PrevWord()); |
| 2698 | EndGroupUndo(); |
| 2699 | } else { |
| 2700 | AddEditUndoItem(new CFXEU_Clear(this, range, GetSelText())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2701 | } |
| 2702 | } |
| 2703 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2704 | SelectNone(); |
| 2705 | SetCaret(m_pVT->DeleteWords(range)); |
| 2706 | m_SelState.Set(m_wpCaret, m_wpCaret); |
| 2707 | |
| 2708 | if (bPaint) { |
| 2709 | RearrangePart(range); |
| 2710 | ScrollToCaret(); |
| 2711 | |
| 2712 | CPVT_WordRange wr(m_wpOldCaret, GetVisibleWordRange().EndPos); |
| 2713 | Refresh(RP_ANALYSE, &wr); |
| 2714 | |
| 2715 | SetCaretOrigin(); |
| 2716 | SetCaretInfo(); |
| 2717 | } |
| 2718 | |
| 2719 | if (m_bOprNotify && m_pOprNotify) |
| 2720 | m_pOprNotify->OnClear(m_wpCaret, m_wpOldCaret); |
| 2721 | |
| 2722 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | FX_BOOL CFX_Edit::InsertText(const FX_WCHAR* text, |
| 2726 | int32_t charset, |
| 2727 | const CPVT_SecProps* pSecProps, |
| 2728 | const CPVT_WordProps* pWordProps, |
| 2729 | FX_BOOL bAddUndo, |
| 2730 | FX_BOOL bPaint) { |
| 2731 | if (IsTextOverflow()) |
| 2732 | return FALSE; |
| 2733 | |
| 2734 | m_pVT->UpdateWordPlace(m_wpCaret); |
| 2735 | SetCaret(DoInsertText(m_wpCaret, text, charset, pSecProps, pWordProps)); |
| 2736 | m_SelState.Set(m_wpCaret, m_wpCaret); |
| 2737 | |
| 2738 | if (m_wpCaret != m_wpOldCaret) { |
| 2739 | if (bAddUndo && m_bEnableUndo) { |
| 2740 | AddEditUndoItem(new CFXEU_InsertText(this, m_wpOldCaret, m_wpCaret, text, |
| 2741 | charset, pSecProps, pWordProps)); |
| 2742 | } |
| 2743 | |
| 2744 | if (bPaint) |
| 2745 | PaintInsertText(m_wpOldCaret, m_wpCaret); |
| 2746 | |
| 2747 | if (m_bOprNotify && m_pOprNotify) |
| 2748 | m_pOprNotify->OnInsertText(m_wpCaret, m_wpOldCaret); |
| 2749 | |
| 2750 | return TRUE; |
| 2751 | } |
| 2752 | return FALSE; |
| 2753 | } |
| 2754 | |
| 2755 | void CFX_Edit::PaintInsertText(const CPVT_WordPlace& wpOld, |
| 2756 | const CPVT_WordPlace& wpNew) { |
| 2757 | if (m_pVT->IsValid()) { |
| 2758 | RearrangePart(CPVT_WordRange(wpOld, wpNew)); |
| 2759 | ScrollToCaret(); |
| 2760 | |
| 2761 | CPVT_WordRange wr; |
| 2762 | if (m_wpCaret.LineCmp(wpOld) != 0) |
| 2763 | wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(wpOld), |
| 2764 | m_pVT->GetSectionEndPlace(wpNew)); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2765 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2766 | wr = CPVT_WordRange(wpOld, m_pVT->GetSectionEndPlace(wpNew)); |
| 2767 | Refresh(RP_ANALYSE, &wr); |
| 2768 | SetCaretOrigin(); |
| 2769 | SetCaretInfo(); |
| 2770 | } |
| 2771 | } |
| 2772 | |
| 2773 | FX_BOOL CFX_Edit::Redo() { |
| 2774 | if (m_bEnableUndo) { |
| 2775 | if (m_Undo.CanRedo()) { |
| 2776 | m_Undo.Redo(); |
| 2777 | return TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2778 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2782 | } |
| 2783 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2784 | FX_BOOL CFX_Edit::Undo() { |
| 2785 | if (m_bEnableUndo) { |
| 2786 | if (m_Undo.CanUndo()) { |
| 2787 | m_Undo.Undo(); |
| 2788 | return TRUE; |
| 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | return FALSE; |
| 2793 | } |
| 2794 | |
| 2795 | void CFX_Edit::SetCaretOrigin() { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2796 | if (!m_pVT->IsValid()) |
| 2797 | return; |
| 2798 | |
| 2799 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 2800 | pIterator->SetAt(m_wpCaret); |
| 2801 | CPVT_Word word; |
| 2802 | CPVT_Line line; |
| 2803 | if (pIterator->GetWord(word)) { |
| 2804 | m_ptCaret.x = word.ptWord.x + word.fWidth; |
| 2805 | m_ptCaret.y = word.ptWord.y; |
| 2806 | } else if (pIterator->GetLine(line)) { |
| 2807 | m_ptCaret.x = line.ptLine.x; |
| 2808 | m_ptCaret.y = line.ptLine.y; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2809 | } |
| 2810 | } |
| 2811 | |
| 2812 | int32_t CFX_Edit::WordPlaceToWordIndex(const CPVT_WordPlace& place) const { |
| 2813 | if (m_pVT->IsValid()) |
| 2814 | return m_pVT->WordPlaceToWordIndex(place); |
| 2815 | |
| 2816 | return -1; |
| 2817 | } |
| 2818 | |
| 2819 | CPVT_WordPlace CFX_Edit::WordIndexToWordPlace(int32_t index) const { |
| 2820 | if (m_pVT->IsValid()) |
| 2821 | return m_pVT->WordIndexToWordPlace(index); |
| 2822 | |
| 2823 | return CPVT_WordPlace(); |
| 2824 | } |
| 2825 | |
| 2826 | FX_BOOL CFX_Edit::IsTextFull() const { |
| 2827 | int32_t nTotalWords = m_pVT->GetTotalWords(); |
| 2828 | int32_t nLimitChar = m_pVT->GetLimitChar(); |
| 2829 | int32_t nCharArray = m_pVT->GetCharArray(); |
| 2830 | |
| 2831 | return IsTextOverflow() || (nLimitChar > 0 && nTotalWords >= nLimitChar) || |
| 2832 | (nCharArray > 0 && nTotalWords >= nCharArray); |
| 2833 | } |
| 2834 | |
| 2835 | FX_BOOL CFX_Edit::IsTextOverflow() const { |
| 2836 | if (!m_bEnableScroll && !m_bEnableOverflow) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2837 | CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
| 2838 | CFX_FloatRect rcContent = m_pVT->GetContentRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2839 | |
| 2840 | if (m_pVT->IsMultiLine() && GetTotalLines() > 1) { |
| 2841 | if (FX_EDIT_IsFloatBigger(rcContent.Height(), rcPlate.Height())) |
| 2842 | return TRUE; |
| 2843 | } |
| 2844 | |
| 2845 | if (FX_EDIT_IsFloatBigger(rcContent.Width(), rcPlate.Width())) |
| 2846 | return TRUE; |
| 2847 | } |
| 2848 | |
| 2849 | return FALSE; |
| 2850 | } |
| 2851 | |
| 2852 | CPVT_WordPlace CFX_Edit::GetLineBeginPlace(const CPVT_WordPlace& place) const { |
| 2853 | return m_pVT->GetLineBeginPlace(place); |
| 2854 | } |
| 2855 | |
| 2856 | CPVT_WordPlace CFX_Edit::GetLineEndPlace(const CPVT_WordPlace& place) const { |
| 2857 | return m_pVT->GetLineEndPlace(place); |
| 2858 | } |
| 2859 | |
| 2860 | CPVT_WordPlace CFX_Edit::GetSectionBeginPlace( |
| 2861 | const CPVT_WordPlace& place) const { |
| 2862 | return m_pVT->GetSectionBeginPlace(place); |
| 2863 | } |
| 2864 | |
| 2865 | CPVT_WordPlace CFX_Edit::GetSectionEndPlace(const CPVT_WordPlace& place) const { |
| 2866 | return m_pVT->GetSectionEndPlace(place); |
| 2867 | } |
| 2868 | |
| 2869 | FX_BOOL CFX_Edit::CanUndo() const { |
| 2870 | if (m_bEnableUndo) { |
| 2871 | return m_Undo.CanUndo(); |
| 2872 | } |
| 2873 | |
| 2874 | return FALSE; |
| 2875 | } |
| 2876 | |
| 2877 | FX_BOOL CFX_Edit::CanRedo() const { |
| 2878 | if (m_bEnableUndo) { |
| 2879 | return m_Undo.CanRedo(); |
| 2880 | } |
| 2881 | |
| 2882 | return FALSE; |
| 2883 | } |
| 2884 | |
| 2885 | FX_BOOL CFX_Edit::IsModified() const { |
| 2886 | if (m_bEnableUndo) { |
| 2887 | return m_Undo.IsModified(); |
| 2888 | } |
| 2889 | |
| 2890 | return FALSE; |
| 2891 | } |
| 2892 | |
| 2893 | void CFX_Edit::EnableRefresh(FX_BOOL bRefresh) { |
| 2894 | m_bEnableRefresh = bRefresh; |
| 2895 | } |
| 2896 | |
| 2897 | void CFX_Edit::EnableUndo(FX_BOOL bUndo) { |
| 2898 | m_bEnableUndo = bUndo; |
| 2899 | } |
| 2900 | |
| 2901 | void CFX_Edit::EnableNotify(FX_BOOL bNotify) { |
| 2902 | m_bNotify = bNotify; |
| 2903 | } |
| 2904 | |
| 2905 | void CFX_Edit::EnableOprNotify(FX_BOOL bNotify) { |
| 2906 | m_bOprNotify = bNotify; |
| 2907 | } |
| 2908 | |
| 2909 | FX_FLOAT CFX_Edit::GetLineTop(const CPVT_WordPlace& place) const { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2910 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 2911 | CPVT_WordPlace wpOld = pIterator->GetAt(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2912 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2913 | pIterator->SetAt(place); |
| 2914 | CPVT_Line line; |
| 2915 | pIterator->GetLine(line); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2916 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2917 | pIterator->SetAt(wpOld); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2918 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2919 | return line.ptLine.y + line.fLineAscent; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
| 2922 | FX_FLOAT CFX_Edit::GetLineBottom(const CPVT_WordPlace& place) const { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2923 | CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 2924 | CPVT_WordPlace wpOld = pIterator->GetAt(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2925 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2926 | pIterator->SetAt(place); |
| 2927 | CPVT_Line line; |
| 2928 | pIterator->GetLine(line); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2929 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2930 | pIterator->SetAt(wpOld); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2931 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 2932 | return line.ptLine.y + line.fLineDescent; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | CPVT_WordPlace CFX_Edit::DoInsertText(const CPVT_WordPlace& place, |
| 2936 | const FX_WCHAR* text, |
| 2937 | int32_t charset, |
| 2938 | const CPVT_SecProps* pSecProps, |
| 2939 | const CPVT_WordProps* pWordProps) { |
| 2940 | CPVT_WordPlace wp = place; |
| 2941 | |
| 2942 | if (m_pVT->IsValid()) { |
| 2943 | CFX_WideString sText = text; |
| 2944 | |
| 2945 | for (int32_t i = 0, sz = sText.GetLength(); i < sz; i++) { |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 2946 | uint16_t word = sText[i]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2947 | switch (word) { |
| 2948 | case 0x0D: |
| 2949 | wp = m_pVT->InsertSection(wp, pSecProps, pWordProps); |
| 2950 | if (sText[i + 1] == 0x0A) |
| 2951 | i++; |
| 2952 | break; |
| 2953 | case 0x0A: |
| 2954 | wp = m_pVT->InsertSection(wp, pSecProps, pWordProps); |
| 2955 | if (sText[i + 1] == 0x0D) |
| 2956 | i++; |
| 2957 | break; |
| 2958 | case 0x09: |
| 2959 | word = 0x20; |
| 2960 | default: |
| 2961 | wp = m_pVT->InsertWord(wp, word, GetCharSetFromUnicode(word, charset), |
| 2962 | pWordProps); |
| 2963 | break; |
| 2964 | } |
| 2965 | } |
| 2966 | } |
| 2967 | |
| 2968 | return wp; |
| 2969 | } |
| 2970 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 2971 | int32_t CFX_Edit::GetCharSetFromUnicode(uint16_t word, int32_t nOldCharset) { |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 2972 | if (IPVT_FontMap* pFontMap = GetFontMap()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2973 | return pFontMap->CharSetFromUnicode(word, nOldCharset); |
| 2974 | return nOldCharset; |
| 2975 | } |
| 2976 | |
| 2977 | void CFX_Edit::BeginGroupUndo(const CFX_WideString& sTitle) { |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 2978 | ASSERT(!m_pGroupUndoItem); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2979 | |
| 2980 | m_pGroupUndoItem = new CFX_Edit_GroupUndoItem(sTitle); |
| 2981 | } |
| 2982 | |
| 2983 | void CFX_Edit::EndGroupUndo() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2984 | m_pGroupUndoItem->UpdateItems(); |
| 2985 | m_Undo.AddItem(m_pGroupUndoItem); |
| 2986 | if (m_bOprNotify && m_pOprNotify) |
| 2987 | m_pOprNotify->OnAddUndo(m_pGroupUndoItem); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 2988 | m_pGroupUndoItem = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | void CFX_Edit::AddEditUndoItem(CFX_Edit_UndoItem* pEditUndoItem) { |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 2992 | if (m_pGroupUndoItem) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2993 | m_pGroupUndoItem->AddUndoItem(pEditUndoItem); |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 2994 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2995 | m_Undo.AddItem(pEditUndoItem); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2996 | if (m_bOprNotify && m_pOprNotify) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2997 | m_pOprNotify->OnAddUndo(pEditUndoItem); |
| 2998 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2999 | } |
| 3000 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3001 | void CFX_Edit::AddUndoItem(IFX_Edit_UndoItem* pUndoItem) { |
| 3002 | m_Undo.AddItem(pUndoItem); |
| 3003 | if (m_bOprNotify && m_pOprNotify) |
| 3004 | m_pOprNotify->OnAddUndo(pUndoItem); |
| 3005 | } |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame^] | 3006 | |
| 3007 | CFX_Edit_LineRectArray::CFX_Edit_LineRectArray() {} |
| 3008 | |
| 3009 | CFX_Edit_LineRectArray::~CFX_Edit_LineRectArray() { |
| 3010 | Empty(); |
| 3011 | } |
| 3012 | |
| 3013 | void CFX_Edit_LineRectArray::Empty() { |
| 3014 | for (int32_t i = 0, sz = m_LineRects.GetSize(); i < sz; i++) |
| 3015 | delete m_LineRects.GetAt(i); |
| 3016 | |
| 3017 | m_LineRects.RemoveAll(); |
| 3018 | } |
| 3019 | |
| 3020 | void CFX_Edit_LineRectArray::RemoveAll() { |
| 3021 | m_LineRects.RemoveAll(); |
| 3022 | } |
| 3023 | |
| 3024 | void CFX_Edit_LineRectArray::operator=(CFX_Edit_LineRectArray& rects) { |
| 3025 | Empty(); |
| 3026 | for (int32_t i = 0, sz = rects.GetSize(); i < sz; i++) |
| 3027 | m_LineRects.Add(rects.GetAt(i)); |
| 3028 | |
| 3029 | rects.RemoveAll(); |
| 3030 | } |
| 3031 | |
| 3032 | void CFX_Edit_LineRectArray::Add(const CPVT_WordRange& wrLine, |
| 3033 | const CFX_FloatRect& rcLine) { |
| 3034 | m_LineRects.Add(new CFX_Edit_LineRect(wrLine, rcLine)); |
| 3035 | } |
| 3036 | |
| 3037 | int32_t CFX_Edit_LineRectArray::GetSize() const { |
| 3038 | return m_LineRects.GetSize(); |
| 3039 | } |
| 3040 | |
| 3041 | CFX_Edit_LineRect* CFX_Edit_LineRectArray::GetAt(int32_t nIndex) const { |
| 3042 | if (nIndex < 0 || nIndex >= m_LineRects.GetSize()) |
| 3043 | return nullptr; |
| 3044 | |
| 3045 | return m_LineRects.GetAt(nIndex); |
| 3046 | } |
| 3047 | |
| 3048 | CFX_Edit_Select::CFX_Edit_Select() {} |
| 3049 | |
| 3050 | CFX_Edit_Select::CFX_Edit_Select(const CPVT_WordPlace& begin, |
| 3051 | const CPVT_WordPlace& end) { |
| 3052 | Set(begin, end); |
| 3053 | } |
| 3054 | |
| 3055 | CFX_Edit_Select::CFX_Edit_Select(const CPVT_WordRange& range) { |
| 3056 | Set(range.BeginPos, range.EndPos); |
| 3057 | } |
| 3058 | |
| 3059 | CPVT_WordRange CFX_Edit_Select::ConvertToWordRange() const { |
| 3060 | return CPVT_WordRange(BeginPos, EndPos); |
| 3061 | } |
| 3062 | |
| 3063 | void CFX_Edit_Select::Default() { |
| 3064 | BeginPos.Default(); |
| 3065 | EndPos.Default(); |
| 3066 | } |
| 3067 | |
| 3068 | void CFX_Edit_Select::Set(const CPVT_WordPlace& begin, |
| 3069 | const CPVT_WordPlace& end) { |
| 3070 | BeginPos = begin; |
| 3071 | EndPos = end; |
| 3072 | } |
| 3073 | |
| 3074 | void CFX_Edit_Select::SetBeginPos(const CPVT_WordPlace& begin) { |
| 3075 | BeginPos = begin; |
| 3076 | } |
| 3077 | |
| 3078 | void CFX_Edit_Select::SetEndPos(const CPVT_WordPlace& end) { |
| 3079 | EndPos = end; |
| 3080 | } |
| 3081 | |
| 3082 | FX_BOOL CFX_Edit_Select::IsExist() const { |
| 3083 | return BeginPos != EndPos; |
| 3084 | } |
| 3085 | |
| 3086 | FX_BOOL CFX_Edit_Select::operator!=(const CPVT_WordRange& wr) const { |
| 3087 | return wr.BeginPos != BeginPos || wr.EndPos != EndPos; |
| 3088 | } |
| 3089 | |
| 3090 | CFX_Edit_RectArray::CFX_Edit_RectArray() {} |
| 3091 | |
| 3092 | CFX_Edit_RectArray::~CFX_Edit_RectArray() { |
| 3093 | Empty(); |
| 3094 | } |
| 3095 | |
| 3096 | void CFX_Edit_RectArray::Empty() { |
| 3097 | for (int32_t i = 0, sz = m_Rects.GetSize(); i < sz; i++) |
| 3098 | delete m_Rects.GetAt(i); |
| 3099 | |
| 3100 | m_Rects.RemoveAll(); |
| 3101 | } |
| 3102 | |
| 3103 | void CFX_Edit_RectArray::Add(const CFX_FloatRect& rect) { |
| 3104 | // check for overlapped area |
| 3105 | for (int32_t i = 0, sz = m_Rects.GetSize(); i < sz; i++) { |
| 3106 | CFX_FloatRect* pRect = m_Rects.GetAt(i); |
| 3107 | if (pRect && pRect->Contains(rect)) |
| 3108 | return; |
| 3109 | } |
| 3110 | |
| 3111 | m_Rects.Add(new CFX_FloatRect(rect)); |
| 3112 | } |
| 3113 | |
| 3114 | int32_t CFX_Edit_RectArray::GetSize() const { |
| 3115 | return m_Rects.GetSize(); |
| 3116 | } |
| 3117 | |
| 3118 | CFX_FloatRect* CFX_Edit_RectArray::GetAt(int32_t nIndex) const { |
| 3119 | if (nIndex < 0 || nIndex >= m_Rects.GetSize()) |
| 3120 | return nullptr; |
| 3121 | |
| 3122 | return m_Rects.GetAt(nIndex); |
| 3123 | } |