| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "xfa/fwl/basewidget/fwl_caretimp.h" | |
| 8 | |
| 9 #include "xfa/fwl/basewidget/ifwl_caret.h" | |
| 10 #include "xfa/fwl/core/cfwl_themebackground.h" | |
| 11 #include "xfa/fwl/core/fwl_noteimp.h" | |
| 12 #include "xfa/fwl/core/fwl_widgetimp.h" | |
| 13 #include "xfa/fwl/core/ifwl_themeprovider.h" | |
| 14 | |
| 15 // static | |
| 16 IFWL_Caret* IFWL_Caret::Create(const CFWL_WidgetImpProperties& properties, | |
| 17 IFWL_Widget* pOuter) { | |
| 18 IFWL_Caret* pCaret = new IFWL_Caret; | |
| 19 CFWL_CaretImp* pCaretImpl = new CFWL_CaretImp(properties, pOuter); | |
| 20 pCaret->SetImpl(pCaretImpl); | |
| 21 pCaretImpl->SetInterface(pCaret); | |
| 22 return pCaret; | |
| 23 } | |
| 24 IFWL_Caret::IFWL_Caret() {} | |
| 25 void IFWL_Caret::ShowCaret(FX_BOOL bFlag) { | |
| 26 static_cast<CFWL_CaretImp*>(GetImpl())->ShowCaret(bFlag); | |
| 27 } | |
| 28 FWL_Error IFWL_Caret::GetFrequency(uint32_t& elapse) { | |
| 29 return static_cast<CFWL_CaretImp*>(GetImpl())->GetFrequency(elapse); | |
| 30 } | |
| 31 FWL_Error IFWL_Caret::SetFrequency(uint32_t elapse) { | |
| 32 return static_cast<CFWL_CaretImp*>(GetImpl())->SetFrequency(elapse); | |
| 33 } | |
| 34 FWL_Error IFWL_Caret::SetColor(CFX_Color crFill) { | |
| 35 return static_cast<CFWL_CaretImp*>(GetImpl())->SetColor(crFill); | |
| 36 } | |
| 37 | |
| 38 CFWL_CaretImp::CFWL_CaretImp(const CFWL_WidgetImpProperties& properties, | |
| 39 IFWL_Widget* pOuter) | |
| 40 : CFWL_WidgetImp(properties, pOuter), | |
| 41 m_pTimer(new CFWL_CaretTimer(this)), | |
| 42 m_pTimerInfo(nullptr), | |
| 43 m_dwElapse(400), | |
| 44 m_bSetColor(FALSE) { | |
| 45 SetStates(FWL_STATE_CAT_HightLight); | |
| 46 } | |
| 47 | |
| 48 CFWL_CaretImp::~CFWL_CaretImp() {} | |
| 49 | |
| 50 FWL_Error CFWL_CaretImp::GetClassName(CFX_WideString& wsClass) const { | |
| 51 wsClass = FWL_CLASS_Caret; | |
| 52 return FWL_Error::Succeeded; | |
| 53 } | |
| 54 | |
| 55 FWL_Type CFWL_CaretImp::GetClassID() const { | |
| 56 return FWL_Type::Caret; | |
| 57 } | |
| 58 | |
| 59 FWL_Error CFWL_CaretImp::Initialize() { | |
| 60 if (CFWL_WidgetImp::Initialize() != FWL_Error::Succeeded) | |
| 61 return FWL_Error::Indefinite; | |
| 62 | |
| 63 m_pDelegate = new CFWL_CaretImpDelegate(this); | |
| 64 return FWL_Error::Succeeded; | |
| 65 } | |
| 66 | |
| 67 FWL_Error CFWL_CaretImp::Finalize() { | |
| 68 if (m_pTimerInfo) { | |
| 69 m_pTimerInfo->StopTimer(); | |
| 70 m_pTimerInfo = nullptr; | |
| 71 } | |
| 72 delete m_pDelegate; | |
| 73 m_pDelegate = nullptr; | |
| 74 return CFWL_WidgetImp::Finalize(); | |
| 75 } | |
| 76 FWL_Error CFWL_CaretImp::DrawWidget(CFX_Graphics* pGraphics, | |
| 77 const CFX_Matrix* pMatrix) { | |
| 78 if (!pGraphics) | |
| 79 return FWL_Error::Indefinite; | |
| 80 if (!m_pProperties->m_pThemeProvider) | |
| 81 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
| 82 if (!m_pProperties->m_pThemeProvider) | |
| 83 return FWL_Error::Indefinite; | |
| 84 | |
| 85 DrawCaretBK(pGraphics, m_pProperties->m_pThemeProvider, pMatrix); | |
| 86 return FWL_Error::Succeeded; | |
| 87 } | |
| 88 | |
| 89 void CFWL_CaretImp::ShowCaret(FX_BOOL bFlag) { | |
| 90 if (m_pTimerInfo) { | |
| 91 m_pTimerInfo->StopTimer(); | |
| 92 m_pTimerInfo = nullptr; | |
| 93 } | |
| 94 if (bFlag) | |
| 95 m_pTimerInfo = m_pTimer->StartTimer(m_dwElapse, true); | |
| 96 | |
| 97 SetStates(FWL_WGTSTATE_Invisible, !bFlag); | |
| 98 } | |
| 99 FWL_Error CFWL_CaretImp::GetFrequency(uint32_t& elapse) { | |
| 100 elapse = m_dwElapse; | |
| 101 return FWL_Error::Succeeded; | |
| 102 } | |
| 103 FWL_Error CFWL_CaretImp::SetFrequency(uint32_t elapse) { | |
| 104 m_dwElapse = elapse; | |
| 105 return FWL_Error::Succeeded; | |
| 106 } | |
| 107 FWL_Error CFWL_CaretImp::SetColor(CFX_Color crFill) { | |
| 108 m_bSetColor = TRUE; | |
| 109 m_crFill = crFill; | |
| 110 return FWL_Error::Succeeded; | |
| 111 } | |
| 112 | |
| 113 void CFWL_CaretImp::DrawCaretBK(CFX_Graphics* pGraphics, | |
| 114 IFWL_ThemeProvider* pTheme, | |
| 115 const CFX_Matrix* pMatrix) { | |
| 116 CFX_RectF rect; | |
| 117 GetWidgetRect(rect); | |
| 118 rect.Set(0, 0, rect.width, rect.height); | |
| 119 CFWL_ThemeBackground param; | |
| 120 param.m_pWidget = m_pInterface; | |
| 121 param.m_pGraphics = pGraphics; | |
| 122 param.m_rtPart = rect; | |
| 123 if (m_bSetColor) | |
| 124 param.m_pData = &m_crFill; | |
| 125 if (!(m_pProperties->m_dwStates & FWL_STATE_CAT_HightLight)) | |
| 126 return; | |
| 127 | |
| 128 param.m_iPart = CFWL_Part::Background; | |
| 129 param.m_dwStates = CFWL_PartState_HightLight; | |
| 130 if (pMatrix) | |
| 131 param.m_matrix.Concat(*pMatrix); | |
| 132 | |
| 133 pTheme->DrawBackground(¶m); | |
| 134 } | |
| 135 | |
| 136 CFWL_CaretImp::CFWL_CaretTimer::CFWL_CaretTimer(CFWL_CaretImp* pCaret) | |
| 137 : m_pCaret(pCaret) {} | |
| 138 | |
| 139 void CFWL_CaretImp::CFWL_CaretTimer::Run(IFWL_TimerInfo* pTimerInfo) { | |
| 140 bool toggle = !(m_pCaret->GetStates() & FWL_STATE_CAT_HightLight); | |
| 141 m_pCaret->SetStates(FWL_STATE_CAT_HightLight, toggle); | |
| 142 | |
| 143 CFX_RectF rt; | |
| 144 m_pCaret->GetWidgetRect(rt); | |
| 145 rt.Set(0, 0, rt.width + 1, rt.height); | |
| 146 m_pCaret->Repaint(&rt); | |
| 147 } | |
| 148 | |
| 149 CFWL_CaretImpDelegate::CFWL_CaretImpDelegate(CFWL_CaretImp* pOwner) | |
| 150 : m_pOwner(pOwner) {} | |
| 151 | |
| 152 void CFWL_CaretImpDelegate::OnProcessMessage(CFWL_Message* pMessage) {} | |
| 153 | |
| 154 void CFWL_CaretImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | |
| 155 const CFX_Matrix* pMatrix) { | |
| 156 m_pOwner->DrawWidget(pGraphics, pMatrix); | |
| 157 } | |
| OLD | NEW |