| 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/core/ifwl_checkbox.h" | 7 #include "xfa/fwl/core/ifwl_checkbox.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 const int kCaptionMargin = 5; | 24 const int kCaptionMargin = 5; |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 IFWL_CheckBox::IFWL_CheckBox(const IFWL_App* app, | 28 IFWL_CheckBox::IFWL_CheckBox(const IFWL_App* app, |
| 29 const CFWL_WidgetImpProperties& properties) | 29 const CFWL_WidgetImpProperties& properties) |
| 30 : IFWL_Widget(app, properties, nullptr), | 30 : IFWL_Widget(app, properties, nullptr), |
| 31 m_dwTTOStyles(FDE_TTOSTYLE_SingleLine), | 31 m_dwTTOStyles(FDE_TTOSTYLE_SingleLine), |
| 32 m_iTTOAlign(FDE_TTOALIGNMENT_Center), | 32 m_iTTOAlign(FDE_TTOALIGNMENT_Center), |
| 33 m_bBtnDown(FALSE) { | 33 m_bBtnDown(false) { |
| 34 m_rtClient.Reset(); | 34 m_rtClient.Reset(); |
| 35 m_rtBox.Reset(); | 35 m_rtBox.Reset(); |
| 36 m_rtCaption.Reset(); | 36 m_rtCaption.Reset(); |
| 37 m_rtFocus.Reset(); | 37 m_rtFocus.Reset(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 IFWL_CheckBox::~IFWL_CheckBox() {} | 40 IFWL_CheckBox::~IFWL_CheckBox() {} |
| 41 | 41 |
| 42 FWL_Type IFWL_CheckBox::GetClassID() const { | 42 FWL_Type IFWL_CheckBox::GetClassID() const { |
| 43 return FWL_Type::CheckBox; | 43 return FWL_Type::CheckBox; |
| 44 } | 44 } |
| 45 | 45 |
| 46 FWL_Error IFWL_CheckBox::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | 46 FWL_Error IFWL_CheckBox::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { |
| 47 if (bAutoSize) { | 47 if (bAutoSize) { |
| 48 rect.Set(0, 0, 0, 0); | 48 rect.Set(0, 0, 0, 0); |
| 49 if (!m_pProperties->m_pThemeProvider) | 49 if (!m_pProperties->m_pThemeProvider) |
| 50 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 50 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
| 51 if (!m_pProperties->m_pThemeProvider) | 51 if (!m_pProperties->m_pThemeProvider) |
| 52 return FWL_Error::Indefinite; | 52 return FWL_Error::Indefinite; |
| 53 if (!m_pProperties->m_pDataProvider) | 53 if (!m_pProperties->m_pDataProvider) |
| 54 return FWL_Error::Indefinite; | 54 return FWL_Error::Indefinite; |
| 55 CFX_WideString wsCaption; | 55 CFX_WideString wsCaption; |
| 56 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); | 56 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); |
| 57 if (wsCaption.GetLength() > 0) { | 57 if (wsCaption.GetLength() > 0) { |
| 58 CFX_SizeF sz = CalcTextSize( | 58 CFX_SizeF sz = CalcTextSize( |
| 59 wsCaption, m_pProperties->m_pThemeProvider, | 59 wsCaption, m_pProperties->m_pThemeProvider, |
| 60 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine)); | 60 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine)); |
| 61 rect.Set(0, 0, sz.x, sz.y); | 61 rect.Set(0, 0, sz.x, sz.y); |
| 62 } | 62 } |
| 63 rect.Inflate(kCaptionMargin, kCaptionMargin); | 63 rect.Inflate(kCaptionMargin, kCaptionMargin); |
| 64 IFWL_CheckBoxDP* pData = | 64 IFWL_CheckBoxDP* pData = |
| 65 static_cast<IFWL_CheckBoxDP*>(m_pProperties->m_pDataProvider); | 65 static_cast<IFWL_CheckBoxDP*>(m_pProperties->m_pDataProvider); |
| 66 FX_FLOAT fCheckBox = pData->GetBoxSize(this); | 66 FX_FLOAT fCheckBox = pData->GetBoxSize(this); |
| 67 rect.width += fCheckBox; | 67 rect.width += fCheckBox; |
| 68 if (rect.height < fCheckBox) { | 68 if (rect.height < fCheckBox) { |
| 69 rect.height = fCheckBox; | 69 rect.height = fCheckBox; |
| 70 } | 70 } |
| 71 IFWL_Widget::GetWidgetRect(rect, TRUE); | 71 IFWL_Widget::GetWidgetRect(rect, true); |
| 72 } else { | 72 } else { |
| 73 rect = m_pProperties->m_rtWidget; | 73 rect = m_pProperties->m_rtWidget; |
| 74 } | 74 } |
| 75 return FWL_Error::Succeeded; | 75 return FWL_Error::Succeeded; |
| 76 } | 76 } |
| 77 | 77 |
| 78 FWL_Error IFWL_CheckBox::Update() { | 78 FWL_Error IFWL_CheckBox::Update() { |
| 79 if (IsLocked()) { | 79 if (IsLocked()) { |
| 80 return FWL_Error::Indefinite; | 80 return FWL_Error::Indefinite; |
| 81 } | 81 } |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 | 392 |
| 393 void IFWL_CheckBox::OnProcessMessage(CFWL_Message* pMessage) { | 393 void IFWL_CheckBox::OnProcessMessage(CFWL_Message* pMessage) { |
| 394 if (!pMessage) | 394 if (!pMessage) |
| 395 return; | 395 return; |
| 396 | 396 |
| 397 switch (pMessage->GetClassID()) { | 397 switch (pMessage->GetClassID()) { |
| 398 case CFWL_MessageType::Activate: | 398 case CFWL_MessageType::Activate: |
| 399 OnActivate(pMessage); | 399 OnActivate(pMessage); |
| 400 break; | 400 break; |
| 401 case CFWL_MessageType::SetFocus: | 401 case CFWL_MessageType::SetFocus: |
| 402 OnFocusChanged(pMessage, TRUE); | 402 OnFocusChanged(pMessage, true); |
| 403 break; | 403 break; |
| 404 case CFWL_MessageType::KillFocus: | 404 case CFWL_MessageType::KillFocus: |
| 405 OnFocusChanged(pMessage, FALSE); | 405 OnFocusChanged(pMessage, false); |
| 406 break; | 406 break; |
| 407 case CFWL_MessageType::Mouse: { | 407 case CFWL_MessageType::Mouse: { |
| 408 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 408 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); |
| 409 switch (pMsg->m_dwCmd) { | 409 switch (pMsg->m_dwCmd) { |
| 410 case FWL_MouseCommand::LeftButtonDown: | 410 case FWL_MouseCommand::LeftButtonDown: |
| 411 OnLButtonDown(pMsg); | 411 OnLButtonDown(pMsg); |
| 412 break; | 412 break; |
| 413 case FWL_MouseCommand::LeftButtonUp: | 413 case FWL_MouseCommand::LeftButtonUp: |
| 414 OnLButtonUp(pMsg); | 414 OnLButtonUp(pMsg); |
| 415 break; | 415 break; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 440 void IFWL_CheckBox::OnDrawWidget(CFX_Graphics* pGraphics, | 440 void IFWL_CheckBox::OnDrawWidget(CFX_Graphics* pGraphics, |
| 441 const CFX_Matrix* pMatrix) { | 441 const CFX_Matrix* pMatrix) { |
| 442 DrawWidget(pGraphics, pMatrix); | 442 DrawWidget(pGraphics, pMatrix); |
| 443 } | 443 } |
| 444 | 444 |
| 445 void IFWL_CheckBox::OnActivate(CFWL_Message* pMsg) { | 445 void IFWL_CheckBox::OnActivate(CFWL_Message* pMsg) { |
| 446 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Deactivated; | 446 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Deactivated; |
| 447 Repaint(&(m_rtClient)); | 447 Repaint(&(m_rtClient)); |
| 448 } | 448 } |
| 449 | 449 |
| 450 void IFWL_CheckBox::OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet) { | 450 void IFWL_CheckBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { |
| 451 if (bSet) | 451 if (bSet) |
| 452 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | 452 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; |
| 453 else | 453 else |
| 454 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | 454 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; |
| 455 | 455 |
| 456 Repaint(&(m_rtClient)); | 456 Repaint(&(m_rtClient)); |
| 457 } | 457 } |
| 458 | 458 |
| 459 void IFWL_CheckBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 459 void IFWL_CheckBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { |
| 460 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | 460 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
| 461 return; | 461 return; |
| 462 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) | 462 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) |
| 463 SetFocus(TRUE); | 463 SetFocus(true); |
| 464 | 464 |
| 465 m_bBtnDown = TRUE; | 465 m_bBtnDown = true; |
| 466 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; | 466 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; |
| 467 m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; | 467 m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; |
| 468 Repaint(&(m_rtClient)); | 468 Repaint(&(m_rtClient)); |
| 469 } | 469 } |
| 470 | 470 |
| 471 void IFWL_CheckBox::OnLButtonUp(CFWL_MsgMouse* pMsg) { | 471 void IFWL_CheckBox::OnLButtonUp(CFWL_MsgMouse* pMsg) { |
| 472 if (!m_bBtnDown) | 472 if (!m_bBtnDown) |
| 473 return; | 473 return; |
| 474 | 474 |
| 475 m_bBtnDown = FALSE; | 475 m_bBtnDown = false; |
| 476 if (!m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) | 476 if (!m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) |
| 477 return; | 477 return; |
| 478 | 478 |
| 479 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; | 479 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; |
| 480 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; | 480 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; |
| 481 NextStates(); | 481 NextStates(); |
| 482 } | 482 } |
| 483 | 483 |
| 484 void IFWL_CheckBox::OnMouseMove(CFWL_MsgMouse* pMsg) { | 484 void IFWL_CheckBox::OnMouseMove(CFWL_MsgMouse* pMsg) { |
| 485 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | 485 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
| 486 return; | 486 return; |
| 487 | 487 |
| 488 FX_BOOL bRepaint = FALSE; | 488 bool bRepaint = false; |
| 489 if (m_bBtnDown) { | 489 if (m_bBtnDown) { |
| 490 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | 490 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 491 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) == 0) { | 491 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) == 0) { |
| 492 bRepaint = TRUE; | 492 bRepaint = true; |
| 493 m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; | 493 m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; |
| 494 } | 494 } |
| 495 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered)) { | 495 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered)) { |
| 496 bRepaint = TRUE; | 496 bRepaint = true; |
| 497 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; | 497 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; |
| 498 } | 498 } |
| 499 } else { | 499 } else { |
| 500 if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) { | 500 if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) { |
| 501 bRepaint = TRUE; | 501 bRepaint = true; |
| 502 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; | 502 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; |
| 503 } | 503 } |
| 504 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) { | 504 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) { |
| 505 bRepaint = TRUE; | 505 bRepaint = true; |
| 506 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; | 506 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; |
| 507 } | 507 } |
| 508 } | 508 } |
| 509 } else { | 509 } else { |
| 510 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | 510 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 511 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) { | 511 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) { |
| 512 bRepaint = TRUE; | 512 bRepaint = true; |
| 513 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; | 513 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; |
| 514 } | 514 } |
| 515 } | 515 } |
| 516 } | 516 } |
| 517 if (bRepaint) { | 517 if (bRepaint) { |
| 518 Repaint(&(m_rtBox)); | 518 Repaint(&(m_rtBox)); |
| 519 } | 519 } |
| 520 } | 520 } |
| 521 | 521 |
| 522 void IFWL_CheckBox::OnMouseLeave(CFWL_MsgMouse* pMsg) { | 522 void IFWL_CheckBox::OnMouseLeave(CFWL_MsgMouse* pMsg) { |
| 523 if (m_bBtnDown) | 523 if (m_bBtnDown) |
| 524 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; | 524 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; |
| 525 else | 525 else |
| 526 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; | 526 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; |
| 527 | 527 |
| 528 Repaint(&(m_rtBox)); | 528 Repaint(&(m_rtBox)); |
| 529 } | 529 } |
| 530 | 530 |
| 531 void IFWL_CheckBox::OnKeyDown(CFWL_MsgKey* pMsg) { | 531 void IFWL_CheckBox::OnKeyDown(CFWL_MsgKey* pMsg) { |
| 532 if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) { | 532 if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) { |
| 533 DispatchKeyEvent(pMsg); | 533 DispatchKeyEvent(pMsg); |
| 534 return; | 534 return; |
| 535 } | 535 } |
| 536 if (pMsg->m_dwKeyCode == FWL_VKEY_Return || | 536 if (pMsg->m_dwKeyCode == FWL_VKEY_Return || |
| 537 pMsg->m_dwKeyCode == FWL_VKEY_Space) { | 537 pMsg->m_dwKeyCode == FWL_VKEY_Space) { |
| 538 NextStates(); | 538 NextStates(); |
| 539 } | 539 } |
| 540 } | 540 } |
| OLD | NEW |