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 |
11 #include "third_party/base/ptr_util.h" | 11 #include "third_party/base/ptr_util.h" |
12 #include "xfa/fde/tto/fde_textout.h" | 12 #include "xfa/fde/tto/fde_textout.h" |
13 #include "xfa/fwl/core/cfwl_message.h" | 13 #include "xfa/fwl/core/cfwl_message.h" |
14 #include "xfa/fwl/core/cfwl_themebackground.h" | 14 #include "xfa/fwl/core/cfwl_themebackground.h" |
15 #include "xfa/fwl/core/cfwl_themetext.h" | 15 #include "xfa/fwl/core/cfwl_themetext.h" |
16 #include "xfa/fwl/core/cfwl_widgetmgr.h" | 16 #include "xfa/fwl/core/cfwl_widgetmgr.h" |
| 17 #include "xfa/fwl/core/fwl_noteimp.h" |
17 #include "xfa/fwl/core/ifwl_app.h" | 18 #include "xfa/fwl/core/ifwl_app.h" |
18 #include "xfa/fwl/core/fwl_noteimp.h" | |
19 #include "xfa/fwl/core/ifwl_checkbox.h" | 19 #include "xfa/fwl/core/ifwl_checkbox.h" |
20 #include "xfa/fwl/core/ifwl_themeprovider.h" | 20 #include "xfa/fwl/core/ifwl_themeprovider.h" |
21 | 21 |
22 namespace { | 22 namespace { |
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 | |
39 SetDelegate(pdfium::MakeUnique<CFWL_CheckBoxImpDelegate>(this)); | |
40 } | 38 } |
41 | 39 |
42 IFWL_CheckBox::~IFWL_CheckBox() {} | 40 IFWL_CheckBox::~IFWL_CheckBox() {} |
43 | 41 |
44 FWL_Type IFWL_CheckBox::GetClassID() const { | 42 FWL_Type IFWL_CheckBox::GetClassID() const { |
45 return FWL_Type::CheckBox; | 43 return FWL_Type::CheckBox; |
46 } | 44 } |
47 | 45 |
48 FWL_Error IFWL_CheckBox::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | 46 FWL_Error IFWL_CheckBox::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { |
49 if (bAutoSize) { | 47 if (bAutoSize) { |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 } | 383 } |
386 Repaint(&m_rtClient); | 384 Repaint(&m_rtClient); |
387 uint32_t dwLaststate = m_pProperties->m_dwStates; | 385 uint32_t dwLaststate = m_pProperties->m_dwStates; |
388 if (dwFirststate != dwLaststate) { | 386 if (dwFirststate != dwLaststate) { |
389 CFWL_EvtCkbCheckStateChanged wmCheckBoxState; | 387 CFWL_EvtCkbCheckStateChanged wmCheckBoxState; |
390 wmCheckBoxState.m_pSrcTarget = this; | 388 wmCheckBoxState.m_pSrcTarget = this; |
391 DispatchEvent(&wmCheckBoxState); | 389 DispatchEvent(&wmCheckBoxState); |
392 } | 390 } |
393 } | 391 } |
394 | 392 |
395 CFWL_CheckBoxImpDelegate::CFWL_CheckBoxImpDelegate(IFWL_CheckBox* pOwner) | 393 void IFWL_CheckBox::OnProcessMessage(CFWL_Message* pMessage) { |
396 : m_pOwner(pOwner) {} | |
397 | |
398 void CFWL_CheckBoxImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
399 if (!pMessage) | 394 if (!pMessage) |
400 return; | 395 return; |
401 | 396 |
402 switch (pMessage->GetClassID()) { | 397 switch (pMessage->GetClassID()) { |
403 case CFWL_MessageType::Activate: { | 398 case CFWL_MessageType::Activate: |
404 OnActivate(pMessage); | 399 OnActivate(pMessage); |
405 break; | 400 break; |
406 } | 401 case CFWL_MessageType::SetFocus: |
407 case CFWL_MessageType::SetFocus: { | |
408 OnFocusChanged(pMessage, TRUE); | 402 OnFocusChanged(pMessage, TRUE); |
409 break; | 403 break; |
410 } | 404 case CFWL_MessageType::KillFocus: |
411 case CFWL_MessageType::KillFocus: { | |
412 OnFocusChanged(pMessage, FALSE); | 405 OnFocusChanged(pMessage, FALSE); |
413 break; | 406 break; |
414 } | |
415 case CFWL_MessageType::Mouse: { | 407 case CFWL_MessageType::Mouse: { |
416 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 408 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); |
417 switch (pMsg->m_dwCmd) { | 409 switch (pMsg->m_dwCmd) { |
418 case FWL_MouseCommand::LeftButtonDown: { | 410 case FWL_MouseCommand::LeftButtonDown: |
419 OnLButtonDown(pMsg); | 411 OnLButtonDown(pMsg); |
420 break; | 412 break; |
421 } | 413 case FWL_MouseCommand::LeftButtonUp: |
422 case FWL_MouseCommand::LeftButtonUp: { | |
423 OnLButtonUp(pMsg); | 414 OnLButtonUp(pMsg); |
424 break; | 415 break; |
425 } | 416 case FWL_MouseCommand::Move: |
426 case FWL_MouseCommand::Move: { | |
427 OnMouseMove(pMsg); | 417 OnMouseMove(pMsg); |
428 break; | 418 break; |
429 } | 419 case FWL_MouseCommand::Leave: |
430 case FWL_MouseCommand::Leave: { | |
431 OnMouseLeave(pMsg); | 420 OnMouseLeave(pMsg); |
432 break; | 421 break; |
433 } | |
434 default: | 422 default: |
435 break; | 423 break; |
436 } | 424 } |
437 break; | 425 break; |
438 } | 426 } |
439 case CFWL_MessageType::Key: { | 427 case CFWL_MessageType::Key: { |
440 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); | 428 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); |
441 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) | 429 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) |
442 OnKeyDown(pKey); | 430 OnKeyDown(pKey); |
443 break; | 431 break; |
444 } | 432 } |
445 default: { break; } | 433 default: |
| 434 break; |
446 } | 435 } |
447 | 436 |
448 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | 437 IFWL_Widget::OnProcessMessage(pMessage); |
449 } | 438 } |
450 | 439 |
451 void CFWL_CheckBoxImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | 440 void IFWL_CheckBox::OnDrawWidget(CFX_Graphics* pGraphics, |
452 const CFX_Matrix* pMatrix) { | 441 const CFX_Matrix* pMatrix) { |
453 m_pOwner->DrawWidget(pGraphics, pMatrix); | 442 DrawWidget(pGraphics, pMatrix); |
454 } | 443 } |
455 | 444 |
456 void CFWL_CheckBoxImpDelegate::OnActivate(CFWL_Message* pMsg) { | 445 void IFWL_CheckBox::OnActivate(CFWL_Message* pMsg) { |
457 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Deactivated; | 446 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Deactivated; |
458 m_pOwner->Repaint(&(m_pOwner->m_rtClient)); | 447 Repaint(&(m_rtClient)); |
459 } | 448 } |
460 | 449 |
461 void CFWL_CheckBoxImpDelegate::OnFocusChanged(CFWL_Message* pMsg, | 450 void IFWL_CheckBox::OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet) { |
462 FX_BOOL bSet) { | 451 if (bSet) |
463 if (bSet) { | 452 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; |
464 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | 453 else |
465 } else { | 454 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; |
466 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | 455 |
467 } | 456 Repaint(&(m_rtClient)); |
468 m_pOwner->Repaint(&(m_pOwner->m_rtClient)); | |
469 } | 457 } |
470 | 458 |
471 void CFWL_CheckBoxImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 459 void IFWL_CheckBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { |
472 if (m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { | 460 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
473 return; | 461 return; |
474 } | 462 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) |
475 if ((m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { | 463 SetFocus(TRUE); |
476 m_pOwner->SetFocus(TRUE); | 464 |
477 } | 465 m_bBtnDown = TRUE; |
478 m_pOwner->m_bBtnDown = TRUE; | 466 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; |
479 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; | 467 m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; |
480 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; | 468 Repaint(&(m_rtClient)); |
481 m_pOwner->Repaint(&(m_pOwner->m_rtClient)); | |
482 } | 469 } |
483 | 470 |
484 void CFWL_CheckBoxImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) { | 471 void IFWL_CheckBox::OnLButtonUp(CFWL_MsgMouse* pMsg) { |
485 if (!m_pOwner->m_bBtnDown) { | 472 if (!m_bBtnDown) |
486 return; | 473 return; |
487 } | 474 |
488 m_pOwner->m_bBtnDown = FALSE; | 475 m_bBtnDown = FALSE; |
489 if (!m_pOwner->m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | 476 if (!m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) |
490 return; | 477 return; |
491 } | 478 |
492 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; | 479 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; |
493 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; | 480 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; |
494 m_pOwner->NextStates(); | 481 NextStates(); |
495 } | 482 } |
496 | 483 |
497 void CFWL_CheckBoxImpDelegate::OnMouseMove(CFWL_MsgMouse* pMsg) { | 484 void IFWL_CheckBox::OnMouseMove(CFWL_MsgMouse* pMsg) { |
498 if (m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { | 485 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
499 return; | 486 return; |
500 } | 487 |
501 FX_BOOL bRepaint = FALSE; | 488 FX_BOOL bRepaint = FALSE; |
502 if (m_pOwner->m_bBtnDown) { | 489 if (m_bBtnDown) { |
503 if (m_pOwner->m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | 490 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { |
504 if ((m_pOwner->m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) == 0) { | 491 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) == 0) { |
505 bRepaint = TRUE; | 492 bRepaint = TRUE; |
506 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; | 493 m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; |
507 } | 494 } |
508 if ((m_pOwner->m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered)) { | 495 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered)) { |
509 bRepaint = TRUE; | 496 bRepaint = TRUE; |
510 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; | 497 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; |
511 } | 498 } |
512 } else { | 499 } else { |
513 if (m_pOwner->m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) { | 500 if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) { |
514 bRepaint = TRUE; | 501 bRepaint = TRUE; |
515 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; | 502 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; |
516 } | 503 } |
517 if ((m_pOwner->m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) { | 504 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) { |
518 bRepaint = TRUE; | 505 bRepaint = TRUE; |
519 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; | 506 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; |
520 } | 507 } |
521 } | 508 } |
522 } else { | 509 } else { |
523 if (m_pOwner->m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | 510 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { |
524 if ((m_pOwner->m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) { | 511 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) { |
525 bRepaint = TRUE; | 512 bRepaint = TRUE; |
526 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; | 513 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; |
527 } | 514 } |
528 } | 515 } |
529 } | 516 } |
530 if (bRepaint) { | 517 if (bRepaint) { |
531 m_pOwner->Repaint(&(m_pOwner->m_rtBox)); | 518 Repaint(&(m_rtBox)); |
532 } | 519 } |
533 } | 520 } |
534 | 521 |
535 void CFWL_CheckBoxImpDelegate::OnMouseLeave(CFWL_MsgMouse* pMsg) { | 522 void IFWL_CheckBox::OnMouseLeave(CFWL_MsgMouse* pMsg) { |
536 if (m_pOwner->m_bBtnDown) { | 523 if (m_bBtnDown) |
537 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; | 524 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; |
538 } else { | 525 else |
539 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; | 526 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; |
540 } | 527 |
541 m_pOwner->Repaint(&(m_pOwner->m_rtBox)); | 528 Repaint(&(m_rtBox)); |
542 } | 529 } |
543 | 530 |
544 void CFWL_CheckBoxImpDelegate::OnKeyDown(CFWL_MsgKey* pMsg) { | 531 void IFWL_CheckBox::OnKeyDown(CFWL_MsgKey* pMsg) { |
545 if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) { | 532 if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) { |
546 m_pOwner->DispatchKeyEvent(pMsg); | 533 DispatchKeyEvent(pMsg); |
547 return; | 534 return; |
548 } | 535 } |
549 if (pMsg->m_dwKeyCode == FWL_VKEY_Return || | 536 if (pMsg->m_dwKeyCode == FWL_VKEY_Return || |
550 pMsg->m_dwKeyCode == FWL_VKEY_Space) { | 537 pMsg->m_dwKeyCode == FWL_VKEY_Space) { |
551 m_pOwner->NextStates(); | 538 NextStates(); |
552 } | 539 } |
553 } | 540 } |
OLD | NEW |