| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "fpdfsdk/pdfwindow/PWL_Edit.h" | 7 #include "fpdfsdk/pdfwindow/PWL_Edit.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 11 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
| 12 #include "core/fpdfdoc/include/cpvt_word.h" | 12 #include "core/fpdfdoc/include/cpvt_word.h" |
| 13 #include "core/fxcrt/include/fx_safe_types.h" | 13 #include "core/fxcrt/include/fx_safe_types.h" |
| 14 #include "core/fxcrt/include/fx_xml.h" | 14 #include "core/fxcrt/include/fx_xml.h" |
| 15 #include "core/fxge/include/fx_ge.h" | 15 #include "core/fxge/include/fx_ge.h" |
| 16 #include "fpdfsdk/pdfwindow/PWL_Caret.h" | 16 #include "fpdfsdk/pdfwindow/PWL_Caret.h" |
| 17 #include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" | 17 #include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" |
| 18 #include "fpdfsdk/pdfwindow/PWL_FontMap.h" | 18 #include "fpdfsdk/pdfwindow/PWL_FontMap.h" |
| 19 #include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" | 19 #include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" |
| 20 #include "fpdfsdk/pdfwindow/PWL_Utils.h" | 20 #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
| 21 #include "fpdfsdk/pdfwindow/PWL_Wnd.h" | 21 #include "fpdfsdk/pdfwindow/PWL_Wnd.h" |
| 22 #include "public/fpdf_fwlevent.h" | 22 #include "public/fpdf_fwlevent.h" |
| 23 #include "third_party/base/stl_util.h" | 23 #include "third_party/base/stl_util.h" |
| 24 | 24 |
| 25 CPWL_Edit::CPWL_Edit() | 25 CPWL_Edit::CPWL_Edit() |
| 26 : m_pFillerNotify(NULL), m_pSpellCheck(NULL), m_bFocus(FALSE) { | 26 : m_pFillerNotify(nullptr), m_bFocus(FALSE), m_pFormFiller(nullptr) {} |
| 27 m_pFormFiller = NULL; | |
| 28 } | |
| 29 | 27 |
| 30 CPWL_Edit::~CPWL_Edit() { | 28 CPWL_Edit::~CPWL_Edit() { |
| 31 ASSERT(m_bFocus == FALSE); | 29 ASSERT(m_bFocus == FALSE); |
| 32 } | 30 } |
| 33 | 31 |
| 34 CFX_ByteString CPWL_Edit::GetClassName() const { | 32 CFX_ByteString CPWL_Edit::GetClassName() const { |
| 35 return PWL_CLASSNAME_EDIT; | 33 return PWL_CLASSNAME_EDIT; |
| 36 } | 34 } |
| 37 | 35 |
| 38 void CPWL_Edit::OnDestroy() {} | 36 void CPWL_Edit::OnDestroy() {} |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 238 |
| 241 if (HasFlag(PES_TEXTOVERFLOW)) { | 239 if (HasFlag(PES_TEXTOVERFLOW)) { |
| 242 SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f)); | 240 SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f)); |
| 243 m_pEdit->SetTextOverflow(TRUE, FALSE); | 241 m_pEdit->SetTextOverflow(TRUE, FALSE); |
| 244 } else { | 242 } else { |
| 245 if (m_pEditCaret) { | 243 if (m_pEditCaret) { |
| 246 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( | 244 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( |
| 247 GetClientRect(), 1.0f)); // +1 for caret beside border | 245 GetClientRect(), 1.0f)); // +1 for caret beside border |
| 248 } | 246 } |
| 249 } | 247 } |
| 250 | |
| 251 if (HasFlag(PES_SPELLCHECK)) { | |
| 252 m_pSpellCheck = GetCreationParam().pSpellCheck; | |
| 253 } | |
| 254 } | 248 } |
| 255 | 249 |
| 256 void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { | 250 void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
| 257 CPWL_Wnd::GetThisAppearanceStream(sAppStream); | 251 CPWL_Wnd::GetThisAppearanceStream(sAppStream); |
| 258 | 252 |
| 259 CFX_FloatRect rcClient = GetClientRect(); | 253 CFX_FloatRect rcClient = GetClientRect(); |
| 260 CFX_ByteTextBuf sLine; | 254 CFX_ByteTextBuf sLine; |
| 261 | 255 |
| 262 int32_t nCharArray = m_pEdit->GetCharArray(); | 256 int32_t nCharArray = m_pEdit->GetCharArray(); |
| 263 | 257 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter); | 343 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter); |
| 350 CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream( | 344 CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream( |
| 351 m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), | 345 m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), |
| 352 m_pEdit->GetPasswordChar()); | 346 m_pEdit->GetPasswordChar()); |
| 353 | 347 |
| 354 if (sEditAfter.GetLength() > 0) | 348 if (sEditAfter.GetLength() > 0) |
| 355 sText << "BT\n" | 349 sText << "BT\n" |
| 356 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsByteStringC() | 350 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsByteStringC() |
| 357 << sEditAfter.AsByteStringC() << "ET\n"; | 351 << sEditAfter.AsByteStringC() << "ET\n"; |
| 358 | 352 |
| 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) | |
| 365 .AsByteStringC() | |
| 366 << sSpellCheck.AsByteStringC(); | |
| 367 } | |
| 368 | |
| 369 if (sText.GetLength() > 0) { | 353 if (sText.GetLength() > 0) { |
| 370 CFX_FloatRect rcClient = GetClientRect(); | 354 CFX_FloatRect rcClient = GetClientRect(); |
| 371 sAppStream << "q\n/Tx BMC\n"; | 355 sAppStream << "q\n/Tx BMC\n"; |
| 372 | 356 |
| 373 if (!HasFlag(PES_TEXTOVERFLOW)) | 357 if (!HasFlag(PES_TEXTOVERFLOW)) |
| 374 sAppStream << rcClient.left << " " << rcClient.bottom << " " | 358 sAppStream << rcClient.left << " " << rcClient.bottom << " " |
| 375 << rcClient.right - rcClient.left << " " | 359 << rcClient.right - rcClient.left << " " |
| 376 << rcClient.top - rcClient.bottom << " re W n\n"; | 360 << rcClient.top - rcClient.bottom << " re W n\n"; |
| 377 | 361 |
| 378 sAppStream << sText; | 362 sAppStream << sText; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 if (!HasFlag(PES_TEXTOVERFLOW)) { | 444 if (!HasFlag(PES_TEXTOVERFLOW)) { |
| 461 rcClip = GetClientRect(); | 445 rcClip = GetClientRect(); |
| 462 pRange = &wrRange; | 446 pRange = &wrRange; |
| 463 } | 447 } |
| 464 IFX_SystemHandler* pSysHandler = GetSystemHandler(); | 448 IFX_SystemHandler* pSysHandler = GetSystemHandler(); |
| 465 IFX_Edit::DrawEdit( | 449 IFX_Edit::DrawEdit( |
| 466 pDevice, pUser2Device, m_pEdit, | 450 pDevice, pUser2Device, m_pEdit, |
| 467 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), | 451 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), |
| 468 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTransparency()), | 452 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTransparency()), |
| 469 rcClip, CFX_FloatPoint(0.0f, 0.0f), pRange, pSysHandler, m_pFormFiller); | 453 rcClip, CFX_FloatPoint(0.0f, 0.0f), pRange, pSysHandler, m_pFormFiller); |
| 470 | |
| 471 if (HasFlag(PES_SPELLCHECK)) { | |
| 472 CPWL_Utils::DrawEditSpellCheck(pDevice, pUser2Device, m_pEdit, rcClip, | |
| 473 CFX_FloatPoint(0.0f, 0.0f), pRange, | |
| 474 GetCreationParam().pSpellCheck); | |
| 475 } | |
| 476 } | 454 } |
| 477 | 455 |
| 478 FX_BOOL CPWL_Edit::OnLButtonDown(const CFX_FloatPoint& point, uint32_t nFlag) { | 456 FX_BOOL CPWL_Edit::OnLButtonDown(const CFX_FloatPoint& point, uint32_t nFlag) { |
| 479 CPWL_Wnd::OnLButtonDown(point, nFlag); | 457 CPWL_Wnd::OnLButtonDown(point, nFlag); |
| 480 | 458 |
| 481 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { | 459 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { |
| 482 if (m_bMouseDown) | 460 if (m_bMouseDown) |
| 483 InvalidateRect(); | 461 InvalidateRect(); |
| 484 | 462 |
| 485 m_bMouseDown = TRUE; | 463 m_bMouseDown = TRUE; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 CPVT_WordRange wrLatin = GetLatinWordsRange(point); | 507 CPVT_WordRange wrLatin = GetLatinWordsRange(point); |
| 530 CFX_WideString swLatin = m_pEdit->GetRangeText(wrLatin); | 508 CFX_WideString swLatin = m_pEdit->GetRangeText(wrLatin); |
| 531 | 509 |
| 532 FX_HMENU hPopup = pSH->CreatePopupMenu(); | 510 FX_HMENU hPopup = pSH->CreatePopupMenu(); |
| 533 if (!hPopup) | 511 if (!hPopup) |
| 534 return FALSE; | 512 return FALSE; |
| 535 | 513 |
| 536 std::vector<CFX_ByteString> sSuggestWords; | 514 std::vector<CFX_ByteString> sSuggestWords; |
| 537 CFX_FloatPoint ptPopup = point; | 515 CFX_FloatPoint ptPopup = point; |
| 538 | 516 |
| 539 if (!IsReadOnly()) { | |
| 540 if (HasFlag(PES_SPELLCHECK) && !swLatin.IsEmpty()) { | |
| 541 if (m_pSpellCheck) { | |
| 542 CFX_ByteString sLatin = CFX_ByteString::FromUnicode(swLatin); | |
| 543 if (!m_pSpellCheck->CheckWord(sLatin)) { | |
| 544 m_pSpellCheck->SuggestWords(sLatin, sSuggestWords); | |
| 545 | |
| 546 int32_t nSuggest = pdfium::CollectionSize<int32_t>(sSuggestWords); | |
| 547 for (int32_t nWord = 0; nWord < nSuggest; nWord++) { | |
| 548 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_SUGGEST + nWord, | |
| 549 sSuggestWords[nWord].UTF8Decode()); | |
| 550 } | |
| 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(); | 517 IPWL_Provider* pProvider = GetProvider(); |
| 561 | 518 |
| 562 if (HasFlag(PES_UNDO)) { | 519 if (HasFlag(PES_UNDO)) { |
| 563 pSH->AppendMenuItem( | 520 pSH->AppendMenuItem( |
| 564 hPopup, WM_PWLEDIT_UNDO, | 521 hPopup, WM_PWLEDIT_UNDO, |
| 565 pProvider ? pProvider->LoadPopupMenuString(0) : L"&Undo"); | 522 pProvider ? pProvider->LoadPopupMenuString(0) : L"&Undo"); |
| 566 pSH->AppendMenuItem( | 523 pSH->AppendMenuItem( |
| 567 hPopup, WM_PWLEDIT_REDO, | 524 hPopup, WM_PWLEDIT_REDO, |
| 568 pProvider ? pProvider->LoadPopupMenuString(1) : L"&Redo"); | 525 pProvider ? pProvider->LoadPopupMenuString(1) : L"&Redo"); |
| 569 pSH->AppendMenuItem(hPopup, 0, L""); | 526 pSH->AppendMenuItem(hPopup, 0, L""); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 } | 814 } |
| 858 | 815 |
| 859 FX_BOOL CPWL_Edit::IsVScrollBarVisible() const { | 816 FX_BOOL CPWL_Edit::IsVScrollBarVisible() const { |
| 860 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { | 817 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { |
| 861 return pScroll->IsVisible(); | 818 return pScroll->IsVisible(); |
| 862 } | 819 } |
| 863 | 820 |
| 864 return FALSE; | 821 return FALSE; |
| 865 } | 822 } |
| 866 | 823 |
| 867 void CPWL_Edit::EnableSpellCheck(FX_BOOL bEnabled) { | |
| 868 if (bEnabled) | |
| 869 AddFlag(PES_SPELLCHECK); | |
| 870 else | |
| 871 RemoveFlag(PES_SPELLCHECK); | |
| 872 } | |
| 873 | |
| 874 FX_BOOL CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) { | 824 FX_BOOL CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) { |
| 875 if (m_bMouseDown) | 825 if (m_bMouseDown) |
| 876 return TRUE; | 826 return TRUE; |
| 877 | 827 |
| 878 if (nChar == FWL_VKEY_Delete) { | 828 if (nChar == FWL_VKEY_Delete) { |
| 879 if (m_pFillerNotify) { | 829 if (m_pFillerNotify) { |
| 880 FX_BOOL bRC = TRUE; | 830 FX_BOOL bRC = TRUE; |
| 881 FX_BOOL bExit = FALSE; | 831 FX_BOOL bExit = FALSE; |
| 882 CFX_WideString strChange; | 832 CFX_WideString strChange; |
| 883 CFX_WideString strChangeEx; | 833 CFX_WideString strChangeEx; |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 } | 1142 } |
| 1193 | 1143 |
| 1194 void CPWL_Edit::GeneratePageObjects(CPDF_PageObjectHolder* pObjectHolder, | 1144 void CPWL_Edit::GeneratePageObjects(CPDF_PageObjectHolder* pObjectHolder, |
| 1195 const CFX_FloatPoint& ptOffset) { | 1145 const CFX_FloatPoint& ptOffset) { |
| 1196 CFX_ArrayTemplate<CPDF_TextObject*> ObjArray; | 1146 CFX_ArrayTemplate<CPDF_TextObject*> ObjArray; |
| 1197 IFX_Edit::GeneratePageObjects( | 1147 IFX_Edit::GeneratePageObjects( |
| 1198 pObjectHolder, m_pEdit, ptOffset, NULL, | 1148 pObjectHolder, m_pEdit, ptOffset, NULL, |
| 1199 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), | 1149 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), |
| 1200 ObjArray); | 1150 ObjArray); |
| 1201 } | 1151 } |
| OLD | NEW |