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() : m_pFillerNotify(NULL), m_bFocus(FALSE) { |
26 : m_pFillerNotify(NULL), m_pSpellCheck(NULL), m_bFocus(FALSE) { | |
27 m_pFormFiller = NULL; | 26 m_pFormFiller = NULL; |
Tom Sepez
2016/04/07 15:31:26
nit: move to initializer list, also nullptrs.
dsinclair
2016/04/07 16:25:27
Done.
| |
28 } | 27 } |
29 | 28 |
30 CPWL_Edit::~CPWL_Edit() { | 29 CPWL_Edit::~CPWL_Edit() { |
31 ASSERT(m_bFocus == FALSE); | 30 ASSERT(m_bFocus == FALSE); |
32 } | 31 } |
33 | 32 |
34 CFX_ByteString CPWL_Edit::GetClassName() const { | 33 CFX_ByteString CPWL_Edit::GetClassName() const { |
35 return PWL_CLASSNAME_EDIT; | 34 return PWL_CLASSNAME_EDIT; |
36 } | 35 } |
37 | 36 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 | 239 |
241 if (HasFlag(PES_TEXTOVERFLOW)) { | 240 if (HasFlag(PES_TEXTOVERFLOW)) { |
242 SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f)); | 241 SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f)); |
243 m_pEdit->SetTextOverflow(TRUE, FALSE); | 242 m_pEdit->SetTextOverflow(TRUE, FALSE); |
244 } else { | 243 } else { |
245 if (m_pEditCaret) { | 244 if (m_pEditCaret) { |
246 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( | 245 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( |
247 GetClientRect(), 1.0f)); // +1 for caret beside border | 246 GetClientRect(), 1.0f)); // +1 for caret beside border |
248 } | 247 } |
249 } | 248 } |
250 | |
251 if (HasFlag(PES_SPELLCHECK)) { | |
252 m_pSpellCheck = GetCreationParam().pSpellCheck; | |
253 } | |
254 } | 249 } |
255 | 250 |
256 void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { | 251 void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
257 CPWL_Wnd::GetThisAppearanceStream(sAppStream); | 252 CPWL_Wnd::GetThisAppearanceStream(sAppStream); |
258 | 253 |
259 CFX_FloatRect rcClient = GetClientRect(); | 254 CFX_FloatRect rcClient = GetClientRect(); |
260 CFX_ByteTextBuf sLine; | 255 CFX_ByteTextBuf sLine; |
261 | 256 |
262 int32_t nCharArray = m_pEdit->GetCharArray(); | 257 int32_t nCharArray = m_pEdit->GetCharArray(); |
263 | 258 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter); | 344 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter); |
350 CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream( | 345 CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream( |
351 m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), | 346 m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), |
352 m_pEdit->GetPasswordChar()); | 347 m_pEdit->GetPasswordChar()); |
353 | 348 |
354 if (sEditAfter.GetLength() > 0) | 349 if (sEditAfter.GetLength() > 0) |
355 sText << "BT\n" | 350 sText << "BT\n" |
356 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsByteStringC() | 351 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsByteStringC() |
357 << sEditAfter.AsByteStringC() << "ET\n"; | 352 << sEditAfter.AsByteStringC() << "ET\n"; |
358 | 353 |
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) { | 354 if (sText.GetLength() > 0) { |
370 CFX_FloatRect rcClient = GetClientRect(); | 355 CFX_FloatRect rcClient = GetClientRect(); |
371 sAppStream << "q\n/Tx BMC\n"; | 356 sAppStream << "q\n/Tx BMC\n"; |
372 | 357 |
373 if (!HasFlag(PES_TEXTOVERFLOW)) | 358 if (!HasFlag(PES_TEXTOVERFLOW)) |
374 sAppStream << rcClient.left << " " << rcClient.bottom << " " | 359 sAppStream << rcClient.left << " " << rcClient.bottom << " " |
375 << rcClient.right - rcClient.left << " " | 360 << rcClient.right - rcClient.left << " " |
376 << rcClient.top - rcClient.bottom << " re W n\n"; | 361 << rcClient.top - rcClient.bottom << " re W n\n"; |
377 | 362 |
378 sAppStream << sText; | 363 sAppStream << sText; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 if (!HasFlag(PES_TEXTOVERFLOW)) { | 445 if (!HasFlag(PES_TEXTOVERFLOW)) { |
461 rcClip = GetClientRect(); | 446 rcClip = GetClientRect(); |
462 pRange = &wrRange; | 447 pRange = &wrRange; |
463 } | 448 } |
464 IFX_SystemHandler* pSysHandler = GetSystemHandler(); | 449 IFX_SystemHandler* pSysHandler = GetSystemHandler(); |
465 IFX_Edit::DrawEdit( | 450 IFX_Edit::DrawEdit( |
466 pDevice, pUser2Device, m_pEdit, | 451 pDevice, pUser2Device, m_pEdit, |
467 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), | 452 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), |
468 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTransparency()), | 453 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTransparency()), |
469 rcClip, CFX_FloatPoint(0.0f, 0.0f), pRange, pSysHandler, m_pFormFiller); | 454 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 } | 455 } |
477 | 456 |
478 FX_BOOL CPWL_Edit::OnLButtonDown(const CFX_FloatPoint& point, uint32_t nFlag) { | 457 FX_BOOL CPWL_Edit::OnLButtonDown(const CFX_FloatPoint& point, uint32_t nFlag) { |
479 CPWL_Wnd::OnLButtonDown(point, nFlag); | 458 CPWL_Wnd::OnLButtonDown(point, nFlag); |
480 | 459 |
481 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { | 460 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { |
482 if (m_bMouseDown) | 461 if (m_bMouseDown) |
483 InvalidateRect(); | 462 InvalidateRect(); |
484 | 463 |
485 m_bMouseDown = TRUE; | 464 m_bMouseDown = TRUE; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 CPVT_WordRange wrLatin = GetLatinWordsRange(point); | 508 CPVT_WordRange wrLatin = GetLatinWordsRange(point); |
530 CFX_WideString swLatin = m_pEdit->GetRangeText(wrLatin); | 509 CFX_WideString swLatin = m_pEdit->GetRangeText(wrLatin); |
531 | 510 |
532 FX_HMENU hPopup = pSH->CreatePopupMenu(); | 511 FX_HMENU hPopup = pSH->CreatePopupMenu(); |
533 if (!hPopup) | 512 if (!hPopup) |
534 return FALSE; | 513 return FALSE; |
535 | 514 |
536 std::vector<CFX_ByteString> sSuggestWords; | 515 std::vector<CFX_ByteString> sSuggestWords; |
537 CFX_FloatPoint ptPopup = point; | 516 CFX_FloatPoint ptPopup = point; |
538 | 517 |
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(); | 518 IPWL_Provider* pProvider = GetProvider(); |
561 | 519 |
562 if (HasFlag(PES_UNDO)) { | 520 if (HasFlag(PES_UNDO)) { |
563 pSH->AppendMenuItem( | 521 pSH->AppendMenuItem( |
564 hPopup, WM_PWLEDIT_UNDO, | 522 hPopup, WM_PWLEDIT_UNDO, |
565 pProvider ? pProvider->LoadPopupMenuString(0) : L"&Undo"); | 523 pProvider ? pProvider->LoadPopupMenuString(0) : L"&Undo"); |
566 pSH->AppendMenuItem( | 524 pSH->AppendMenuItem( |
567 hPopup, WM_PWLEDIT_REDO, | 525 hPopup, WM_PWLEDIT_REDO, |
568 pProvider ? pProvider->LoadPopupMenuString(1) : L"&Redo"); | 526 pProvider ? pProvider->LoadPopupMenuString(1) : L"&Redo"); |
569 pSH->AppendMenuItem(hPopup, 0, L""); | 527 pSH->AppendMenuItem(hPopup, 0, L""); |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
857 } | 815 } |
858 | 816 |
859 FX_BOOL CPWL_Edit::IsVScrollBarVisible() const { | 817 FX_BOOL CPWL_Edit::IsVScrollBarVisible() const { |
860 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { | 818 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { |
861 return pScroll->IsVisible(); | 819 return pScroll->IsVisible(); |
862 } | 820 } |
863 | 821 |
864 return FALSE; | 822 return FALSE; |
865 } | 823 } |
866 | 824 |
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) { | 825 FX_BOOL CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) { |
875 if (m_bMouseDown) | 826 if (m_bMouseDown) |
876 return TRUE; | 827 return TRUE; |
877 | 828 |
878 if (nChar == FWL_VKEY_Delete) { | 829 if (nChar == FWL_VKEY_Delete) { |
879 if (m_pFillerNotify) { | 830 if (m_pFillerNotify) { |
880 FX_BOOL bRC = TRUE; | 831 FX_BOOL bRC = TRUE; |
881 FX_BOOL bExit = FALSE; | 832 FX_BOOL bExit = FALSE; |
882 CFX_WideString strChange; | 833 CFX_WideString strChange; |
883 CFX_WideString strChangeEx; | 834 CFX_WideString strChangeEx; |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1192 } | 1143 } |
1193 | 1144 |
1194 void CPWL_Edit::GeneratePageObjects(CPDF_PageObjectHolder* pObjectHolder, | 1145 void CPWL_Edit::GeneratePageObjects(CPDF_PageObjectHolder* pObjectHolder, |
1195 const CFX_FloatPoint& ptOffset) { | 1146 const CFX_FloatPoint& ptOffset) { |
1196 CFX_ArrayTemplate<CPDF_TextObject*> ObjArray; | 1147 CFX_ArrayTemplate<CPDF_TextObject*> ObjArray; |
1197 IFX_Edit::GeneratePageObjects( | 1148 IFX_Edit::GeneratePageObjects( |
1198 pObjectHolder, m_pEdit, ptOffset, NULL, | 1149 pObjectHolder, m_pEdit, ptOffset, NULL, |
1199 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), | 1150 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), |
1200 ObjArray); | 1151 ObjArray); |
1201 } | 1152 } |
OLD | NEW |