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