| 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_pushbuttonimp.h" | 7 #include "xfa/fwl/basewidget/fwl_pushbuttonimp.h" |
| 8 | 8 |
| 9 #include "xfa/fde/tto/fde_textout.h" | 9 #include "xfa/fde/tto/fde_textout.h" |
| 10 #include "xfa/fwl/basewidget/ifwl_pushbutton.h" | 10 #include "xfa/fwl/basewidget/ifwl_pushbutton.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 const CFWL_WidgetImpProperties& properties, | 32 const CFWL_WidgetImpProperties& properties, |
| 33 IFWL_Widget* pOuter) | 33 IFWL_Widget* pOuter) |
| 34 : CFWL_WidgetImp(properties, pOuter), | 34 : CFWL_WidgetImp(properties, pOuter), |
| 35 m_bBtnDown(FALSE), | 35 m_bBtnDown(FALSE), |
| 36 m_dwTTOStyles(FDE_TTOSTYLE_SingleLine), | 36 m_dwTTOStyles(FDE_TTOSTYLE_SingleLine), |
| 37 m_iTTOAlign(FDE_TTOALIGNMENT_Center) { | 37 m_iTTOAlign(FDE_TTOALIGNMENT_Center) { |
| 38 m_rtClient.Set(0, 0, 0, 0); | 38 m_rtClient.Set(0, 0, 0, 0); |
| 39 m_rtCaption.Set(0, 0, 0, 0); | 39 m_rtCaption.Set(0, 0, 0, 0); |
| 40 } | 40 } |
| 41 CFWL_PushButtonImp::~CFWL_PushButtonImp() {} | 41 CFWL_PushButtonImp::~CFWL_PushButtonImp() {} |
| 42 FWL_ERR CFWL_PushButtonImp::GetClassName(CFX_WideString& wsClass) const { | 42 FWL_Error CFWL_PushButtonImp::GetClassName(CFX_WideString& wsClass) const { |
| 43 wsClass = FWL_CLASS_PushButton; | 43 wsClass = FWL_CLASS_PushButton; |
| 44 return FWL_ERR_Succeeded; | 44 return FWL_Error::Succeeded; |
| 45 } | 45 } |
| 46 uint32_t CFWL_PushButtonImp::GetClassID() const { | 46 uint32_t CFWL_PushButtonImp::GetClassID() const { |
| 47 return FWL_CLASSHASH_PushButton; | 47 return FWL_CLASSHASH_PushButton; |
| 48 } | 48 } |
| 49 FWL_ERR CFWL_PushButtonImp::Initialize() { | 49 FWL_Error CFWL_PushButtonImp::Initialize() { |
| 50 if (CFWL_WidgetImp::Initialize() != FWL_ERR_Succeeded) | 50 if (CFWL_WidgetImp::Initialize() != FWL_Error::Succeeded) |
| 51 return FWL_ERR_Indefinite; | 51 return FWL_Error::Indefinite; |
| 52 m_pDelegate = new CFWL_PushButtonImpDelegate(this); | 52 m_pDelegate = new CFWL_PushButtonImpDelegate(this); |
| 53 return FWL_ERR_Succeeded; | 53 return FWL_Error::Succeeded; |
| 54 } | 54 } |
| 55 FWL_ERR CFWL_PushButtonImp::Finalize() { | 55 FWL_Error CFWL_PushButtonImp::Finalize() { |
| 56 delete m_pDelegate; | 56 delete m_pDelegate; |
| 57 m_pDelegate = nullptr; | 57 m_pDelegate = nullptr; |
| 58 return CFWL_WidgetImp::Finalize(); | 58 return CFWL_WidgetImp::Finalize(); |
| 59 } | 59 } |
| 60 FWL_ERR CFWL_PushButtonImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | 60 FWL_Error CFWL_PushButtonImp::GetWidgetRect(CFX_RectF& rect, |
| 61 FX_BOOL bAutoSize) { |
| 61 if (bAutoSize) { | 62 if (bAutoSize) { |
| 62 rect.Set(0, 0, 0, 0); | 63 rect.Set(0, 0, 0, 0); |
| 63 if (m_pProperties->m_pThemeProvider == NULL) { | 64 if (m_pProperties->m_pThemeProvider == NULL) { |
| 64 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 65 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
| 65 } | 66 } |
| 66 CFX_WideString wsCaption; | 67 CFX_WideString wsCaption; |
| 67 IFWL_PushButtonDP* pData = | 68 IFWL_PushButtonDP* pData = |
| 68 static_cast<IFWL_PushButtonDP*>(m_pProperties->m_pDataProvider); | 69 static_cast<IFWL_PushButtonDP*>(m_pProperties->m_pDataProvider); |
| 69 if (pData) { | 70 if (pData) { |
| 70 pData->GetCaption(m_pInterface, wsCaption); | 71 pData->GetCaption(m_pInterface, wsCaption); |
| 71 } | 72 } |
| 72 int32_t iLen = wsCaption.GetLength(); | 73 int32_t iLen = wsCaption.GetLength(); |
| 73 if (iLen > 0) { | 74 if (iLen > 0) { |
| 74 CFX_SizeF sz = CalcTextSize(wsCaption, m_pProperties->m_pThemeProvider); | 75 CFX_SizeF sz = CalcTextSize(wsCaption, m_pProperties->m_pThemeProvider); |
| 75 rect.Set(0, 0, sz.x, sz.y); | 76 rect.Set(0, 0, sz.x, sz.y); |
| 76 } | 77 } |
| 77 FX_FLOAT* fcaption = | 78 FX_FLOAT* fcaption = |
| 78 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::Margin)); | 79 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::Margin)); |
| 79 rect.Inflate(*fcaption, *fcaption); | 80 rect.Inflate(*fcaption, *fcaption); |
| 80 CFWL_WidgetImp::GetWidgetRect(rect, TRUE); | 81 CFWL_WidgetImp::GetWidgetRect(rect, TRUE); |
| 81 } else { | 82 } else { |
| 82 rect = m_pProperties->m_rtWidget; | 83 rect = m_pProperties->m_rtWidget; |
| 83 } | 84 } |
| 84 return FWL_ERR_Succeeded; | 85 return FWL_Error::Succeeded; |
| 85 } | 86 } |
| 86 | 87 |
| 87 void CFWL_PushButtonImp::SetStates(uint32_t dwStates, FX_BOOL bSet) { | 88 void CFWL_PushButtonImp::SetStates(uint32_t dwStates, FX_BOOL bSet) { |
| 88 if ((dwStates & FWL_WGTSTATE_Disabled) && bSet) { | 89 if ((dwStates & FWL_WGTSTATE_Disabled) && bSet) { |
| 89 m_pProperties->m_dwStates = FWL_WGTSTATE_Disabled; | 90 m_pProperties->m_dwStates = FWL_WGTSTATE_Disabled; |
| 90 return; | 91 return; |
| 91 } | 92 } |
| 92 CFWL_WidgetImp::SetStates(dwStates, bSet); | 93 CFWL_WidgetImp::SetStates(dwStates, bSet); |
| 93 } | 94 } |
| 94 | 95 |
| 95 FWL_ERR CFWL_PushButtonImp::Update() { | 96 FWL_Error CFWL_PushButtonImp::Update() { |
| 96 if (IsLocked()) { | 97 if (IsLocked()) { |
| 97 return FWL_ERR_Indefinite; | 98 return FWL_Error::Indefinite; |
| 98 } | 99 } |
| 99 if (!m_pProperties->m_pThemeProvider) { | 100 if (!m_pProperties->m_pThemeProvider) { |
| 100 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 101 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
| 101 } | 102 } |
| 102 UpdateTextOutStyles(); | 103 UpdateTextOutStyles(); |
| 103 GetClientRect(m_rtClient); | 104 GetClientRect(m_rtClient); |
| 104 m_rtCaption = m_rtClient; | 105 m_rtCaption = m_rtClient; |
| 105 FX_FLOAT* fcaption = | 106 FX_FLOAT* fcaption = |
| 106 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::Margin)); | 107 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::Margin)); |
| 107 m_rtCaption.Inflate(-*fcaption, -*fcaption); | 108 m_rtCaption.Inflate(-*fcaption, -*fcaption); |
| 108 return FWL_ERR_Succeeded; | 109 return FWL_Error::Succeeded; |
| 109 } | 110 } |
| 110 FWL_ERR CFWL_PushButtonImp::DrawWidget(CFX_Graphics* pGraphics, | 111 FWL_Error CFWL_PushButtonImp::DrawWidget(CFX_Graphics* pGraphics, |
| 111 const CFX_Matrix* pMatrix) { | 112 const CFX_Matrix* pMatrix) { |
| 112 if (!pGraphics) | 113 if (!pGraphics) |
| 113 return FWL_ERR_Indefinite; | 114 return FWL_Error::Indefinite; |
| 114 if (!m_pProperties->m_pThemeProvider) | 115 if (!m_pProperties->m_pThemeProvider) |
| 115 return FWL_ERR_Indefinite; | 116 return FWL_Error::Indefinite; |
| 116 IFWL_PushButtonDP* pData = | 117 IFWL_PushButtonDP* pData = |
| 117 static_cast<IFWL_PushButtonDP*>(m_pProperties->m_pDataProvider); | 118 static_cast<IFWL_PushButtonDP*>(m_pProperties->m_pDataProvider); |
| 118 CFX_DIBitmap* pPicture = NULL; | 119 CFX_DIBitmap* pPicture = NULL; |
| 119 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 120 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
| 120 if (HasBorder()) { | 121 if (HasBorder()) { |
| 121 DrawBorder(pGraphics, CFWL_Part::Border, m_pProperties->m_pThemeProvider, | 122 DrawBorder(pGraphics, CFWL_Part::Border, m_pProperties->m_pThemeProvider, |
| 122 pMatrix); | 123 pMatrix); |
| 123 } | 124 } |
| 124 if (HasEdge()) { | 125 if (HasEdge()) { |
| 125 DrawEdge(pGraphics, CFWL_Part::Edge, m_pProperties->m_pThemeProvider, | 126 DrawEdge(pGraphics, CFWL_Part::Edge, m_pProperties->m_pThemeProvider, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 ipicheight -= rtText.height / 2; | 287 ipicheight -= rtText.height / 2; |
| 287 break; | 288 break; |
| 288 } | 289 } |
| 289 pGraphics->DrawImage(pPicture, point, &matrix); | 290 pGraphics->DrawImage(pPicture, point, &matrix); |
| 290 } | 291 } |
| 291 matrix.e += m_rtClient.left + iPicwidth; | 292 matrix.e += m_rtClient.left + iPicwidth; |
| 292 matrix.f += m_rtClient.top + ipicheight; | 293 matrix.f += m_rtClient.top + ipicheight; |
| 293 DrawText(pGraphics, m_pProperties->m_pThemeProvider, &matrix); | 294 DrawText(pGraphics, m_pProperties->m_pThemeProvider, &matrix); |
| 294 break; | 295 break; |
| 295 } | 296 } |
| 296 return FWL_ERR_Succeeded; | 297 return FWL_Error::Succeeded; |
| 297 } | 298 } |
| 298 void CFWL_PushButtonImp::DrawBkground(CFX_Graphics* pGraphics, | 299 void CFWL_PushButtonImp::DrawBkground(CFX_Graphics* pGraphics, |
| 299 IFWL_ThemeProvider* pTheme, | 300 IFWL_ThemeProvider* pTheme, |
| 300 const CFX_Matrix* pMatrix) { | 301 const CFX_Matrix* pMatrix) { |
| 301 CFWL_ThemeBackground param; | 302 CFWL_ThemeBackground param; |
| 302 param.m_pWidget = m_pInterface; | 303 param.m_pWidget = m_pInterface; |
| 303 param.m_iPart = CFWL_Part::Background; | 304 param.m_iPart = CFWL_Part::Background; |
| 304 param.m_dwStates = GetPartStates(); | 305 param.m_dwStates = GetPartStates(); |
| 305 param.m_pGraphics = pGraphics; | 306 param.m_pGraphics = pGraphics; |
| 306 if (pMatrix) { | 307 if (pMatrix) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; | 398 m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; |
| 398 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) { | 399 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) { |
| 399 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; | 400 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; |
| 400 } | 401 } |
| 401 } | 402 } |
| 402 | 403 |
| 403 CFWL_PushButtonImpDelegate::CFWL_PushButtonImpDelegate( | 404 CFWL_PushButtonImpDelegate::CFWL_PushButtonImpDelegate( |
| 404 CFWL_PushButtonImp* pOwner) | 405 CFWL_PushButtonImp* pOwner) |
| 405 : m_pOwner(pOwner) {} | 406 : m_pOwner(pOwner) {} |
| 406 | 407 |
| 407 int32_t CFWL_PushButtonImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | 408 void CFWL_PushButtonImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { |
| 408 if (!pMessage) | 409 if (!pMessage) |
| 409 return 0; | 410 return; |
| 410 if (!m_pOwner->IsEnabled()) | 411 if (!m_pOwner->IsEnabled()) |
| 411 return 1; | 412 return; |
| 412 | 413 |
| 413 int32_t iRet = 1; | |
| 414 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); | 414 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); |
| 415 switch (dwMsgCode) { | 415 switch (dwMsgCode) { |
| 416 case CFWL_MessageType::SetFocus: { | 416 case CFWL_MessageType::SetFocus: { |
| 417 OnFocusChanged(pMessage, TRUE); | 417 OnFocusChanged(pMessage, TRUE); |
| 418 break; | 418 break; |
| 419 } | 419 } |
| 420 case CFWL_MessageType::KillFocus: { | 420 case CFWL_MessageType::KillFocus: { |
| 421 OnFocusChanged(pMessage, FALSE); | 421 OnFocusChanged(pMessage, FALSE); |
| 422 break; | 422 break; |
| 423 } | 423 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 445 } | 445 } |
| 446 break; | 446 break; |
| 447 } | 447 } |
| 448 case CFWL_MessageType::Key: { | 448 case CFWL_MessageType::Key: { |
| 449 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); | 449 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); |
| 450 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) | 450 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) |
| 451 OnKeyDown(pKey); | 451 OnKeyDown(pKey); |
| 452 break; | 452 break; |
| 453 } | 453 } |
| 454 default: { | 454 default: { |
| 455 iRet = 0; | |
| 456 break; | 455 break; |
| 457 } | 456 } |
| 458 } | 457 } |
| 459 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | 458 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); |
| 460 return iRet; | |
| 461 } | 459 } |
| 462 | 460 |
| 463 FWL_ERR CFWL_PushButtonImpDelegate::OnProcessEvent(CFWL_Event* pEvent) { | 461 void CFWL_PushButtonImpDelegate::OnProcessEvent(CFWL_Event* pEvent) {} |
| 464 return FWL_ERR_Succeeded; | 462 |
| 463 void CFWL_PushButtonImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, |
| 464 const CFX_Matrix* pMatrix) { |
| 465 m_pOwner->DrawWidget(pGraphics, pMatrix); |
| 465 } | 466 } |
| 466 FWL_ERR CFWL_PushButtonImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | 467 |
| 467 const CFX_Matrix* pMatrix) { | |
| 468 return m_pOwner->DrawWidget(pGraphics, pMatrix); | |
| 469 } | |
| 470 void CFWL_PushButtonImpDelegate::OnFocusChanged(CFWL_Message* pMsg, | 468 void CFWL_PushButtonImpDelegate::OnFocusChanged(CFWL_Message* pMsg, |
| 471 FX_BOOL bSet) { | 469 FX_BOOL bSet) { |
| 472 if (bSet) { | 470 if (bSet) { |
| 473 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | 471 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; |
| 474 } else { | 472 } else { |
| 475 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | 473 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; |
| 476 } | 474 } |
| 477 m_pOwner->Repaint(&m_pOwner->m_rtClient); | 475 m_pOwner->Repaint(&m_pOwner->m_rtClient); |
| 478 } | 476 } |
| 479 void CFWL_PushButtonImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 477 void CFWL_PushButtonImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 CFWL_EvtClick wmClick; | 549 CFWL_EvtClick wmClick; |
| 552 wmClick.m_pSrcTarget = m_pOwner->m_pInterface; | 550 wmClick.m_pSrcTarget = m_pOwner->m_pInterface; |
| 553 m_pOwner->DispatchEvent(&wmClick); | 551 m_pOwner->DispatchEvent(&wmClick); |
| 554 return; | 552 return; |
| 555 } | 553 } |
| 556 if (pMsg->m_dwKeyCode != FWL_VKEY_Tab) { | 554 if (pMsg->m_dwKeyCode != FWL_VKEY_Tab) { |
| 557 return; | 555 return; |
| 558 } | 556 } |
| 559 m_pOwner->DispatchKeyEvent(pMsg); | 557 m_pOwner->DispatchKeyEvent(pMsg); |
| 560 } | 558 } |
| OLD | NEW |