| 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_spinbuttonimp.h" | 7 #include "xfa/fwl/basewidget/fwl_spinbuttonimp.h" |
| 8 | 8 |
| 9 #include "xfa/fwl/basewidget/ifwl_spinbutton.h" | 9 #include "xfa/fwl/basewidget/ifwl_spinbutton.h" |
| 10 #include "xfa/fwl/core/cfwl_message.h" | 10 #include "xfa/fwl/core/cfwl_message.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 const CFWL_WidgetImpProperties& properties, | 29 const CFWL_WidgetImpProperties& properties, |
| 30 IFWL_Widget* pOuter) { | 30 IFWL_Widget* pOuter) { |
| 31 IFWL_SpinButton* pSpinButton = new IFWL_SpinButton; | 31 IFWL_SpinButton* pSpinButton = new IFWL_SpinButton; |
| 32 CFWL_SpinButtonImp* pSpinButtonImpl = | 32 CFWL_SpinButtonImp* pSpinButtonImpl = |
| 33 new CFWL_SpinButtonImp(properties, nullptr); | 33 new CFWL_SpinButtonImp(properties, nullptr); |
| 34 pSpinButton->SetImpl(pSpinButtonImpl); | 34 pSpinButton->SetImpl(pSpinButtonImpl); |
| 35 pSpinButtonImpl->SetInterface(pSpinButton); | 35 pSpinButtonImpl->SetInterface(pSpinButton); |
| 36 return pSpinButton; | 36 return pSpinButton; |
| 37 } | 37 } |
| 38 IFWL_SpinButton::IFWL_SpinButton() {} | 38 IFWL_SpinButton::IFWL_SpinButton() {} |
| 39 FWL_ERR IFWL_SpinButton::EnableButton(FX_BOOL bEnable, FX_BOOL bUp) { | 39 FWL_Error IFWL_SpinButton::EnableButton(FX_BOOL bEnable, FX_BOOL bUp) { |
| 40 return static_cast<CFWL_SpinButtonImp*>(GetImpl()) | 40 return static_cast<CFWL_SpinButtonImp*>(GetImpl()) |
| 41 ->EnableButton(bEnable, bUp); | 41 ->EnableButton(bEnable, bUp); |
| 42 } | 42 } |
| 43 FX_BOOL IFWL_SpinButton::IsButtonEnable(FX_BOOL bUp) { | 43 FX_BOOL IFWL_SpinButton::IsButtonEnable(FX_BOOL bUp) { |
| 44 return static_cast<CFWL_SpinButtonImp*>(GetImpl())->IsButtonEnable(bUp); | 44 return static_cast<CFWL_SpinButtonImp*>(GetImpl())->IsButtonEnable(bUp); |
| 45 } | 45 } |
| 46 | 46 |
| 47 CFWL_SpinButtonImp::CFWL_SpinButtonImp( | 47 CFWL_SpinButtonImp::CFWL_SpinButtonImp( |
| 48 const CFWL_WidgetImpProperties& properties, | 48 const CFWL_WidgetImpProperties& properties, |
| 49 IFWL_Widget* pOuter) | 49 IFWL_Widget* pOuter) |
| 50 : CFWL_WidgetImp(properties, pOuter), | 50 : CFWL_WidgetImp(properties, pOuter), |
| 51 m_dwUpState(CFWL_PartState_Normal), | 51 m_dwUpState(CFWL_PartState_Normal), |
| 52 m_dwDnState(CFWL_PartState_Normal), | 52 m_dwDnState(CFWL_PartState_Normal), |
| 53 m_iButtonIndex(0), | 53 m_iButtonIndex(0), |
| 54 m_bLButtonDwn(FALSE), | 54 m_bLButtonDwn(FALSE), |
| 55 m_hTimer(NULL) { | 55 m_hTimer(NULL) { |
| 56 m_rtClient.Reset(); | 56 m_rtClient.Reset(); |
| 57 m_rtUpButton.Reset(); | 57 m_rtUpButton.Reset(); |
| 58 m_rtDnButton.Reset(); | 58 m_rtDnButton.Reset(); |
| 59 m_pProperties->m_dwStyleExes |= FWL_STYLEEXE_SPB_Vert; | 59 m_pProperties->m_dwStyleExes |= FWL_STYLEEXE_SPB_Vert; |
| 60 } | 60 } |
| 61 CFWL_SpinButtonImp::~CFWL_SpinButtonImp() {} | 61 CFWL_SpinButtonImp::~CFWL_SpinButtonImp() {} |
| 62 FWL_ERR CFWL_SpinButtonImp::GetClassName(CFX_WideString& wsClass) const { | 62 FWL_Error CFWL_SpinButtonImp::GetClassName(CFX_WideString& wsClass) const { |
| 63 wsClass = FWL_CLASS_SpinButton; | 63 wsClass = FWL_CLASS_SpinButton; |
| 64 return FWL_ERR_Succeeded; | 64 return FWL_Error::Succeeded; |
| 65 } | 65 } |
| 66 uint32_t CFWL_SpinButtonImp::GetClassID() const { | 66 uint32_t CFWL_SpinButtonImp::GetClassID() const { |
| 67 return FWL_CLASSHASH_SpinButton; | 67 return FWL_CLASSHASH_SpinButton; |
| 68 } | 68 } |
| 69 FWL_ERR CFWL_SpinButtonImp::Initialize() { | 69 FWL_Error CFWL_SpinButtonImp::Initialize() { |
| 70 if (CFWL_WidgetImp::Initialize() != FWL_ERR_Succeeded) | 70 if (CFWL_WidgetImp::Initialize() != FWL_Error::Succeeded) |
| 71 return FWL_ERR_Indefinite; | 71 return FWL_Error::Indefinite; |
| 72 m_pDelegate = new CFWL_SpinButtonImpDelegate(this); | 72 m_pDelegate = new CFWL_SpinButtonImpDelegate(this); |
| 73 return FWL_ERR_Succeeded; | 73 return FWL_Error::Succeeded; |
| 74 } | 74 } |
| 75 FWL_ERR CFWL_SpinButtonImp::Finalize() { | 75 FWL_Error CFWL_SpinButtonImp::Finalize() { |
| 76 delete m_pDelegate; | 76 delete m_pDelegate; |
| 77 m_pDelegate = nullptr; | 77 m_pDelegate = nullptr; |
| 78 return CFWL_WidgetImp::Finalize(); | 78 return CFWL_WidgetImp::Finalize(); |
| 79 } | 79 } |
| 80 FWL_ERR CFWL_SpinButtonImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | 80 FWL_Error CFWL_SpinButtonImp::GetWidgetRect(CFX_RectF& rect, |
| 81 FX_BOOL bAutoSize) { |
| 81 if (bAutoSize) { | 82 if (bAutoSize) { |
| 82 rect.Set(0, 0, kMinWidth, kMinHeight); | 83 rect.Set(0, 0, kMinWidth, kMinHeight); |
| 83 CFWL_WidgetImp::GetWidgetRect(rect, TRUE); | 84 CFWL_WidgetImp::GetWidgetRect(rect, TRUE); |
| 84 } else { | 85 } else { |
| 85 rect = m_pProperties->m_rtWidget; | 86 rect = m_pProperties->m_rtWidget; |
| 86 } | 87 } |
| 87 return FWL_ERR_Succeeded; | 88 return FWL_Error::Succeeded; |
| 88 } | 89 } |
| 89 FWL_ERR CFWL_SpinButtonImp::Update() { | 90 FWL_Error CFWL_SpinButtonImp::Update() { |
| 90 if (IsLocked()) { | 91 if (IsLocked()) { |
| 91 return FWL_ERR_Indefinite; | 92 return FWL_Error::Indefinite; |
| 92 } | 93 } |
| 93 GetClientRect(m_rtClient); | 94 GetClientRect(m_rtClient); |
| 94 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXE_SPB_Vert) { | 95 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXE_SPB_Vert) { |
| 95 m_rtUpButton.Set(m_rtClient.top, m_rtClient.left, m_rtClient.width, | 96 m_rtUpButton.Set(m_rtClient.top, m_rtClient.left, m_rtClient.width, |
| 96 m_rtClient.height / 2); | 97 m_rtClient.height / 2); |
| 97 m_rtDnButton.Set(m_rtClient.left, m_rtClient.top + m_rtClient.height / 2, | 98 m_rtDnButton.Set(m_rtClient.left, m_rtClient.top + m_rtClient.height / 2, |
| 98 m_rtClient.width, m_rtClient.height / 2); | 99 m_rtClient.width, m_rtClient.height / 2); |
| 99 } else { | 100 } else { |
| 100 m_rtUpButton.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width / 2, | 101 m_rtUpButton.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width / 2, |
| 101 m_rtClient.height); | 102 m_rtClient.height); |
| 102 m_rtDnButton.Set(m_rtClient.left + m_rtClient.width / 2, m_rtClient.top, | 103 m_rtDnButton.Set(m_rtClient.left + m_rtClient.width / 2, m_rtClient.top, |
| 103 m_rtClient.width / 2, m_rtClient.height); | 104 m_rtClient.width / 2, m_rtClient.height); |
| 104 } | 105 } |
| 105 return FWL_ERR_Succeeded; | 106 return FWL_Error::Succeeded; |
| 106 } | 107 } |
| 107 FWL_WidgetHit CFWL_SpinButtonImp::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | 108 FWL_WidgetHit CFWL_SpinButtonImp::HitTest(FX_FLOAT fx, FX_FLOAT fy) { |
| 108 if (m_rtClient.Contains(fx, fy)) | 109 if (m_rtClient.Contains(fx, fy)) |
| 109 return FWL_WidgetHit::Client; | 110 return FWL_WidgetHit::Client; |
| 110 if (HasBorder() && (m_rtClient.Contains(fx, fy))) | 111 if (HasBorder() && (m_rtClient.Contains(fx, fy))) |
| 111 return FWL_WidgetHit::Border; | 112 return FWL_WidgetHit::Border; |
| 112 if (HasEdge()) { | 113 if (HasEdge()) { |
| 113 CFX_RectF rtEdge; | 114 CFX_RectF rtEdge; |
| 114 GetEdgeRect(rtEdge); | 115 GetEdgeRect(rtEdge); |
| 115 if (rtEdge.Contains(fx, fy)) | 116 if (rtEdge.Contains(fx, fy)) |
| 116 return FWL_WidgetHit::Left; | 117 return FWL_WidgetHit::Left; |
| 117 } | 118 } |
| 118 if (m_rtUpButton.Contains(fx, fy)) | 119 if (m_rtUpButton.Contains(fx, fy)) |
| 119 return FWL_WidgetHit::UpButton; | 120 return FWL_WidgetHit::UpButton; |
| 120 if (m_rtDnButton.Contains(fx, fy)) | 121 if (m_rtDnButton.Contains(fx, fy)) |
| 121 return FWL_WidgetHit::DownButton; | 122 return FWL_WidgetHit::DownButton; |
| 122 return FWL_WidgetHit::Unknown; | 123 return FWL_WidgetHit::Unknown; |
| 123 } | 124 } |
| 124 FWL_ERR CFWL_SpinButtonImp::DrawWidget(CFX_Graphics* pGraphics, | 125 FWL_Error CFWL_SpinButtonImp::DrawWidget(CFX_Graphics* pGraphics, |
| 125 const CFX_Matrix* pMatrix) { | 126 const CFX_Matrix* pMatrix) { |
| 126 if (!pGraphics) | 127 if (!pGraphics) |
| 127 return FWL_ERR_Indefinite; | 128 return FWL_Error::Indefinite; |
| 128 CFX_RectF rtClip(m_rtClient); | 129 CFX_RectF rtClip(m_rtClient); |
| 129 if (pMatrix != NULL) { | 130 if (pMatrix != NULL) { |
| 130 pMatrix->TransformRect(rtClip); | 131 pMatrix->TransformRect(rtClip); |
| 131 } | 132 } |
| 132 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); | 133 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); |
| 133 if (HasBorder()) { | 134 if (HasBorder()) { |
| 134 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | 135 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); |
| 135 } | 136 } |
| 136 if (HasEdge()) { | 137 if (HasEdge()) { |
| 137 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | 138 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); |
| 138 } | 139 } |
| 139 DrawUpButton(pGraphics, pTheme, pMatrix); | 140 DrawUpButton(pGraphics, pTheme, pMatrix); |
| 140 DrawDownButton(pGraphics, pTheme, pMatrix); | 141 DrawDownButton(pGraphics, pTheme, pMatrix); |
| 141 return FWL_ERR_Succeeded; | 142 return FWL_Error::Succeeded; |
| 142 } | 143 } |
| 143 int32_t CFWL_SpinButtonImp::Run(FWL_HTIMER hTimer) { | 144 int32_t CFWL_SpinButtonImp::Run(FWL_HTIMER hTimer) { |
| 144 if (m_hTimer) { | 145 if (m_hTimer) { |
| 145 CFWL_EvtSpbClick wmPosChanged; | 146 CFWL_EvtSpbClick wmPosChanged; |
| 146 wmPosChanged.m_pSrcTarget = m_pInterface; | 147 wmPosChanged.m_pSrcTarget = m_pInterface; |
| 147 wmPosChanged.m_bUp = m_iButtonIndex == 0; | 148 wmPosChanged.m_bUp = m_iButtonIndex == 0; |
| 148 DispatchEvent(&wmPosChanged); | 149 DispatchEvent(&wmPosChanged); |
| 149 } | 150 } |
| 150 return 1; | 151 return 1; |
| 151 } | 152 } |
| 152 FWL_ERR CFWL_SpinButtonImp::EnableButton(FX_BOOL bEnable, FX_BOOL bUp) { | 153 FWL_Error CFWL_SpinButtonImp::EnableButton(FX_BOOL bEnable, FX_BOOL bUp) { |
| 153 if (bUp) { | 154 if (bUp) { |
| 154 if (bEnable) { | 155 if (bEnable) { |
| 155 m_dwUpState = CFWL_PartState_Normal; | 156 m_dwUpState = CFWL_PartState_Normal; |
| 156 } else { | 157 } else { |
| 157 m_dwUpState = CFWL_PartState_Disabled; | 158 m_dwUpState = CFWL_PartState_Disabled; |
| 158 } | 159 } |
| 159 } else { | 160 } else { |
| 160 if (bEnable) { | 161 if (bEnable) { |
| 161 m_dwDnState = CFWL_PartState_Normal; | 162 m_dwDnState = CFWL_PartState_Normal; |
| 162 } else { | 163 } else { |
| 163 m_dwDnState = CFWL_PartState_Disabled; | 164 m_dwDnState = CFWL_PartState_Disabled; |
| 164 } | 165 } |
| 165 } | 166 } |
| 166 return FWL_ERR_Succeeded; | 167 return FWL_Error::Succeeded; |
| 167 } | 168 } |
| 168 FX_BOOL CFWL_SpinButtonImp::IsButtonEnable(FX_BOOL bUp) { | 169 FX_BOOL CFWL_SpinButtonImp::IsButtonEnable(FX_BOOL bUp) { |
| 169 if (bUp) { | 170 if (bUp) { |
| 170 return (m_dwUpState != CFWL_PartState_Disabled); | 171 return (m_dwUpState != CFWL_PartState_Disabled); |
| 171 } | 172 } |
| 172 return (m_dwDnState != CFWL_PartState_Disabled); | 173 return (m_dwDnState != CFWL_PartState_Disabled); |
| 173 } | 174 } |
| 174 void CFWL_SpinButtonImp::DrawUpButton(CFX_Graphics* pGraphics, | 175 void CFWL_SpinButtonImp::DrawUpButton(CFX_Graphics* pGraphics, |
| 175 IFWL_ThemeProvider* pTheme, | 176 IFWL_ThemeProvider* pTheme, |
| 176 const CFX_Matrix* pMatrix) { | 177 const CFX_Matrix* pMatrix) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 197 params.m_matrix.Concat(*pMatrix); | 198 params.m_matrix.Concat(*pMatrix); |
| 198 } | 199 } |
| 199 params.m_rtPart = m_rtDnButton; | 200 params.m_rtPart = m_rtDnButton; |
| 200 pTheme->DrawBackground(¶ms); | 201 pTheme->DrawBackground(¶ms); |
| 201 } | 202 } |
| 202 | 203 |
| 203 CFWL_SpinButtonImpDelegate::CFWL_SpinButtonImpDelegate( | 204 CFWL_SpinButtonImpDelegate::CFWL_SpinButtonImpDelegate( |
| 204 CFWL_SpinButtonImp* pOwner) | 205 CFWL_SpinButtonImp* pOwner) |
| 205 : m_pOwner(pOwner) {} | 206 : m_pOwner(pOwner) {} |
| 206 | 207 |
| 207 int32_t CFWL_SpinButtonImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | 208 void CFWL_SpinButtonImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { |
| 208 if (!pMessage) | 209 if (!pMessage) |
| 209 return 0; | 210 return; |
| 210 | 211 |
| 211 int32_t iRet = 1; | |
| 212 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); | 212 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); |
| 213 switch (dwMsgCode) { | 213 switch (dwMsgCode) { |
| 214 case CFWL_MessageType::SetFocus: { | 214 case CFWL_MessageType::SetFocus: { |
| 215 OnFocusChanged(pMessage, TRUE); | 215 OnFocusChanged(pMessage, TRUE); |
| 216 break; | 216 break; |
| 217 } | 217 } |
| 218 case CFWL_MessageType::KillFocus: { | 218 case CFWL_MessageType::KillFocus: { |
| 219 OnFocusChanged(pMessage, FALSE); | 219 OnFocusChanged(pMessage, FALSE); |
| 220 break; | 220 break; |
| 221 } | 221 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 243 } | 243 } |
| 244 break; | 244 break; |
| 245 } | 245 } |
| 246 case CFWL_MessageType::Key: { | 246 case CFWL_MessageType::Key: { |
| 247 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); | 247 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); |
| 248 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) | 248 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) |
| 249 OnKeyDown(pKey); | 249 OnKeyDown(pKey); |
| 250 break; | 250 break; |
| 251 } | 251 } |
| 252 default: { | 252 default: { |
| 253 iRet = 0; | |
| 254 break; | 253 break; |
| 255 } | 254 } |
| 256 } | 255 } |
| 257 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | 256 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); |
| 258 return iRet; | |
| 259 } | 257 } |
| 260 | 258 |
| 261 FWL_ERR CFWL_SpinButtonImpDelegate::OnProcessEvent(CFWL_Event* pEvent) { | 259 void CFWL_SpinButtonImpDelegate::OnProcessEvent(CFWL_Event* pEvent) {} |
| 262 return FWL_ERR_Succeeded; | 260 |
| 261 void CFWL_SpinButtonImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, |
| 262 const CFX_Matrix* pMatrix) { |
| 263 m_pOwner->DrawWidget(pGraphics, pMatrix); |
| 263 } | 264 } |
| 264 FWL_ERR CFWL_SpinButtonImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | 265 |
| 265 const CFX_Matrix* pMatrix) { | |
| 266 return m_pOwner->DrawWidget(pGraphics, pMatrix); | |
| 267 } | |
| 268 void CFWL_SpinButtonImpDelegate::OnFocusChanged(CFWL_Message* pMsg, | 266 void CFWL_SpinButtonImpDelegate::OnFocusChanged(CFWL_Message* pMsg, |
| 269 FX_BOOL bSet) { | 267 FX_BOOL bSet) { |
| 270 if (bSet) { | 268 if (bSet) { |
| 271 m_pOwner->m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); | 269 m_pOwner->m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); |
| 272 } else { | 270 } else { |
| 273 m_pOwner->m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); | 271 m_pOwner->m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); |
| 274 } | 272 } |
| 275 m_pOwner->Repaint(&m_pOwner->m_rtClient); | 273 m_pOwner->Repaint(&m_pOwner->m_rtClient); |
| 276 } | 274 } |
| 277 void CFWL_SpinButtonImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 275 void CFWL_SpinButtonImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 if (!bUpEnable && !bDownEnable) { | 426 if (!bUpEnable && !bDownEnable) { |
| 429 return; | 427 return; |
| 430 } | 428 } |
| 431 CFWL_EvtSpbClick wmPosChanged; | 429 CFWL_EvtSpbClick wmPosChanged; |
| 432 wmPosChanged.m_pSrcTarget = m_pOwner->m_pInterface; | 430 wmPosChanged.m_pSrcTarget = m_pOwner->m_pInterface; |
| 433 wmPosChanged.m_bUp = bUpEnable; | 431 wmPosChanged.m_bUp = bUpEnable; |
| 434 m_pOwner->DispatchEvent(&wmPosChanged); | 432 m_pOwner->DispatchEvent(&wmPosChanged); |
| 435 m_pOwner->Repaint(bUpEnable ? &m_pOwner->m_rtUpButton | 433 m_pOwner->Repaint(bUpEnable ? &m_pOwner->m_rtUpButton |
| 436 : &m_pOwner->m_rtDnButton); | 434 : &m_pOwner->m_rtDnButton); |
| 437 } | 435 } |
| OLD | NEW |