| 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 void IFWL_Caret::ShowCaret(FX_BOOL bFlag) { | 25 void IFWL_Caret::ShowCaret(FX_BOOL bFlag) { |
| 26 static_cast<CFWL_CaretImp*>(GetImpl())->ShowCaret(bFlag); | 26 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 | 86 |
| 86 void CFWL_CaretImp::ShowCaret(FX_BOOL bFlag) { | 87 void CFWL_CaretImp::ShowCaret(FX_BOOL bFlag) { |
| 87 if (m_hTimer) { | 88 if (m_hTimer) { |
| 88 FWL_StopTimer(m_hTimer); | 89 FWL_StopTimer(m_hTimer); |
| 89 m_hTimer = nullptr; | 90 m_hTimer = nullptr; |
| 90 } | 91 } |
| 91 if (bFlag) | 92 if (bFlag) |
| 92 m_hTimer = FWL_StartTimer(m_pTimer, m_dwElapse); | 93 m_hTimer = FWL_StartTimer(m_pTimer, m_dwElapse); |
| 93 | 94 |
| 94 SetStates(FWL_WGTSTATE_Invisible, !bFlag); | 95 SetStates(FWL_WGTSTATE_Invisible, !bFlag); |
| 95 } | 96 } |
| 96 FWL_ERR CFWL_CaretImp::GetFrequency(uint32_t& elapse) { | 97 FWL_Error CFWL_CaretImp::GetFrequency(uint32_t& elapse) { |
| 97 elapse = m_dwElapse; | 98 elapse = m_dwElapse; |
| 98 return FWL_ERR_Succeeded; | 99 return FWL_Error::Succeeded; |
| 99 } | 100 } |
| 100 FWL_ERR CFWL_CaretImp::SetFrequency(uint32_t elapse) { | 101 FWL_Error CFWL_CaretImp::SetFrequency(uint32_t elapse) { |
| 101 m_dwElapse = elapse; | 102 m_dwElapse = elapse; |
| 102 return FWL_ERR_Succeeded; | 103 return FWL_Error::Succeeded; |
| 103 } | 104 } |
| 104 FWL_ERR CFWL_CaretImp::SetColor(CFX_Color crFill) { | 105 FWL_Error CFWL_CaretImp::SetColor(CFX_Color crFill) { |
| 105 m_bSetColor = TRUE; | 106 m_bSetColor = TRUE; |
| 106 m_crFill = crFill; | 107 m_crFill = crFill; |
| 107 return FWL_ERR_Succeeded; | 108 return FWL_Error::Succeeded; |
| 108 } | 109 } |
| 109 FX_BOOL CFWL_CaretImp::DrawCaretBK(CFX_Graphics* pGraphics, | 110 |
| 110 IFWL_ThemeProvider* pTheme, | 111 void CFWL_CaretImp::DrawCaretBK(CFX_Graphics* pGraphics, |
| 111 const CFX_Matrix* pMatrix) { | 112 IFWL_ThemeProvider* pTheme, |
| 113 const CFX_Matrix* pMatrix) { |
| 112 CFX_RectF rect; | 114 CFX_RectF rect; |
| 113 GetWidgetRect(rect); | 115 GetWidgetRect(rect); |
| 114 rect.Set(0, 0, rect.width, rect.height); | 116 rect.Set(0, 0, rect.width, rect.height); |
| 115 CFWL_ThemeBackground param; | 117 CFWL_ThemeBackground param; |
| 116 param.m_pWidget = m_pInterface; | 118 param.m_pWidget = m_pInterface; |
| 117 param.m_pGraphics = pGraphics; | 119 param.m_pGraphics = pGraphics; |
| 118 param.m_rtPart = rect; | 120 param.m_rtPart = rect; |
| 119 if (m_bSetColor) { | 121 if (m_bSetColor) |
| 120 param.m_pData = &m_crFill; | 122 param.m_pData = &m_crFill; |
| 121 } | 123 if (!(m_pProperties->m_dwStates & FWL_STATE_CAT_HightLight)) |
| 122 if (!(m_pProperties->m_dwStates & FWL_STATE_CAT_HightLight)) { | 124 return; |
| 123 return FWL_ERR_Succeeded; | 125 |
| 124 } | |
| 125 param.m_iPart = CFWL_Part::Background; | 126 param.m_iPart = CFWL_Part::Background; |
| 126 param.m_dwStates = CFWL_PartState_HightLight; | 127 param.m_dwStates = CFWL_PartState_HightLight; |
| 127 if (pMatrix) { | 128 if (pMatrix) |
| 128 param.m_matrix.Concat(*pMatrix); | 129 param.m_matrix.Concat(*pMatrix); |
| 129 } | 130 |
| 130 pTheme->DrawBackground(¶m); | 131 pTheme->DrawBackground(¶m); |
| 131 return FWL_ERR_Succeeded; | |
| 132 } | 132 } |
| 133 | 133 |
| 134 CFWL_CaretImp::CFWL_CaretTimer::CFWL_CaretTimer(CFWL_CaretImp* pCaret) | 134 CFWL_CaretImp::CFWL_CaretTimer::CFWL_CaretTimer(CFWL_CaretImp* pCaret) |
| 135 : m_pCaret(pCaret) {} | 135 : m_pCaret(pCaret) {} |
| 136 | 136 |
| 137 int32_t CFWL_CaretImp::CFWL_CaretTimer::Run(FWL_HTIMER hTimer) { | 137 int32_t CFWL_CaretImp::CFWL_CaretTimer::Run(FWL_HTIMER hTimer) { |
| 138 if (m_pCaret->GetStates() & FWL_STATE_CAT_HightLight) { | 138 if (m_pCaret->GetStates() & FWL_STATE_CAT_HightLight) { |
| 139 m_pCaret->SetStates(FWL_STATE_CAT_HightLight, FALSE); | 139 m_pCaret->SetStates(FWL_STATE_CAT_HightLight, FALSE); |
| 140 } else { | 140 } else { |
| 141 m_pCaret->SetStates(FWL_STATE_CAT_HightLight); | 141 m_pCaret->SetStates(FWL_STATE_CAT_HightLight); |
| 142 } | 142 } |
| 143 CFX_RectF rt; | 143 CFX_RectF rt; |
| 144 m_pCaret->GetWidgetRect(rt); | 144 m_pCaret->GetWidgetRect(rt); |
| 145 rt.Set(0, 0, rt.width + 1, rt.height); | 145 rt.Set(0, 0, rt.width + 1, rt.height); |
| 146 m_pCaret->Repaint(&rt); | 146 m_pCaret->Repaint(&rt); |
| 147 return 1; | 147 return 1; |
| 148 } | 148 } |
| 149 |
| 149 CFWL_CaretImpDelegate::CFWL_CaretImpDelegate(CFWL_CaretImp* pOwner) | 150 CFWL_CaretImpDelegate::CFWL_CaretImpDelegate(CFWL_CaretImp* pOwner) |
| 150 : m_pOwner(pOwner) {} | 151 : m_pOwner(pOwner) {} |
| 151 int32_t CFWL_CaretImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | 152 |
| 152 return 1; | 153 void CFWL_CaretImpDelegate::OnProcessMessage(CFWL_Message* pMessage) {} |
| 154 |
| 155 void CFWL_CaretImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, |
| 156 const CFX_Matrix* pMatrix) { |
| 157 m_pOwner->DrawWidget(pGraphics, pMatrix); |
| 153 } | 158 } |
| 154 FWL_ERR CFWL_CaretImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | |
| 155 const CFX_Matrix* pMatrix) { | |
| 156 return m_pOwner->DrawWidget(pGraphics, pMatrix); | |
| 157 } | |
| OLD | NEW |