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 | |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/pdfwindow/PWL_Edit.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 8 | |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 9 | #include <vector> |
| 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_word.h" |
Dan Sinclair | a8a28e0 | 2016-03-23 15:41:39 -0400 | [diff] [blame] | 13 | #include "core/fxcrt/include/fx_safe_types.h" |
| 14 | #include "core/fxcrt/include/fx_xml.h" |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 15 | #include "core/include/fxge/fx_ge.h" |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 16 | #include "fpdfsdk/pdfwindow/PWL_Caret.h" |
| 17 | #include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" |
| 18 | #include "fpdfsdk/pdfwindow/PWL_FontMap.h" |
| 19 | #include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" |
| 20 | #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
| 21 | #include "fpdfsdk/pdfwindow/PWL_Wnd.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 22 | #include "public/fpdf_fwlevent.h" |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 23 | #include "third_party/base/stl_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 24 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 25 | CPWL_Edit::CPWL_Edit() |
| 26 | : m_pFillerNotify(NULL), m_pSpellCheck(NULL), m_bFocus(FALSE) { |
| 27 | m_pFormFiller = NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 30 | CPWL_Edit::~CPWL_Edit() { |
| 31 | ASSERT(m_bFocus == FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 34 | CFX_ByteString CPWL_Edit::GetClassName() const { |
| 35 | return PWL_CLASSNAME_EDIT; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 38 | void CPWL_Edit::OnDestroy() {} |
| 39 | |
| 40 | void CPWL_Edit::SetText(const FX_WCHAR* csText) { |
| 41 | CFX_WideString swText = csText; |
| 42 | |
| 43 | if (HasFlag(PES_RICH)) { |
| 44 | CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText); |
| 45 | |
| 46 | if (CXML_Element* pXML = |
| 47 | CXML_Element::Parse(sValue.c_str(), sValue.GetLength())) { |
| 48 | int32_t nCount = pXML->CountChildren(); |
| 49 | FX_BOOL bFirst = TRUE; |
| 50 | |
| 51 | swText.Empty(); |
| 52 | |
| 53 | for (int32_t i = 0; i < nCount; i++) { |
| 54 | if (CXML_Element* pSubElement = pXML->GetElement(i)) { |
| 55 | CFX_ByteString tag = pSubElement->GetTagName(); |
| 56 | if (tag.EqualNoCase("p")) { |
| 57 | int nChild = pSubElement->CountChildren(); |
| 58 | CFX_WideString swSection; |
| 59 | for (int32_t j = 0; j < nChild; j++) { |
| 60 | swSection += pSubElement->GetContent(j); |
| 61 | } |
| 62 | |
| 63 | if (bFirst) |
| 64 | bFirst = FALSE; |
| 65 | else |
| 66 | swText += FWL_VKEY_Return; |
| 67 | swText += swSection; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | delete pXML; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | m_pEdit->SetText(swText.c_str()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 79 | void CPWL_Edit::RePosChildWnd() { |
| 80 | if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 81 | CFX_FloatRect rcWindow = m_rcOldWindow; |
| 82 | CFX_FloatRect rcVScroll = |
| 83 | CFX_FloatRect(rcWindow.right, rcWindow.bottom, |
| 84 | rcWindow.right + PWL_SCROLLBAR_WIDTH, rcWindow.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 85 | pVSB->Move(rcVScroll, TRUE, FALSE); |
| 86 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 87 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 88 | if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW)) |
| 89 | m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( |
Dan Sinclair | 50cce60 | 2016-02-24 09:51:16 -0500 | [diff] [blame] | 90 | GetClientRect(), 1.0f)); // +1 for caret beside border |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 91 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 92 | CPWL_EditCtrl::RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 95 | CFX_FloatRect CPWL_Edit::GetClientRect() const { |
| 96 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 97 | GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth())); |
| 98 | |
| 99 | if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { |
| 100 | if (pVSB->IsVisible()) { |
| 101 | rcClient.right -= PWL_SCROLLBAR_WIDTH; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | return rcClient; |
| 106 | } |
| 107 | |
| 108 | void CPWL_Edit::SetAlignFormatH(PWL_EDIT_ALIGNFORMAT_H nFormat, |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 109 | FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 110 | m_pEdit->SetAlignmentH((int32_t)nFormat, bPaint); |
| 111 | } |
| 112 | |
| 113 | void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat, |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 114 | FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 115 | m_pEdit->SetAlignmentV((int32_t)nFormat, bPaint); |
| 116 | } |
| 117 | |
| 118 | FX_BOOL CPWL_Edit::CanSelectAll() const { |
| 119 | return GetSelectWordRange() != m_pEdit->GetWholeWordRange(); |
| 120 | } |
| 121 | |
| 122 | FX_BOOL CPWL_Edit::CanClear() const { |
| 123 | return !IsReadOnly() && m_pEdit->IsSelected(); |
| 124 | } |
| 125 | |
| 126 | FX_BOOL CPWL_Edit::CanCopy() const { |
| 127 | return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) && |
| 128 | m_pEdit->IsSelected(); |
| 129 | } |
| 130 | |
| 131 | FX_BOOL CPWL_Edit::CanCut() const { |
| 132 | return CanCopy() && !IsReadOnly(); |
| 133 | } |
| 134 | |
| 135 | FX_BOOL CPWL_Edit::CanPaste() const { |
| 136 | if (IsReadOnly()) |
| 137 | return FALSE; |
| 138 | |
| 139 | CFX_WideString swClipboard; |
| 140 | if (IFX_SystemHandler* pSH = GetSystemHandler()) |
| 141 | swClipboard = pSH->GetClipboardText(GetAttachedHWnd()); |
| 142 | |
| 143 | return !swClipboard.IsEmpty(); |
| 144 | } |
| 145 | |
| 146 | void CPWL_Edit::CopyText() { |
| 147 | if (!CanCopy()) |
| 148 | return; |
| 149 | |
| 150 | CFX_WideString str = m_pEdit->GetSelText(); |
| 151 | |
| 152 | if (IFX_SystemHandler* pSH = GetSystemHandler()) |
| 153 | pSH->SetClipboardText(GetAttachedHWnd(), str); |
| 154 | } |
| 155 | |
| 156 | void CPWL_Edit::PasteText() { |
| 157 | if (!CanPaste()) |
| 158 | return; |
| 159 | |
| 160 | CFX_WideString swClipboard; |
| 161 | if (IFX_SystemHandler* pSH = GetSystemHandler()) |
| 162 | swClipboard = pSH->GetClipboardText(GetAttachedHWnd()); |
| 163 | |
| 164 | if (m_pFillerNotify) { |
| 165 | FX_BOOL bRC = TRUE; |
| 166 | FX_BOOL bExit = FALSE; |
| 167 | CFX_WideString strChangeEx; |
| 168 | int nSelStart = 0; |
| 169 | int nSelEnd = 0; |
| 170 | GetSel(nSelStart, nSelEnd); |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 171 | m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swClipboard, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 172 | strChangeEx, nSelStart, nSelEnd, TRUE, |
| 173 | bRC, bExit, 0); |
| 174 | if (!bRC) |
| 175 | return; |
| 176 | if (bExit) |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | if (swClipboard.GetLength() > 0) { |
| 181 | Clear(); |
| 182 | InsertText(swClipboard.c_str()); |
| 183 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | void CPWL_Edit::CutText() { |
| 187 | if (!CanCut()) |
| 188 | return; |
| 189 | |
| 190 | CFX_WideString str = m_pEdit->GetSelText(); |
| 191 | |
| 192 | if (IFX_SystemHandler* pSH = GetSystemHandler()) |
| 193 | pSH->SetClipboardText(GetAttachedHWnd(), str); |
| 194 | |
| 195 | m_pEdit->Clear(); |
| 196 | } |
| 197 | |
| 198 | void CPWL_Edit::OnCreated() { |
| 199 | CPWL_EditCtrl::OnCreated(); |
| 200 | |
| 201 | if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { |
| 202 | pScroll->RemoveFlag(PWS_AUTOTRANSPARENT); |
| 203 | pScroll->SetTransparency(255); |
| 204 | } |
| 205 | |
| 206 | SetParamByFlag(); |
| 207 | |
| 208 | m_rcOldWindow = GetWindowRect(); |
| 209 | |
| 210 | m_pEdit->SetOprNotify(this); |
| 211 | m_pEdit->EnableOprNotify(TRUE); |
| 212 | } |
| 213 | |
| 214 | void CPWL_Edit::SetParamByFlag() { |
| 215 | if (HasFlag(PES_RIGHT)) { |
| 216 | m_pEdit->SetAlignmentH(2, FALSE); |
| 217 | } else if (HasFlag(PES_MIDDLE)) { |
| 218 | m_pEdit->SetAlignmentH(1, FALSE); |
| 219 | } else { |
| 220 | m_pEdit->SetAlignmentH(0, FALSE); |
| 221 | } |
| 222 | |
| 223 | if (HasFlag(PES_BOTTOM)) { |
| 224 | m_pEdit->SetAlignmentV(2, FALSE); |
| 225 | } else if (HasFlag(PES_CENTER)) { |
| 226 | m_pEdit->SetAlignmentV(1, FALSE); |
| 227 | } else { |
| 228 | m_pEdit->SetAlignmentV(0, FALSE); |
| 229 | } |
| 230 | |
| 231 | if (HasFlag(PES_PASSWORD)) { |
| 232 | m_pEdit->SetPasswordChar('*', FALSE); |
| 233 | } |
| 234 | |
| 235 | m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), FALSE); |
| 236 | m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), FALSE); |
| 237 | m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), FALSE); |
| 238 | m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), FALSE); |
| 239 | m_pEdit->EnableUndo(HasFlag(PES_UNDO)); |
| 240 | |
| 241 | if (HasFlag(PES_TEXTOVERFLOW)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 242 | SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 243 | m_pEdit->SetTextOverflow(TRUE, FALSE); |
| 244 | } else { |
| 245 | if (m_pEditCaret) { |
| 246 | m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( |
Dan Sinclair | 50cce60 | 2016-02-24 09:51:16 -0500 | [diff] [blame] | 247 | GetClientRect(), 1.0f)); // +1 for caret beside border |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
| 251 | if (HasFlag(PES_SPELLCHECK)) { |
| 252 | m_pSpellCheck = GetCreationParam().pSpellCheck; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
| 257 | CPWL_Wnd::GetThisAppearanceStream(sAppStream); |
| 258 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 259 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 260 | CFX_ByteTextBuf sLine; |
| 261 | |
| 262 | int32_t nCharArray = m_pEdit->GetCharArray(); |
| 263 | |
| 264 | if (nCharArray > 0) { |
| 265 | switch (GetBorderStyle()) { |
| 266 | case PBS_SOLID: { |
| 267 | sLine << "q\n" << GetBorderWidth() << " w\n" |
| 268 | << CPWL_Utils::GetColorAppStream(GetBorderColor(), FALSE) |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 269 | .AsByteStringC() |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 270 | << " 2 J 0 j\n"; |
| 271 | |
| 272 | for (int32_t i = 1; i < nCharArray; i++) { |
| 273 | sLine << rcClient.left + |
| 274 | ((rcClient.right - rcClient.left) / nCharArray) * i |
| 275 | << " " << rcClient.bottom << " m\n" |
| 276 | << rcClient.left + |
| 277 | ((rcClient.right - rcClient.left) / nCharArray) * i |
| 278 | << " " << rcClient.top << " l S\n"; |
| 279 | } |
| 280 | |
| 281 | sLine << "Q\n"; |
| 282 | } break; |
| 283 | case PBS_DASH: { |
| 284 | sLine << "q\n" << GetBorderWidth() << " w\n" |
| 285 | << CPWL_Utils::GetColorAppStream(GetBorderColor(), FALSE) |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 286 | .AsByteStringC() |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 287 | << " 2 J 0 j\n" |
| 288 | << "[" << GetBorderDash().nDash << " " << GetBorderDash().nGap |
| 289 | << "] " << GetBorderDash().nPhase << " d\n"; |
| 290 | |
| 291 | for (int32_t i = 1; i < nCharArray; i++) { |
| 292 | sLine << rcClient.left + |
| 293 | ((rcClient.right - rcClient.left) / nCharArray) * i |
| 294 | << " " << rcClient.bottom << " m\n" |
| 295 | << rcClient.left + |
| 296 | ((rcClient.right - rcClient.left) / nCharArray) * i |
| 297 | << " " << rcClient.top << " l S\n"; |
| 298 | } |
| 299 | |
| 300 | sLine << "Q\n"; |
| 301 | } break; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | sAppStream << sLine; |
| 306 | |
| 307 | CFX_ByteTextBuf sText; |
| 308 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 309 | CFX_FloatPoint ptOffset = CFX_FloatPoint(0.0f, 0.0f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 310 | |
| 311 | CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange(); |
| 312 | CPVT_WordRange wrSelect = GetSelectWordRange(); |
| 313 | CPVT_WordRange wrVisible = |
| 314 | (HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange()); |
| 315 | CPVT_WordRange wrSelBefore(wrWhole.BeginPos, wrSelect.BeginPos); |
| 316 | CPVT_WordRange wrSelAfter(wrSelect.EndPos, wrWhole.EndPos); |
| 317 | |
| 318 | CPVT_WordRange wrTemp = |
| 319 | CPWL_Utils::OverlapWordRange(GetSelectWordRange(), wrVisible); |
| 320 | CFX_ByteString sEditSel = |
| 321 | CPWL_Utils::GetEditSelAppStream(m_pEdit, ptOffset, &wrTemp); |
| 322 | |
| 323 | if (sEditSel.GetLength() > 0) |
| 324 | sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR) |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 325 | .AsByteStringC() |
| 326 | << sEditSel.AsByteStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 327 | |
| 328 | wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelBefore); |
| 329 | CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream( |
| 330 | m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), |
| 331 | m_pEdit->GetPasswordChar()); |
| 332 | |
| 333 | if (sEditBefore.GetLength() > 0) |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 334 | sText << "BT\n" |
| 335 | << CPWL_Utils::GetColorAppStream(GetTextColor()).AsByteStringC() |
| 336 | << sEditBefore.AsByteStringC() << "ET\n"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 337 | |
| 338 | wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelect); |
| 339 | CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream( |
| 340 | m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), |
| 341 | m_pEdit->GetPasswordChar()); |
| 342 | |
| 343 | if (sEditMid.GetLength() > 0) |
| 344 | sText << "BT\n" |
| 345 | << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1)) |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 346 | .AsByteStringC() |
| 347 | << sEditMid.AsByteStringC() << "ET\n"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 348 | |
| 349 | wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter); |
| 350 | CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream( |
| 351 | m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), |
| 352 | m_pEdit->GetPasswordChar()); |
| 353 | |
| 354 | if (sEditAfter.GetLength() > 0) |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 355 | sText << "BT\n" |
| 356 | << CPWL_Utils::GetColorAppStream(GetTextColor()).AsByteStringC() |
| 357 | << sEditAfter.AsByteStringC() << "ET\n"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 358 | |
| 359 | if (HasFlag(PES_SPELLCHECK)) { |
| 360 | CFX_ByteString sSpellCheck = CPWL_Utils::GetSpellCheckAppStream( |
| 361 | m_pEdit, m_pSpellCheck, ptOffset, &wrVisible); |
| 362 | if (sSpellCheck.GetLength() > 0) |
| 363 | sText << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_RGB, 1, 0, 0), |
| 364 | FALSE) |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 365 | .AsByteStringC() |
| 366 | << sSpellCheck.AsByteStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | if (sText.GetLength() > 0) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 370 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 371 | sAppStream << "q\n/Tx BMC\n"; |
| 372 | |
| 373 | if (!HasFlag(PES_TEXTOVERFLOW)) |
| 374 | sAppStream << rcClient.left << " " << rcClient.bottom << " " |
| 375 | << rcClient.right - rcClient.left << " " |
| 376 | << rcClient.top - rcClient.bottom << " re W n\n"; |
| 377 | |
| 378 | sAppStream << sText; |
| 379 | |
| 380 | sAppStream << "EMC\nQ\n"; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 385 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 386 | CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); |
| 387 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 388 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 389 | CFX_ByteTextBuf sLine; |
| 390 | |
| 391 | int32_t nCharArray = m_pEdit->GetCharArray(); |
| 392 | FX_SAFE_INT32 nCharArraySafe = nCharArray; |
| 393 | nCharArraySafe -= 1; |
| 394 | nCharArraySafe *= 2; |
| 395 | |
| 396 | if (nCharArray > 0 && nCharArraySafe.IsValid()) { |
| 397 | switch (GetBorderStyle()) { |
| 398 | case PBS_SOLID: { |
| 399 | CFX_GraphStateData gsd; |
| 400 | gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth(); |
| 401 | |
| 402 | CFX_PathData path; |
| 403 | path.SetPointCount(nCharArraySafe.ValueOrDie()); |
| 404 | |
| 405 | for (int32_t i = 0; i < nCharArray - 1; i++) { |
| 406 | path.SetPoint( |
| 407 | i * 2, |
| 408 | rcClient.left + |
| 409 | ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
| 410 | rcClient.bottom, FXPT_MOVETO); |
| 411 | path.SetPoint( |
| 412 | i * 2 + 1, |
| 413 | rcClient.left + |
| 414 | ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
| 415 | rcClient.top, FXPT_LINETO); |
| 416 | } |
| 417 | if (path.GetPointCount() > 0) |
| 418 | pDevice->DrawPath( |
| 419 | &path, pUser2Device, &gsd, 0, |
| 420 | CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255), |
| 421 | FXFILL_ALTERNATE); |
| 422 | } break; |
| 423 | case PBS_DASH: { |
| 424 | CFX_GraphStateData gsd; |
| 425 | gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth(); |
| 426 | |
| 427 | gsd.SetDashCount(2); |
| 428 | gsd.m_DashArray[0] = (FX_FLOAT)GetBorderDash().nDash; |
| 429 | gsd.m_DashArray[1] = (FX_FLOAT)GetBorderDash().nGap; |
| 430 | gsd.m_DashPhase = (FX_FLOAT)GetBorderDash().nPhase; |
| 431 | |
| 432 | CFX_PathData path; |
| 433 | path.SetPointCount(nCharArraySafe.ValueOrDie()); |
| 434 | |
| 435 | for (int32_t i = 0; i < nCharArray - 1; i++) { |
| 436 | path.SetPoint( |
| 437 | i * 2, |
| 438 | rcClient.left + |
| 439 | ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
| 440 | rcClient.bottom, FXPT_MOVETO); |
| 441 | path.SetPoint( |
| 442 | i * 2 + 1, |
| 443 | rcClient.left + |
| 444 | ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
| 445 | rcClient.top, FXPT_LINETO); |
| 446 | } |
| 447 | if (path.GetPointCount() > 0) |
| 448 | pDevice->DrawPath( |
| 449 | &path, pUser2Device, &gsd, 0, |
| 450 | CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255), |
| 451 | FXFILL_ALTERNATE); |
| 452 | } break; |
| 453 | } |
| 454 | } |
| 455 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 456 | CFX_FloatRect rcClip; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 457 | CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange(); |
| 458 | CPVT_WordRange* pRange = NULL; |
| 459 | |
| 460 | if (!HasFlag(PES_TEXTOVERFLOW)) { |
| 461 | rcClip = GetClientRect(); |
| 462 | pRange = &wrRange; |
| 463 | } |
| 464 | IFX_SystemHandler* pSysHandler = GetSystemHandler(); |
| 465 | IFX_Edit::DrawEdit( |
| 466 | pDevice, pUser2Device, m_pEdit, |
| 467 | CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), |
| 468 | CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTransparency()), |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 469 | rcClip, CFX_FloatPoint(0.0f, 0.0f), pRange, pSysHandler, m_pFormFiller); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 470 | |
| 471 | if (HasFlag(PES_SPELLCHECK)) { |
| 472 | CPWL_Utils::DrawEditSpellCheck(pDevice, pUser2Device, m_pEdit, rcClip, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 473 | CFX_FloatPoint(0.0f, 0.0f), pRange, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 474 | GetCreationParam().pSpellCheck); |
| 475 | } |
| 476 | } |
| 477 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 478 | FX_BOOL CPWL_Edit::OnLButtonDown(const CFX_FloatPoint& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 479 | CPWL_Wnd::OnLButtonDown(point, nFlag); |
| 480 | |
| 481 | if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { |
| 482 | if (m_bMouseDown) |
| 483 | InvalidateRect(); |
| 484 | |
| 485 | m_bMouseDown = TRUE; |
| 486 | SetCapture(); |
| 487 | |
| 488 | m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 489 | } |
| 490 | |
| 491 | return TRUE; |
| 492 | } |
| 493 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 494 | FX_BOOL CPWL_Edit::OnLButtonDblClk(const CFX_FloatPoint& point, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 495 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 496 | CPWL_Wnd::OnLButtonDblClk(point, nFlag); |
| 497 | |
| 498 | if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { |
| 499 | m_pEdit->SelectAll(); |
| 500 | } |
| 501 | |
| 502 | return TRUE; |
| 503 | } |
| 504 | |
| 505 | #define WM_PWLEDIT_UNDO 0x01 |
| 506 | #define WM_PWLEDIT_REDO 0x02 |
| 507 | #define WM_PWLEDIT_CUT 0x03 |
| 508 | #define WM_PWLEDIT_COPY 0x04 |
| 509 | #define WM_PWLEDIT_PASTE 0x05 |
| 510 | #define WM_PWLEDIT_DELETE 0x06 |
| 511 | #define WM_PWLEDIT_SELECTALL 0x07 |
| 512 | #define WM_PWLEDIT_SUGGEST 0x08 |
| 513 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 514 | FX_BOOL CPWL_Edit::OnRButtonUp(const CFX_FloatPoint& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 515 | if (m_bMouseDown) |
| 516 | return FALSE; |
| 517 | |
| 518 | CPWL_Wnd::OnRButtonUp(point, nFlag); |
| 519 | |
| 520 | if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point)) |
| 521 | return TRUE; |
| 522 | |
| 523 | IFX_SystemHandler* pSH = GetSystemHandler(); |
| 524 | if (!pSH) |
| 525 | return FALSE; |
| 526 | |
| 527 | SetFocus(); |
| 528 | |
| 529 | CPVT_WordRange wrLatin = GetLatinWordsRange(point); |
| 530 | CFX_WideString swLatin = m_pEdit->GetRangeText(wrLatin); |
| 531 | |
| 532 | FX_HMENU hPopup = pSH->CreatePopupMenu(); |
| 533 | if (!hPopup) |
| 534 | return FALSE; |
| 535 | |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 536 | std::vector<CFX_ByteString> sSuggestWords; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 537 | CFX_FloatPoint ptPopup = point; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 538 | |
| 539 | if (!IsReadOnly()) { |
| 540 | if (HasFlag(PES_SPELLCHECK) && !swLatin.IsEmpty()) { |
| 541 | if (m_pSpellCheck) { |
| 542 | CFX_ByteString sLatin = CFX_ByteString::FromUnicode(swLatin); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 543 | if (!m_pSpellCheck->CheckWord(sLatin)) { |
| 544 | m_pSpellCheck->SuggestWords(sLatin, sSuggestWords); |
| 545 | |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 546 | int32_t nSuggest = pdfium::CollectionSize<int32_t>(sSuggestWords); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 547 | for (int32_t nWord = 0; nWord < nSuggest; nWord++) { |
| 548 | pSH->AppendMenuItem(hPopup, WM_PWLEDIT_SUGGEST + nWord, |
| 549 | sSuggestWords[nWord].UTF8Decode()); |
| 550 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 551 | if (nSuggest > 0) |
| 552 | pSH->AppendMenuItem(hPopup, 0, L""); |
| 553 | |
| 554 | ptPopup = GetWordRightBottomPoint(wrLatin.EndPos); |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | IPWL_Provider* pProvider = GetProvider(); |
| 561 | |
| 562 | if (HasFlag(PES_UNDO)) { |
| 563 | pSH->AppendMenuItem( |
| 564 | hPopup, WM_PWLEDIT_UNDO, |
| 565 | pProvider ? pProvider->LoadPopupMenuString(0) : L"&Undo"); |
| 566 | pSH->AppendMenuItem( |
| 567 | hPopup, WM_PWLEDIT_REDO, |
| 568 | pProvider ? pProvider->LoadPopupMenuString(1) : L"&Redo"); |
| 569 | pSH->AppendMenuItem(hPopup, 0, L""); |
| 570 | |
| 571 | if (!m_pEdit->CanUndo()) |
| 572 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_UNDO, FALSE); |
| 573 | if (!m_pEdit->CanRedo()) |
| 574 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_REDO, FALSE); |
| 575 | } |
| 576 | |
| 577 | pSH->AppendMenuItem(hPopup, WM_PWLEDIT_CUT, |
| 578 | pProvider ? pProvider->LoadPopupMenuString(2) : L"Cu&t"); |
| 579 | pSH->AppendMenuItem(hPopup, WM_PWLEDIT_COPY, |
| 580 | pProvider ? pProvider->LoadPopupMenuString(3) : L"&Copy"); |
| 581 | pSH->AppendMenuItem( |
| 582 | hPopup, WM_PWLEDIT_PASTE, |
| 583 | pProvider ? pProvider->LoadPopupMenuString(4) : L"&Paste"); |
| 584 | pSH->AppendMenuItem( |
| 585 | hPopup, WM_PWLEDIT_DELETE, |
| 586 | pProvider ? pProvider->LoadPopupMenuString(5) : L"&Delete"); |
| 587 | |
| 588 | CFX_WideString swText = pSH->GetClipboardText(GetAttachedHWnd()); |
| 589 | if (swText.IsEmpty()) |
| 590 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE); |
| 591 | |
| 592 | if (!m_pEdit->IsSelected()) { |
| 593 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); |
| 594 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE); |
| 595 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE); |
| 596 | } |
| 597 | |
| 598 | if (IsReadOnly()) { |
| 599 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); |
| 600 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE); |
| 601 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE); |
| 602 | } |
| 603 | |
| 604 | if (HasFlag(PES_PASSWORD)) { |
| 605 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); |
| 606 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE); |
| 607 | } |
| 608 | |
| 609 | if (HasFlag(PES_NOREAD)) { |
| 610 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); |
| 611 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE); |
| 612 | } |
| 613 | |
| 614 | pSH->AppendMenuItem(hPopup, 0, L""); |
| 615 | pSH->AppendMenuItem( |
| 616 | hPopup, WM_PWLEDIT_SELECTALL, |
| 617 | pProvider ? pProvider->LoadPopupMenuString(6) : L"&Select All"); |
| 618 | |
| 619 | if (m_pEdit->GetTotalWords() == 0) { |
| 620 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_SELECTALL, FALSE); |
| 621 | } |
| 622 | |
| 623 | int32_t x, y; |
| 624 | PWLtoWnd(ptPopup, x, y); |
| 625 | pSH->ClientToScreen(GetAttachedHWnd(), x, y); |
| 626 | pSH->SetCursor(FXCT_ARROW); |
| 627 | int32_t nCmd = pSH->TrackPopupMenu(hPopup, x, y, GetAttachedHWnd()); |
| 628 | |
| 629 | switch (nCmd) { |
| 630 | case WM_PWLEDIT_UNDO: |
| 631 | Undo(); |
| 632 | break; |
| 633 | case WM_PWLEDIT_REDO: |
| 634 | Redo(); |
| 635 | break; |
| 636 | case WM_PWLEDIT_CUT: |
| 637 | CutText(); |
| 638 | break; |
| 639 | case WM_PWLEDIT_COPY: |
| 640 | CopyText(); |
| 641 | break; |
| 642 | case WM_PWLEDIT_PASTE: |
| 643 | PasteText(); |
| 644 | break; |
| 645 | case WM_PWLEDIT_DELETE: |
| 646 | Clear(); |
| 647 | break; |
| 648 | case WM_PWLEDIT_SELECTALL: |
| 649 | SelectAll(); |
| 650 | break; |
| 651 | case WM_PWLEDIT_SUGGEST + 0: |
| 652 | SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), |
| 653 | m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); |
| 654 | ReplaceSel(sSuggestWords[0].UTF8Decode().c_str()); |
| 655 | break; |
| 656 | case WM_PWLEDIT_SUGGEST + 1: |
| 657 | SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), |
| 658 | m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); |
| 659 | ReplaceSel(sSuggestWords[1].UTF8Decode().c_str()); |
| 660 | break; |
| 661 | case WM_PWLEDIT_SUGGEST + 2: |
| 662 | SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), |
| 663 | m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); |
| 664 | ReplaceSel(sSuggestWords[2].UTF8Decode().c_str()); |
| 665 | break; |
| 666 | case WM_PWLEDIT_SUGGEST + 3: |
| 667 | SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), |
| 668 | m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); |
| 669 | ReplaceSel(sSuggestWords[3].UTF8Decode().c_str()); |
| 670 | break; |
| 671 | case WM_PWLEDIT_SUGGEST + 4: |
| 672 | SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), |
| 673 | m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); |
| 674 | ReplaceSel(sSuggestWords[4].UTF8Decode().c_str()); |
| 675 | break; |
| 676 | default: |
| 677 | break; |
| 678 | } |
| 679 | |
| 680 | pSH->DestroyMenu(hPopup); |
| 681 | |
| 682 | return TRUE; |
| 683 | } |
| 684 | |
| 685 | void CPWL_Edit::OnSetFocus() { |
| 686 | SetEditCaret(TRUE); |
| 687 | |
| 688 | if (!IsReadOnly()) { |
| 689 | if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler()) |
| 690 | pFocusHandler->OnSetFocus(this); |
| 691 | } |
| 692 | |
| 693 | m_bFocus = TRUE; |
| 694 | } |
| 695 | |
| 696 | void CPWL_Edit::OnKillFocus() { |
| 697 | ShowVScrollBar(FALSE); |
| 698 | |
| 699 | m_pEdit->SelectNone(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 700 | SetCaret(FALSE, CFX_FloatPoint(0.0f, 0.0f), CFX_FloatPoint(0.0f, 0.0f)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 701 | |
| 702 | SetCharSet(0); |
| 703 | |
| 704 | if (!IsReadOnly()) { |
| 705 | if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler()) |
| 706 | pFocusHandler->OnKillFocus(this); |
| 707 | } |
| 708 | |
| 709 | m_bFocus = FALSE; |
| 710 | } |
| 711 | |
| 712 | void CPWL_Edit::SetHorzScale(int32_t nHorzScale, FX_BOOL bPaint /* = TRUE*/) { |
| 713 | m_pEdit->SetHorzScale(nHorzScale, bPaint); |
| 714 | } |
| 715 | |
| 716 | void CPWL_Edit::SetCharSpace(FX_FLOAT fCharSpace, FX_BOOL bPaint /* = TRUE*/) { |
| 717 | m_pEdit->SetCharSpace(fCharSpace, bPaint); |
| 718 | } |
| 719 | |
| 720 | void CPWL_Edit::SetLineLeading(FX_FLOAT fLineLeading, |
| 721 | FX_BOOL bPaint /* = TRUE*/) { |
| 722 | m_pEdit->SetLineLeading(fLineLeading, bPaint); |
| 723 | } |
| 724 | |
| 725 | CFX_ByteString CPWL_Edit::GetSelectAppearanceStream( |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 726 | const CFX_FloatPoint& ptOffset) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 727 | CPVT_WordRange wr = GetSelectWordRange(); |
| 728 | return CPWL_Utils::GetEditSelAppStream(m_pEdit, ptOffset, &wr); |
| 729 | } |
| 730 | |
| 731 | CPVT_WordRange CPWL_Edit::GetSelectWordRange() const { |
| 732 | if (m_pEdit->IsSelected()) { |
| 733 | int32_t nStart = -1; |
| 734 | int32_t nEnd = -1; |
| 735 | |
| 736 | m_pEdit->GetSel(nStart, nEnd); |
| 737 | |
| 738 | CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart); |
| 739 | CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd); |
| 740 | |
| 741 | return CPVT_WordRange(wpStart, wpEnd); |
| 742 | } |
| 743 | |
| 744 | return CPVT_WordRange(); |
| 745 | } |
| 746 | |
| 747 | CFX_ByteString CPWL_Edit::GetTextAppearanceStream( |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 748 | const CFX_FloatPoint& ptOffset) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 749 | CFX_ByteTextBuf sRet; |
| 750 | CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset); |
| 751 | |
| 752 | if (sEdit.GetLength() > 0) { |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 753 | sRet << "BT\n" |
| 754 | << CPWL_Utils::GetColorAppStream(GetTextColor()).AsByteStringC() |
| 755 | << sEdit.AsByteStringC() << "ET\n"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | return sRet.GetByteString(); |
| 759 | } |
| 760 | |
| 761 | CFX_ByteString CPWL_Edit::GetCaretAppearanceStream( |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 762 | const CFX_FloatPoint& ptOffset) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 763 | if (m_pEditCaret) |
| 764 | return m_pEditCaret->GetCaretAppearanceStream(ptOffset); |
| 765 | |
| 766 | return CFX_ByteString(); |
| 767 | } |
| 768 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 769 | CFX_FloatPoint CPWL_Edit::GetWordRightBottomPoint( |
| 770 | const CPVT_WordPlace& wpWord) { |
| 771 | CFX_FloatPoint pt(0.0f, 0.0f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 772 | |
| 773 | if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) { |
| 774 | CPVT_WordPlace wpOld = pIterator->GetAt(); |
| 775 | pIterator->SetAt(wpWord); |
| 776 | CPVT_Word word; |
| 777 | if (pIterator->GetWord(word)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 778 | pt = CFX_FloatPoint(word.ptWord.x + word.fWidth, |
| 779 | word.ptWord.y + word.fDescent); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 780 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 781 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 782 | pIterator->SetAt(wpOld); |
| 783 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 784 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 785 | return pt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 788 | FX_BOOL CPWL_Edit::IsTextFull() const { |
| 789 | return m_pEdit->IsTextFull(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 792 | FX_FLOAT CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 793 | const CFX_FloatRect& rcPlate, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 794 | int32_t nCharArray) { |
| 795 | if (pFont && !pFont->IsStandardFont()) { |
| 796 | FX_RECT rcBBox; |
| 797 | pFont->GetFontBBox(rcBBox); |
| 798 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 799 | CFX_FloatRect rcCell = rcPlate; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 800 | FX_FLOAT xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width(); |
| 801 | FX_FLOAT ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height(); |
| 802 | |
| 803 | return xdiv < ydiv ? xdiv : ydiv; |
| 804 | } |
| 805 | |
| 806 | return 0.0f; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 809 | void CPWL_Edit::SetCharArray(int32_t nCharArray) { |
| 810 | if (HasFlag(PES_CHARARRAY) && nCharArray > 0) { |
| 811 | m_pEdit->SetCharArray(nCharArray); |
| 812 | m_pEdit->SetTextOverflow(TRUE); |
| 813 | |
| 814 | if (HasFlag(PWS_AUTOFONTSIZE)) { |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame^] | 815 | if (IPVT_FontMap* pFontMap = GetFontMap()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 816 | FX_FLOAT fFontSize = GetCharArrayAutoFontSize( |
| 817 | pFontMap->GetPDFFont(0), GetClientRect(), nCharArray); |
| 818 | if (fFontSize > 0.0f) { |
| 819 | m_pEdit->SetAutoFontSize(FALSE); |
| 820 | m_pEdit->SetFontSize(fFontSize); |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 827 | void CPWL_Edit::SetLimitChar(int32_t nLimitChar) { |
| 828 | m_pEdit->SetLimitChar(nLimitChar); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 829 | } |
| 830 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 831 | void CPWL_Edit::ReplaceSel(const FX_WCHAR* csText) { |
| 832 | m_pEdit->Clear(); |
| 833 | m_pEdit->InsertText(csText); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 834 | } |
| 835 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 836 | CFX_FloatRect CPWL_Edit::GetFocusRect() const { |
| 837 | return CFX_FloatRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 840 | void CPWL_Edit::ShowVScrollBar(FX_BOOL bShow) { |
| 841 | if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { |
| 842 | if (bShow) { |
| 843 | if (!pScroll->IsVisible()) { |
| 844 | pScroll->SetVisible(TRUE); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 845 | CFX_FloatRect rcWindow = GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 846 | m_rcOldWindow = rcWindow; |
| 847 | rcWindow.right += PWL_SCROLLBAR_WIDTH; |
| 848 | Move(rcWindow, TRUE, TRUE); |
| 849 | } |
| 850 | } else { |
| 851 | if (pScroll->IsVisible()) { |
| 852 | pScroll->SetVisible(FALSE); |
| 853 | Move(m_rcOldWindow, TRUE, TRUE); |
| 854 | } |
| 855 | } |
| 856 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 859 | FX_BOOL CPWL_Edit::IsVScrollBarVisible() const { |
| 860 | if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { |
| 861 | return pScroll->IsVisible(); |
| 862 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 863 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 864 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 867 | void CPWL_Edit::EnableSpellCheck(FX_BOOL bEnabled) { |
| 868 | if (bEnabled) |
| 869 | AddFlag(PES_SPELLCHECK); |
| 870 | else |
| 871 | RemoveFlag(PES_SPELLCHECK); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 872 | } |
| 873 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 874 | FX_BOOL CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 875 | if (m_bMouseDown) |
| 876 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 877 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 878 | if (nChar == FWL_VKEY_Delete) { |
| 879 | if (m_pFillerNotify) { |
| 880 | FX_BOOL bRC = TRUE; |
| 881 | FX_BOOL bExit = FALSE; |
| 882 | CFX_WideString strChange; |
| 883 | CFX_WideString strChangeEx; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 884 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 885 | int nSelStart = 0; |
| 886 | int nSelEnd = 0; |
| 887 | GetSel(nSelStart, nSelEnd); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 888 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 889 | if (nSelStart == nSelEnd) |
| 890 | nSelEnd = nSelStart + 1; |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 891 | m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange, |
| 892 | strChangeEx, nSelStart, nSelEnd, TRUE, |
| 893 | bRC, bExit, nFlag); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 894 | if (!bRC) |
| 895 | return FALSE; |
| 896 | if (bExit) |
| 897 | return FALSE; |
| 898 | } |
| 899 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 900 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 901 | FX_BOOL bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 902 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 903 | // In case of implementation swallow the OnKeyDown event. |
| 904 | if (IsProceedtoOnChar(nChar, nFlag)) |
| 905 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 906 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 907 | return bRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | /** |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 911 | *In case of implementation swallow the OnKeyDown event. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 912 | *If the event is swallowed, implementation may do other unexpected things, which |
| 913 | *is not the control means to do. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 914 | */ |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 915 | FX_BOOL CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 916 | FX_BOOL bCtrl = IsCTRLpressed(nFlag); |
| 917 | FX_BOOL bAlt = IsALTpressed(nFlag); |
| 918 | if (bCtrl && !bAlt) { |
| 919 | // hot keys for edit control. |
| 920 | switch (nKeyCode) { |
| 921 | case 'C': |
| 922 | case 'V': |
| 923 | case 'X': |
| 924 | case 'A': |
| 925 | case 'Z': |
| 926 | return TRUE; |
| 927 | default: |
| 928 | break; |
| 929 | } |
| 930 | } |
| 931 | // control characters. |
| 932 | switch (nKeyCode) { |
| 933 | case FWL_VKEY_Escape: |
| 934 | case FWL_VKEY_Back: |
| 935 | case FWL_VKEY_Return: |
| 936 | case FWL_VKEY_Space: |
| 937 | return TRUE; |
| 938 | default: |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 939 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 940 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 941 | } |
| 942 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 943 | FX_BOOL CPWL_Edit::OnChar(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 944 | if (m_bMouseDown) |
| 945 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 946 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 947 | FX_BOOL bRC = TRUE; |
| 948 | FX_BOOL bExit = FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 949 | |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 950 | if (!IsCTRLpressed(nFlag)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 951 | if (m_pFillerNotify) { |
| 952 | CFX_WideString swChange; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 953 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 954 | int nSelStart = 0; |
| 955 | int nSelEnd = 0; |
| 956 | GetSel(nSelStart, nSelEnd); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 957 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 958 | switch (nChar) { |
| 959 | case FWL_VKEY_Back: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 960 | if (nSelStart == nSelEnd) |
| 961 | nSelStart = nSelEnd - 1; |
| 962 | break; |
| 963 | case FWL_VKEY_Return: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 964 | break; |
| 965 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 966 | swChange += nChar; |
| 967 | break; |
| 968 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 969 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 970 | CFX_WideString strChangeEx; |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 971 | m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange, |
| 972 | strChangeEx, nSelStart, nSelEnd, TRUE, |
| 973 | bRC, bExit, nFlag); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 974 | } |
| 975 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 976 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 977 | if (!bRC) |
| 978 | return TRUE; |
| 979 | if (bExit) |
| 980 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 981 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame^] | 982 | if (IPVT_FontMap* pFontMap = GetFontMap()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 983 | int32_t nOldCharSet = GetCharSet(); |
| 984 | int32_t nNewCharSet = pFontMap->CharSetFromUnicode(nChar, DEFAULT_CHARSET); |
| 985 | if (nOldCharSet != nNewCharSet) { |
| 986 | SetCharSet(nNewCharSet); |
| 987 | } |
| 988 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 989 | |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 990 | return CPWL_EditCtrl::OnChar(nChar, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 991 | } |
| 992 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 993 | FX_BOOL CPWL_Edit::OnMouseWheel(short zDelta, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 994 | const CFX_FloatPoint& point, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 995 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 996 | if (HasFlag(PES_MULTILINE)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 997 | CFX_FloatPoint ptScroll = GetScrollPos(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 998 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 999 | if (zDelta > 0) { |
| 1000 | ptScroll.y += GetFontSize(); |
| 1001 | } else { |
| 1002 | ptScroll.y -= GetFontSize(); |
| 1003 | } |
| 1004 | SetScrollPos(ptScroll); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1005 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1006 | return TRUE; |
| 1007 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1008 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1009 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1012 | void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place, |
| 1013 | const CPVT_WordPlace& oldplace) { |
| 1014 | if (HasFlag(PES_SPELLCHECK)) { |
| 1015 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 1016 | GetLatinWordsRange(place))); |
| 1017 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1018 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1019 | if (m_pEditNotify) { |
| 1020 | m_pEditNotify->OnInsertReturn(place, oldplace); |
| 1021 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1024 | void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place, |
| 1025 | const CPVT_WordPlace& oldplace) { |
| 1026 | if (HasFlag(PES_SPELLCHECK)) { |
| 1027 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 1028 | GetLatinWordsRange(place))); |
| 1029 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1030 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1031 | if (m_pEditNotify) { |
| 1032 | m_pEditNotify->OnBackSpace(place, oldplace); |
| 1033 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1036 | void CPWL_Edit::OnDelete(const CPVT_WordPlace& place, |
| 1037 | const CPVT_WordPlace& oldplace) { |
| 1038 | if (HasFlag(PES_SPELLCHECK)) { |
| 1039 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 1040 | GetLatinWordsRange(place))); |
| 1041 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1042 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1043 | if (m_pEditNotify) { |
| 1044 | m_pEditNotify->OnDelete(place, oldplace); |
| 1045 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1048 | void CPWL_Edit::OnClear(const CPVT_WordPlace& place, |
| 1049 | const CPVT_WordPlace& oldplace) { |
| 1050 | if (HasFlag(PES_SPELLCHECK)) { |
| 1051 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 1052 | GetLatinWordsRange(place))); |
| 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 | if (m_pEditNotify) { |
| 1056 | m_pEditNotify->OnClear(place, oldplace); |
| 1057 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1060 | void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place, |
| 1061 | const CPVT_WordPlace& oldplace) { |
| 1062 | if (HasFlag(PES_SPELLCHECK)) { |
| 1063 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 1064 | GetLatinWordsRange(place))); |
| 1065 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1066 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1067 | if (m_pEditNotify) { |
| 1068 | m_pEditNotify->OnInsertWord(place, oldplace); |
| 1069 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1070 | } |
| 1071 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1072 | void CPWL_Edit::OnSetText(const CPVT_WordPlace& place, |
| 1073 | const CPVT_WordPlace& oldplace) {} |
| 1074 | |
| 1075 | void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place, |
| 1076 | const CPVT_WordPlace& oldplace) { |
| 1077 | if (HasFlag(PES_SPELLCHECK)) { |
| 1078 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 1079 | GetLatinWordsRange(place))); |
| 1080 | } |
| 1081 | |
| 1082 | if (m_pEditNotify) { |
| 1083 | m_pEditNotify->OnInsertText(place, oldplace); |
| 1084 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1087 | void CPWL_Edit::OnAddUndo(IFX_Edit_UndoItem* pUndoItem) { |
| 1088 | if (m_pEditNotify) { |
| 1089 | m_pEditNotify->OnAddUndo(this); |
| 1090 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1093 | CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1, |
| 1094 | const CPVT_WordRange& wr2) { |
| 1095 | CPVT_WordRange wrRet; |
| 1096 | |
| 1097 | if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) { |
| 1098 | wrRet.BeginPos = wr1.BeginPos; |
| 1099 | } else { |
| 1100 | wrRet.BeginPos = wr2.BeginPos; |
| 1101 | } |
| 1102 | |
| 1103 | if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) { |
| 1104 | wrRet.EndPos = wr2.EndPos; |
| 1105 | } else { |
| 1106 | wrRet.EndPos = wr1.EndPos; |
| 1107 | } |
| 1108 | |
| 1109 | return wrRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1112 | CPVT_WordRange CPWL_Edit::GetLatinWordsRange( |
| 1113 | const CFX_FloatPoint& point) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1114 | return GetSameWordsRange(m_pEdit->SearchWordPlace(point), TRUE, FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1117 | CPVT_WordRange CPWL_Edit::GetLatinWordsRange( |
| 1118 | const CPVT_WordPlace& place) const { |
| 1119 | return GetSameWordsRange(place, TRUE, FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1122 | CPVT_WordRange CPWL_Edit::GetArabicWordsRange( |
| 1123 | const CPVT_WordPlace& place) const { |
| 1124 | return GetSameWordsRange(place, FALSE, TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1127 | #define PWL_ISARABICWORD(word) \ |
| 1128 | ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC)) |
| 1129 | |
| 1130 | CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace& place, |
| 1131 | FX_BOOL bLatin, |
| 1132 | FX_BOOL bArabic) const { |
| 1133 | CPVT_WordRange range; |
| 1134 | |
| 1135 | if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) { |
| 1136 | CPVT_Word wordinfo; |
| 1137 | CPVT_WordPlace wpStart(place), wpEnd(place); |
| 1138 | pIterator->SetAt(place); |
| 1139 | |
| 1140 | if (bLatin) { |
| 1141 | while (pIterator->NextWord()) { |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1142 | if (!pIterator->GetWord(wordinfo) || |
| 1143 | !FX_EDIT_ISLATINWORD(wordinfo.Word)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1144 | break; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | wpEnd = pIterator->GetAt(); |
| 1148 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1149 | } else if (bArabic) { |
| 1150 | while (pIterator->NextWord()) { |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1151 | if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1152 | break; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1153 | |
| 1154 | wpEnd = pIterator->GetAt(); |
| 1155 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | pIterator->SetAt(place); |
| 1159 | |
| 1160 | if (bLatin) { |
| 1161 | do { |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1162 | if (!pIterator->GetWord(wordinfo) || |
| 1163 | !FX_EDIT_ISLATINWORD(wordinfo.Word)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1164 | break; |
| 1165 | } |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1166 | |
| 1167 | wpStart = pIterator->GetAt(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1168 | } while (pIterator->PrevWord()); |
| 1169 | } else if (bArabic) { |
| 1170 | do { |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1171 | if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1172 | break; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1173 | |
| 1174 | wpStart = pIterator->GetAt(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1175 | } while (pIterator->PrevWord()); |
| 1176 | } |
| 1177 | |
| 1178 | range.Set(wpStart, wpEnd); |
| 1179 | } |
| 1180 | |
| 1181 | return range; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1184 | void CPWL_Edit::GeneratePageObjects( |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1185 | CPDF_PageObjectHolder* pObjectHolder, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1186 | const CFX_FloatPoint& ptOffset, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1187 | CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { |
| 1188 | IFX_Edit::GeneratePageObjects( |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1189 | pObjectHolder, m_pEdit, ptOffset, NULL, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1190 | CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), |
| 1191 | ObjArray); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1194 | void CPWL_Edit::GeneratePageObjects(CPDF_PageObjectHolder* pObjectHolder, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1195 | const CFX_FloatPoint& ptOffset) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1196 | CFX_ArrayTemplate<CPDF_TextObject*> ObjArray; |
| 1197 | IFX_Edit::GeneratePageObjects( |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1198 | pObjectHolder, m_pEdit, ptOffset, NULL, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1199 | CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), |
| 1200 | ObjArray); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1201 | } |