diff options
-rw-r--r-- | xfa/fwl/core/cfwl_caret.cpp | 14 | ||||
-rw-r--r-- | xfa/fwl/core/cfwl_caret.h | 3 | ||||
-rw-r--r-- | xfa/fwl/core/cfwl_comboedit.cpp | 2 | ||||
-rw-r--r-- | xfa/fwl/core/cfwl_edit.cpp | 91 | ||||
-rw-r--r-- | xfa/fwl/core/cfwl_edit.h | 3 |
5 files changed, 65 insertions, 48 deletions
diff --git a/xfa/fwl/core/cfwl_caret.cpp b/xfa/fwl/core/cfwl_caret.cpp index b4ebf2cec8..b42945c6a8 100644 --- a/xfa/fwl/core/cfwl_caret.cpp +++ b/xfa/fwl/core/cfwl_caret.cpp @@ -55,15 +55,19 @@ void CFWL_Caret::DrawWidget(CFX_Graphics* pGraphics, DrawCaretBK(pGraphics, m_pProperties->m_pThemeProvider, pMatrix); } -void CFWL_Caret::ShowCaret(bool bFlag) { +void CFWL_Caret::ShowCaret() { + if (m_pTimerInfo) + m_pTimerInfo->StopTimer(); + m_pTimerInfo = m_pTimer->StartTimer(kFrequency, true); + SetStates(FWL_WGTSTATE_Invisible, false); +} + +void CFWL_Caret::HideCaret() { if (m_pTimerInfo) { m_pTimerInfo->StopTimer(); m_pTimerInfo = nullptr; } - if (bFlag) - m_pTimerInfo = m_pTimer->StartTimer(kFrequency, true); - - SetStates(FWL_WGTSTATE_Invisible, !bFlag); + SetStates(FWL_WGTSTATE_Invisible, true); } void CFWL_Caret::DrawCaretBK(CFX_Graphics* pGraphics, diff --git a/xfa/fwl/core/cfwl_caret.h b/xfa/fwl/core/cfwl_caret.h index ad38f7a3ed..ada0405748 100644 --- a/xfa/fwl/core/cfwl_caret.h +++ b/xfa/fwl/core/cfwl_caret.h @@ -34,7 +34,8 @@ class CFWL_Caret : public CFWL_Widget { const CFX_Matrix* pMatrix) override; void Update() override; - void ShowCaret(bool bFlag = true); + void ShowCaret(); + void HideCaret(); private: class Timer : public CFWL_Timer { diff --git a/xfa/fwl/core/cfwl_comboedit.cpp b/xfa/fwl/core/cfwl_comboedit.cpp index 32e4cbb2dc..8ee9da6f14 100644 --- a/xfa/fwl/core/cfwl_comboedit.cpp +++ b/xfa/fwl/core/cfwl_comboedit.cpp @@ -39,7 +39,7 @@ void CFWL_ComboEdit::FlagFocus(bool bSet) { } m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; - ShowCaret(false); + HideCaret(nullptr); } void CFWL_ComboEdit::OnProcessMessage(CFWL_Message* pMessage) { diff --git a/xfa/fwl/core/cfwl_edit.cpp b/xfa/fwl/core/cfwl_edit.cpp index 751bf4336a..0844da3713 100644 --- a/xfa/fwl/core/cfwl_edit.cpp +++ b/xfa/fwl/core/cfwl_edit.cpp @@ -81,7 +81,7 @@ CFWL_Edit::CFWL_Edit(const CFWL_App* app, CFWL_Edit::~CFWL_Edit() { if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) - ShowCaret(false); + HideCaret(nullptr); ClearRecord(); } @@ -125,7 +125,7 @@ void CFWL_Edit::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { void CFWL_Edit::SetStates(uint32_t dwStates, bool bSet) { if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) || (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { - ShowCaret(false); + HideCaret(nullptr); } CFWL_Widget::SetStates(dwStates, bSet); } @@ -890,9 +890,10 @@ void CFWL_Edit::UpdateCaret() { rtCaret.width = right - rtCaret.left; } - bool bShow = - m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && !rtCaret.IsEmpty(); - ShowCaret(bShow, &rtCaret); + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && !rtCaret.IsEmpty()) + ShowCaret(&rtCaret); + else + HideCaret(&rtCaret); } CFWL_ScrollBar* CFWL_Edit::UpdateScroll() { @@ -1166,55 +1167,65 @@ void CFWL_Edit::InitScrollBar(bool bVert) { m_pHorzScrollBar.reset(sb); } -bool FWL_ShowCaret(CFWL_Widget* pWidget, - bool bVisible, - const CFX_RectF* pRtAnchor) { +void CFWL_Edit::ShowCaret(CFX_RectF* pRect) { + if (m_pCaret) { + m_pCaret->ShowCaret(); + if (!pRect->IsEmpty()) + m_pCaret->SetWidgetRect(*pRect); + Repaint(&m_rtEngine); + return; + } + + CFWL_Widget* pOuter = this; + pRect->Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top); + while (pOuter->GetOuter()) { + pOuter = pOuter->GetOuter(); + + CFX_RectF rtOuter; + pOuter->GetWidgetRect(rtOuter); + pRect->Offset(rtOuter.left, rtOuter.top); + } + CXFA_FFWidget* pXFAWidget = - static_cast<CXFA_FFWidget*>(pWidget->GetLayoutItem()); + static_cast<CXFA_FFWidget*>(pOuter->GetLayoutItem()); if (!pXFAWidget) - return false; + return; IXFA_DocEnvironment* pDocEnvironment = pXFAWidget->GetDoc()->GetDocEnvironment(); if (!pDocEnvironment) - return false; + return; - if (bVisible) { - CFX_Matrix mt; - pXFAWidget->GetRotateMatrix(mt); - CFX_RectF rt(*pRtAnchor); - mt.TransformRect(rt); - pDocEnvironment->DisplayCaret(pXFAWidget, bVisible, &rt); - return true; - } + CFX_Matrix mt; + pXFAWidget->GetRotateMatrix(mt); - pDocEnvironment->DisplayCaret(pXFAWidget, bVisible, pRtAnchor); - return true; + CFX_RectF rt(*pRect); + mt.TransformRect(rt); + pDocEnvironment->DisplayCaret(pXFAWidget, true, &rt); } -void CFWL_Edit::ShowCaret(bool bVisible, CFX_RectF* pRect) { +void CFWL_Edit::HideCaret(CFX_RectF* pRect) { if (m_pCaret) { - m_pCaret->ShowCaret(bVisible); - if (bVisible && !pRect->IsEmpty()) - m_pCaret->SetWidgetRect(*pRect); + m_pCaret->HideCaret(); Repaint(&m_rtEngine); return; } CFWL_Widget* pOuter = this; - if (bVisible) { - pRect->Offset(m_pProperties->m_rtWidget.left, - m_pProperties->m_rtWidget.top); - } - while (pOuter->GetOuter()) { + while (pOuter->GetOuter()) pOuter = pOuter->GetOuter(); - if (bVisible) { - CFX_RectF rtOuter; - pOuter->GetWidgetRect(rtOuter); - pRect->Offset(rtOuter.left, rtOuter.top); - } - } - FWL_ShowCaret(pOuter, bVisible, pRect); + + CXFA_FFWidget* pXFAWidget = + static_cast<CXFA_FFWidget*>(pOuter->GetLayoutItem()); + if (!pXFAWidget) + return; + + IXFA_DocEnvironment* pDocEnvironment = + pXFAWidget->GetDoc()->GetDocEnvironment(); + if (!pDocEnvironment) + return; + + pDocEnvironment->DisplayCaret(pXFAWidget, false, pRect); } bool CFWL_Edit::ValidateNumberChar(FX_WCHAR cNum) { @@ -1250,8 +1261,8 @@ bool CFWL_Edit::ValidateNumberChar(FX_WCHAR cNum) { void CFWL_Edit::InitCaret() { if (!m_pCaret) { if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret)) { - m_pCaret.reset(new CFWL_Caret( - m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), this)); + m_pCaret = pdfium::MakeUnique<CFWL_Caret>( + m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), this); m_pCaret->SetParent(this); m_pCaret->SetStates(m_pProperties->m_dwStates); } @@ -1371,7 +1382,7 @@ void CFWL_Edit::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { UpdateCaret(); } else if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) { m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; - ShowCaret(false); + HideCaret(nullptr); if ((dwStyleEx & FWL_STYLEEXT_EDT_NoHideSel) == 0) { int32_t nSel = CountSelRanges(); if (nSel > 0) { diff --git a/xfa/fwl/core/cfwl_edit.h b/xfa/fwl/core/cfwl_edit.h index d560bc5d8d..b8b3b143a3 100644 --- a/xfa/fwl/core/cfwl_edit.h +++ b/xfa/fwl/core/cfwl_edit.h @@ -119,7 +119,8 @@ class CFWL_Edit : public CFWL_Widget { void SetScrollOffset(FX_FLOAT fScrollOffset); protected: - void ShowCaret(bool bVisible, CFX_RectF* pRect = nullptr); + void ShowCaret(CFX_RectF* pRect); + void HideCaret(CFX_RectF* pRect); const CFX_RectF& GetRTClient() const { return m_rtClient; } CFDE_TxtEdtEngine* GetTxtEdtEngine() { return &m_EdtEngine; } |