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_scrollbar.h" | 7 #include "xfa/fwl/core/ifwl_scrollbar.h" |
8 | 8 |
9 #include "third_party/base/ptr_util.h" | 9 #include "third_party/base/ptr_util.h" |
10 #include "xfa/fwl/core/cfwl_message.h" | 10 #include "xfa/fwl/core/cfwl_message.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 DrawThumb(pGraphics, pTheme, pMatrix); | 106 DrawThumb(pGraphics, pTheme, pMatrix); |
107 } | 107 } |
108 | 108 |
109 void IFWL_ScrollBar::SetTrackPos(FX_FLOAT fTrackPos) { | 109 void IFWL_ScrollBar::SetTrackPos(FX_FLOAT fTrackPos) { |
110 m_fTrackPos = fTrackPos; | 110 m_fTrackPos = fTrackPos; |
111 CalcThumbButtonRect(m_rtThumb); | 111 CalcThumbButtonRect(m_rtThumb); |
112 CalcMinTrackRect(m_rtMinTrack); | 112 CalcMinTrackRect(m_rtMinTrack); |
113 CalcMaxTrackRect(m_rtMaxTrack); | 113 CalcMaxTrackRect(m_rtMaxTrack); |
114 } | 114 } |
115 | 115 |
116 bool IFWL_ScrollBar::DoScroll(uint32_t dwCode, FX_FLOAT fPos) { | 116 bool IFWL_ScrollBar::DoScroll(FWL_SCBCODE dwCode, FX_FLOAT fPos) { |
117 switch (dwCode) { | 117 if (dwCode == FWL_SCBCODE::None) |
118 case FWL_SCBCODE_Min: | 118 return false; |
119 case FWL_SCBCODE_Max: | |
120 case FWL_SCBCODE_PageBackward: | |
121 case FWL_SCBCODE_PageForward: | |
122 case FWL_SCBCODE_StepBackward: | |
123 case FWL_SCBCODE_StepForward: | |
124 case FWL_SCBCODE_Pos: | |
125 case FWL_SCBCODE_TrackPos: | |
126 case FWL_SCBCODE_EndScroll: | |
127 break; | |
128 default: | |
129 return false; | |
130 } | |
131 return OnScroll(dwCode, fPos); | 119 return OnScroll(dwCode, fPos); |
132 } | 120 } |
133 | 121 |
134 void IFWL_ScrollBar::DrawTrack(CFX_Graphics* pGraphics, | 122 void IFWL_ScrollBar::DrawTrack(CFX_Graphics* pGraphics, |
135 IFWL_ThemeProvider* pTheme, | 123 IFWL_ThemeProvider* pTheme, |
136 bool bLower, | 124 bool bLower, |
137 const CFX_Matrix* pMatrix) { | 125 const CFX_Matrix* pMatrix) { |
138 CFWL_ThemeBackground param; | 126 CFWL_ThemeBackground param; |
139 param.m_pWidget = this; | 127 param.m_pWidget = this; |
140 param.m_iPart = bLower ? CFWL_Part::LowerTrack : CFWL_Part::UpperTrack; | 128 param.m_iPart = bLower ? CFWL_Part::LowerTrack : CFWL_Part::UpperTrack; |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 fMaxTrackWidth = (fMaxTrackWidth >= 0.0f) ? fMaxTrackWidth : 0.0f; | 455 fMaxTrackWidth = (fMaxTrackWidth >= 0.0f) ? fMaxTrackWidth : 0.0f; |
468 rect.Set(m_rtMaxTrack.left + fW, m_rtMaxTrack.top, fMaxTrackWidth, | 456 rect.Set(m_rtMaxTrack.left + fW, m_rtMaxTrack.top, fMaxTrackWidth, |
469 m_rtMaxTrack.height); | 457 m_rtMaxTrack.height); |
470 } | 458 } |
471 } | 459 } |
472 } | 460 } |
473 } | 461 } |
474 | 462 |
475 bool IFWL_ScrollBar::SendEvent() { | 463 bool IFWL_ScrollBar::SendEvent() { |
476 if (m_iMinButtonState == CFWL_PartState_Pressed) { | 464 if (m_iMinButtonState == CFWL_PartState_Pressed) { |
477 DoScroll(FWL_SCBCODE_StepBackward, m_fTrackPos); | 465 DoScroll(FWL_SCBCODE::StepBackward, m_fTrackPos); |
478 return false; | 466 return false; |
479 } | 467 } |
480 if (m_iMaxButtonState == CFWL_PartState_Pressed) { | 468 if (m_iMaxButtonState == CFWL_PartState_Pressed) { |
481 DoScroll(FWL_SCBCODE_StepForward, m_fTrackPos); | 469 DoScroll(FWL_SCBCODE::StepForward, m_fTrackPos); |
482 return false; | 470 return false; |
483 } | 471 } |
484 if (m_iMinTrackState == CFWL_PartState_Pressed) { | 472 if (m_iMinTrackState == CFWL_PartState_Pressed) { |
485 DoScroll(FWL_SCBCODE_PageBackward, m_fTrackPos); | 473 DoScroll(FWL_SCBCODE::PageBackward, m_fTrackPos); |
486 return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); | 474 return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); |
487 } | 475 } |
488 if (m_iMaxTrackState == CFWL_PartState_Pressed) { | 476 if (m_iMaxTrackState == CFWL_PartState_Pressed) { |
489 DoScroll(FWL_SCBCODE_PageForward, m_fTrackPos); | 477 DoScroll(FWL_SCBCODE::PageForward, m_fTrackPos); |
490 return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); | 478 return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); |
491 } | 479 } |
492 if (m_iMouseWheel) { | 480 if (m_iMouseWheel) { |
493 uint16_t dwCode = | 481 FWL_SCBCODE dwCode = m_iMouseWheel < 0 ? FWL_SCBCODE::StepForward |
494 m_iMouseWheel < 0 ? FWL_SCBCODE_StepForward : FWL_SCBCODE_StepBackward; | 482 : FWL_SCBCODE::StepBackward; |
495 DoScroll(dwCode, m_fTrackPos); | 483 DoScroll(dwCode, m_fTrackPos); |
496 } | 484 } |
497 return true; | 485 return true; |
498 } | 486 } |
499 | 487 |
500 bool IFWL_ScrollBar::OnScroll(uint32_t dwCode, FX_FLOAT fPos) { | 488 bool IFWL_ScrollBar::OnScroll(FWL_SCBCODE dwCode, FX_FLOAT fPos) { |
501 bool bRet = true; | 489 bool bRet = true; |
502 CFWL_EvtScroll ev; | 490 CFWL_EvtScroll ev; |
503 ev.m_iScrollCode = dwCode; | 491 ev.m_iScrollCode = dwCode; |
504 ev.m_pSrcTarget = this; | 492 ev.m_pSrcTarget = this; |
505 ev.m_fPos = fPos; | 493 ev.m_fPos = fPos; |
506 ev.m_pRet = &bRet; | 494 ev.m_pRet = &bRet; |
507 DispatchEvent(&ev); | 495 DispatchEvent(&ev); |
508 return bRet; | 496 return bRet; |
509 } | 497 } |
510 | 498 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 int32_t& iState, | 610 int32_t& iState, |
623 FX_FLOAT fx, | 611 FX_FLOAT fx, |
624 FX_FLOAT fy) { | 612 FX_FLOAT fy) { |
625 int32_t iNewState = | 613 int32_t iNewState = |
626 rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered : CFWL_PartState_Normal; | 614 rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered : CFWL_PartState_Normal; |
627 if (iState == iNewState) | 615 if (iState == iNewState) |
628 return; | 616 return; |
629 | 617 |
630 iState = iNewState; | 618 iState = iNewState; |
631 Repaint(&rtItem); | 619 Repaint(&rtItem); |
632 OnScroll(FWL_SCBCODE_EndScroll, m_fTrackPos); | 620 OnScroll(FWL_SCBCODE::EndScroll, m_fTrackPos); |
633 } | 621 } |
634 | 622 |
635 void IFWL_ScrollBar::DoMouseMove(int32_t iItem, | 623 void IFWL_ScrollBar::DoMouseMove(int32_t iItem, |
636 const CFX_RectF& rtItem, | 624 const CFX_RectF& rtItem, |
637 int32_t& iState, | 625 int32_t& iState, |
638 FX_FLOAT fx, | 626 FX_FLOAT fx, |
639 FX_FLOAT fy) { | 627 FX_FLOAT fy) { |
640 if (!m_bMouseDown) { | 628 if (!m_bMouseDown) { |
641 int32_t iNewState = rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered | 629 int32_t iNewState = rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered |
642 : CFWL_PartState_Normal; | 630 : CFWL_PartState_Normal; |
643 if (iState == iNewState) | 631 if (iState == iNewState) |
644 return; | 632 return; |
645 | 633 |
646 iState = iNewState; | 634 iState = iNewState; |
647 Repaint(&rtItem); | 635 Repaint(&rtItem); |
648 } else if ((2 == iItem) && (m_iThumbButtonState == CFWL_PartState_Pressed)) { | 636 } else if ((2 == iItem) && (m_iThumbButtonState == CFWL_PartState_Pressed)) { |
649 FX_FLOAT fPos = GetTrackPointPos(fx, fy); | 637 FX_FLOAT fPos = GetTrackPointPos(fx, fy); |
650 m_fTrackPos = fPos; | 638 m_fTrackPos = fPos; |
651 OnScroll(FWL_SCBCODE_TrackPos, fPos); | 639 OnScroll(FWL_SCBCODE::TrackPos, fPos); |
652 } | 640 } |
653 } | 641 } |
654 | 642 |
655 void IFWL_ScrollBar::DoMouseLeave(int32_t iItem, | 643 void IFWL_ScrollBar::DoMouseLeave(int32_t iItem, |
656 const CFX_RectF& rtItem, | 644 const CFX_RectF& rtItem, |
657 int32_t& iState) { | 645 int32_t& iState) { |
658 if (iState == CFWL_PartState_Normal) | 646 if (iState == CFWL_PartState_Normal) |
659 return; | 647 return; |
660 | 648 |
661 iState = CFWL_PartState_Normal; | 649 iState = CFWL_PartState_Normal; |
(...skipping 14 matching lines...) Expand all Loading... |
676 | 664 |
677 void IFWL_ScrollBar::Timer::Run(IFWL_TimerInfo* pTimerInfo) { | 665 void IFWL_ScrollBar::Timer::Run(IFWL_TimerInfo* pTimerInfo) { |
678 IFWL_ScrollBar* pButton = static_cast<IFWL_ScrollBar*>(m_pWidget); | 666 IFWL_ScrollBar* pButton = static_cast<IFWL_ScrollBar*>(m_pWidget); |
679 | 667 |
680 if (pButton->m_pTimerInfo) | 668 if (pButton->m_pTimerInfo) |
681 pButton->m_pTimerInfo->StopTimer(); | 669 pButton->m_pTimerInfo->StopTimer(); |
682 | 670 |
683 if (!pButton->SendEvent()) | 671 if (!pButton->SendEvent()) |
684 pButton->m_pTimerInfo = StartTimer(0, true); | 672 pButton->m_pTimerInfo = StartTimer(0, true); |
685 } | 673 } |
OLD | NEW |