| 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 FWL_ERR CFWL_PushButtonImp::SetStates(uint32_t dwStates, FX_BOOL bSet) { | 87 FWL_Error CFWL_PushButtonImp::SetStates(uint32_t dwStates, FX_BOOL bSet) { |
| 87 if ((dwStates & FWL_WGTSTATE_Disabled) && bSet) { | 88 if ((dwStates & FWL_WGTSTATE_Disabled) && bSet) { |
| 88 m_pProperties->m_dwStates = FWL_WGTSTATE_Disabled; | 89 m_pProperties->m_dwStates = FWL_WGTSTATE_Disabled; |
| 89 return FWL_ERR_Succeeded; | 90 return FWL_Error::Succeeded; |
| 90 } | 91 } |
| 91 return CFWL_WidgetImp::SetStates(dwStates, bSet); | 92 return CFWL_WidgetImp::SetStates(dwStates, bSet); |
| 92 } | 93 } |
| 93 FWL_ERR CFWL_PushButtonImp::Update() { | 94 FWL_Error CFWL_PushButtonImp::Update() { |
| 94 if (IsLocked()) { | 95 if (IsLocked()) { |
| 95 return FWL_ERR_Indefinite; | 96 return FWL_Error::Indefinite; |
| 96 } | 97 } |
| 97 if (!m_pProperties->m_pThemeProvider) { | 98 if (!m_pProperties->m_pThemeProvider) { |
| 98 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 99 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
| 99 } | 100 } |
| 100 UpdateTextOutStyles(); | 101 UpdateTextOutStyles(); |
| 101 GetClientRect(m_rtClient); | 102 GetClientRect(m_rtClient); |
| 102 m_rtCaption = m_rtClient; | 103 m_rtCaption = m_rtClient; |
| 103 FX_FLOAT* fcaption = | 104 FX_FLOAT* fcaption = |
| 104 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::Margin)); | 105 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::Margin)); |
| 105 m_rtCaption.Inflate(-*fcaption, -*fcaption); | 106 m_rtCaption.Inflate(-*fcaption, -*fcaption); |
| 106 return FWL_ERR_Succeeded; | 107 return FWL_Error::Succeeded; |
| 107 } | 108 } |
| 108 FWL_ERR CFWL_PushButtonImp::DrawWidget(CFX_Graphics* pGraphics, | 109 FWL_Error CFWL_PushButtonImp::DrawWidget(CFX_Graphics* pGraphics, |
| 109 const CFX_Matrix* pMatrix) { | 110 const CFX_Matrix* pMatrix) { |
| 110 if (!pGraphics) | 111 if (!pGraphics) |
| 111 return FWL_ERR_Indefinite; | 112 return FWL_Error::Indefinite; |
| 112 if (!m_pProperties->m_pThemeProvider) | 113 if (!m_pProperties->m_pThemeProvider) |
| 113 return FWL_ERR_Indefinite; | 114 return FWL_Error::Indefinite; |
| 114 IFWL_PushButtonDP* pData = | 115 IFWL_PushButtonDP* pData = |
| 115 static_cast<IFWL_PushButtonDP*>(m_pProperties->m_pDataProvider); | 116 static_cast<IFWL_PushButtonDP*>(m_pProperties->m_pDataProvider); |
| 116 CFX_DIBitmap* pPicture = NULL; | 117 CFX_DIBitmap* pPicture = NULL; |
| 117 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 118 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
| 118 if (HasBorder()) { | 119 if (HasBorder()) { |
| 119 DrawBorder(pGraphics, CFWL_Part::Border, m_pProperties->m_pThemeProvider, | 120 DrawBorder(pGraphics, CFWL_Part::Border, m_pProperties->m_pThemeProvider, |
| 120 pMatrix); | 121 pMatrix); |
| 121 } | 122 } |
| 122 if (HasEdge()) { | 123 if (HasEdge()) { |
| 123 DrawEdge(pGraphics, CFWL_Part::Edge, m_pProperties->m_pThemeProvider, | 124 DrawEdge(pGraphics, CFWL_Part::Edge, m_pProperties->m_pThemeProvider, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 ipicheight -= rtText.height / 2; | 285 ipicheight -= rtText.height / 2; |
| 285 break; | 286 break; |
| 286 } | 287 } |
| 287 pGraphics->DrawImage(pPicture, point, &matrix); | 288 pGraphics->DrawImage(pPicture, point, &matrix); |
| 288 } | 289 } |
| 289 matrix.e += m_rtClient.left + iPicwidth; | 290 matrix.e += m_rtClient.left + iPicwidth; |
| 290 matrix.f += m_rtClient.top + ipicheight; | 291 matrix.f += m_rtClient.top + ipicheight; |
| 291 DrawText(pGraphics, m_pProperties->m_pThemeProvider, &matrix); | 292 DrawText(pGraphics, m_pProperties->m_pThemeProvider, &matrix); |
| 292 break; | 293 break; |
| 293 } | 294 } |
| 294 return FWL_ERR_Succeeded; | 295 return FWL_Error::Succeeded; |
| 295 } | 296 } |
| 296 void CFWL_PushButtonImp::DrawBkground(CFX_Graphics* pGraphics, | 297 void CFWL_PushButtonImp::DrawBkground(CFX_Graphics* pGraphics, |
| 297 IFWL_ThemeProvider* pTheme, | 298 IFWL_ThemeProvider* pTheme, |
| 298 const CFX_Matrix* pMatrix) { | 299 const CFX_Matrix* pMatrix) { |
| 299 CFWL_ThemeBackground param; | 300 CFWL_ThemeBackground param; |
| 300 param.m_pWidget = m_pInterface; | 301 param.m_pWidget = m_pInterface; |
| 301 param.m_iPart = CFWL_Part::Background; | 302 param.m_iPart = CFWL_Part::Background; |
| 302 param.m_dwStates = GetPartStates(); | 303 param.m_dwStates = GetPartStates(); |
| 303 param.m_pGraphics = pGraphics; | 304 param.m_pGraphics = pGraphics; |
| 304 if (pMatrix) { | 305 if (pMatrix) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; | 396 m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; |
| 396 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) { | 397 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) { |
| 397 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; | 398 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; |
| 398 } | 399 } |
| 399 } | 400 } |
| 400 | 401 |
| 401 CFWL_PushButtonImpDelegate::CFWL_PushButtonImpDelegate( | 402 CFWL_PushButtonImpDelegate::CFWL_PushButtonImpDelegate( |
| 402 CFWL_PushButtonImp* pOwner) | 403 CFWL_PushButtonImp* pOwner) |
| 403 : m_pOwner(pOwner) {} | 404 : m_pOwner(pOwner) {} |
| 404 | 405 |
| 405 int32_t CFWL_PushButtonImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | 406 void CFWL_PushButtonImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { |
| 406 if (!pMessage) | 407 if (!pMessage) |
| 407 return 0; | 408 return; |
| 408 if (!m_pOwner->IsEnabled()) | 409 if (!m_pOwner->IsEnabled()) |
| 409 return 1; | 410 return; |
| 410 | 411 |
| 411 int32_t iRet = 1; | |
| 412 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); | 412 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); |
| 413 switch (dwMsgCode) { | 413 switch (dwMsgCode) { |
| 414 case CFWL_MessageType::SetFocus: { | 414 case CFWL_MessageType::SetFocus: { |
| 415 OnFocusChanged(pMessage, TRUE); | 415 OnFocusChanged(pMessage, TRUE); |
| 416 break; | 416 break; |
| 417 } | 417 } |
| 418 case CFWL_MessageType::KillFocus: { | 418 case CFWL_MessageType::KillFocus: { |
| 419 OnFocusChanged(pMessage, FALSE); | 419 OnFocusChanged(pMessage, FALSE); |
| 420 break; | 420 break; |
| 421 } | 421 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 443 } | 443 } |
| 444 break; | 444 break; |
| 445 } | 445 } |
| 446 case CFWL_MessageType::Key: { | 446 case CFWL_MessageType::Key: { |
| 447 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); | 447 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); |
| 448 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) | 448 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) |
| 449 OnKeyDown(pKey); | 449 OnKeyDown(pKey); |
| 450 break; | 450 break; |
| 451 } | 451 } |
| 452 default: { | 452 default: { |
| 453 iRet = 0; | |
| 454 break; | 453 break; |
| 455 } | 454 } |
| 456 } | 455 } |
| 457 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | 456 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); |
| 458 return iRet; | |
| 459 } | 457 } |
| 460 | 458 |
| 461 FWL_ERR CFWL_PushButtonImpDelegate::OnProcessEvent(CFWL_Event* pEvent) { | 459 void CFWL_PushButtonImpDelegate::OnProcessEvent(CFWL_Event* pEvent) {} |
| 462 return FWL_ERR_Succeeded; | 460 |
| 461 void CFWL_PushButtonImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, |
| 462 const CFX_Matrix* pMatrix) { |
| 463 m_pOwner->DrawWidget(pGraphics, pMatrix); |
| 463 } | 464 } |
| 464 FWL_ERR CFWL_PushButtonImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | 465 |
| 465 const CFX_Matrix* pMatrix) { | |
| 466 return m_pOwner->DrawWidget(pGraphics, pMatrix); | |
| 467 } | |
| 468 void CFWL_PushButtonImpDelegate::OnFocusChanged(CFWL_Message* pMsg, | 466 void CFWL_PushButtonImpDelegate::OnFocusChanged(CFWL_Message* pMsg, |
| 469 FX_BOOL bSet) { | 467 FX_BOOL bSet) { |
| 470 if (bSet) { | 468 if (bSet) { |
| 471 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | 469 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; |
| 472 } else { | 470 } else { |
| 473 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | 471 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; |
| 474 } | 472 } |
| 475 m_pOwner->Repaint(&m_pOwner->m_rtClient); | 473 m_pOwner->Repaint(&m_pOwner->m_rtClient); |
| 476 } | 474 } |
| 477 void CFWL_PushButtonImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 475 void CFWL_PushButtonImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 CFWL_EvtClick wmClick; | 547 CFWL_EvtClick wmClick; |
| 550 wmClick.m_pSrcTarget = m_pOwner->m_pInterface; | 548 wmClick.m_pSrcTarget = m_pOwner->m_pInterface; |
| 551 m_pOwner->DispatchEvent(&wmClick); | 549 m_pOwner->DispatchEvent(&wmClick); |
| 552 return; | 550 return; |
| 553 } | 551 } |
| 554 if (pMsg->m_dwKeyCode != FWL_VKEY_Tab) { | 552 if (pMsg->m_dwKeyCode != FWL_VKEY_Tab) { |
| 555 return; | 553 return; |
| 556 } | 554 } |
| 557 m_pOwner->DispatchKeyEvent(pMsg); | 555 m_pOwner->DispatchKeyEvent(pMsg); |
| 558 } | 556 } |
| OLD | NEW |