| 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_EditCtrl.h" | 7 #include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" |
| 8 | 8 |
| 9 #include "core/fpdfdoc/include/cpvt_section.h" | 9 #include "core/fpdfdoc/include/cpvt_section.h" |
| 10 #include "core/fpdfdoc/include/cpvt_word.h" | 10 #include "core/fpdfdoc/include/cpvt_word.h" |
| 11 #include "fpdfsdk/pdfwindow/PWL_Caret.h" | 11 #include "fpdfsdk/pdfwindow/PWL_Caret.h" |
| 12 #include "fpdfsdk/pdfwindow/PWL_FontMap.h" | 12 #include "fpdfsdk/pdfwindow/PWL_FontMap.h" |
| 13 #include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" | 13 #include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" |
| 14 #include "fpdfsdk/pdfwindow/PWL_Utils.h" | 14 #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
| 15 #include "fpdfsdk/pdfwindow/PWL_Wnd.h" | 15 #include "fpdfsdk/pdfwindow/PWL_Wnd.h" |
| 16 #include "public/fpdf_fwlevent.h" | 16 #include "public/fpdf_fwlevent.h" |
| 17 | 17 |
| 18 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) | 18 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) |
| 19 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) | 19 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) |
| 20 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) | 20 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) |
| 21 #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb)) | 21 #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb)) |
| 22 | 22 |
| 23 CPWL_EditCtrl::CPWL_EditCtrl() | 23 CPWL_EditCtrl::CPWL_EditCtrl() |
| 24 : m_pEdit(IFX_Edit::NewEdit()), | 24 : m_pEdit(IFX_Edit::NewEdit()), |
| 25 m_pEditCaret(NULL), | 25 m_pEditCaret(nullptr), |
| 26 m_bMouseDown(FALSE), | 26 m_bMouseDown(FALSE), |
| 27 m_pEditNotify(NULL), | 27 m_pEditNotify(nullptr), |
| 28 m_nCharSet(DEFAULT_CHARSET), | 28 m_nCharSet(DEFAULT_CHARSET), |
| 29 m_nCodePage(0) {} | 29 m_nCodePage(0) {} |
| 30 | 30 |
| 31 CPWL_EditCtrl::~CPWL_EditCtrl() { | 31 CPWL_EditCtrl::~CPWL_EditCtrl() { |
| 32 IFX_Edit::DelEdit(m_pEdit); | 32 IFX_Edit::DelEdit(m_pEdit); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM& cp) { | 35 void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM& cp) { |
| 36 cp.eCursorType = FXCT_VBEAM; | 36 cp.eCursorType = FXCT_VBEAM; |
| 37 } | 37 } |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 nFontIndex = word.nFontIndex; | 443 nFontIndex = word.nFontIndex; |
| 444 } else if (HasFlag(PES_RICH)) { | 444 } else if (HasFlag(PES_RICH)) { |
| 445 if (pIterator->GetSection(section)) { | 445 if (pIterator->GetSection(section)) { |
| 446 nFontIndex = section.WordProps.nFontIndex; | 446 nFontIndex = section.WordProps.nFontIndex; |
| 447 } | 447 } |
| 448 } | 448 } |
| 449 | 449 |
| 450 if (IPVT_FontMap* pFontMap = GetFontMap()) | 450 if (IPVT_FontMap* pFontMap = GetFontMap()) |
| 451 return pFontMap->GetPDFFont(nFontIndex); | 451 return pFontMap->GetPDFFont(nFontIndex); |
| 452 | 452 |
| 453 return NULL; | 453 return nullptr; |
| 454 } | 454 } |
| 455 | 455 |
| 456 FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const { | 456 FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const { |
| 457 FX_FLOAT fFontSize = GetFontSize(); | 457 FX_FLOAT fFontSize = GetFontSize(); |
| 458 | 458 |
| 459 IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); | 459 IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); |
| 460 pIterator->SetAt(m_pEdit->GetCaret()); | 460 pIterator->SetAt(m_pEdit->GetCaret()); |
| 461 CPVT_Word word; | 461 CPVT_Word word; |
| 462 CPVT_Section section; | 462 CPVT_Section section; |
| 463 if (pIterator->GetWord(word)) { | 463 if (pIterator->GetWord(word)) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 | 556 |
| 557 void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible, | 557 void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible, |
| 558 const CFX_FloatPoint& ptHead, | 558 const CFX_FloatPoint& ptHead, |
| 559 const CFX_FloatPoint& ptFoot, | 559 const CFX_FloatPoint& ptFoot, |
| 560 const CPVT_WordPlace& place) { | 560 const CPVT_WordPlace& place) { |
| 561 PWL_CARET_INFO cInfo; | 561 PWL_CARET_INFO cInfo; |
| 562 cInfo.bVisible = bVisible; | 562 cInfo.bVisible = bVisible; |
| 563 cInfo.ptHead = ptHead; | 563 cInfo.ptHead = ptHead; |
| 564 cInfo.ptFoot = ptFoot; | 564 cInfo.ptFoot = ptFoot; |
| 565 | 565 |
| 566 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t)NULL); | 566 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr); |
| 567 } | 567 } |
| 568 | 568 |
| 569 void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps, | 569 void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps, |
| 570 const CPVT_WordProps& wordProps) {} | 570 const CPVT_WordProps& wordProps) {} |
| 571 | 571 |
| 572 void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) { | 572 void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) { |
| 573 if (IsValid()) { | 573 if (IsValid()) { |
| 574 if (m_pEditNotify) { | 574 if (m_pEditNotify) { |
| 575 m_pEditNotify->OnContentChange(rcContent); | 575 m_pEditNotify->OnContentChange(rcContent); |
| 576 } | 576 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 600 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar); | 600 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar); |
| 601 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd)); | 601 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd)); |
| 602 } | 602 } |
| 603 | 603 |
| 604 void CPWL_EditCtrl::SetReadyToInput() { | 604 void CPWL_EditCtrl::SetReadyToInput() { |
| 605 if (m_bMouseDown) { | 605 if (m_bMouseDown) { |
| 606 ReleaseCapture(); | 606 ReleaseCapture(); |
| 607 m_bMouseDown = FALSE; | 607 m_bMouseDown = FALSE; |
| 608 } | 608 } |
| 609 } | 609 } |
| OLD | NEW |