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