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 "xfa/fwl/core/cfwl_message.h" | 9 #include "xfa/fwl/core/cfwl_message.h" |
10 #include "xfa/fwl/core/cfwl_themebackground.h" | 10 #include "xfa/fwl/core/cfwl_themebackground.h" |
11 #include "xfa/fwl/core/cfwl_themepart.h" | 11 #include "xfa/fwl/core/cfwl_themepart.h" |
12 #include "xfa/fwl/core/fwl_noteimp.h" | 12 #include "xfa/fwl/core/fwl_noteimp.h" |
13 #include "xfa/fwl/core/ifwl_scrollbar.h" | 13 #include "xfa/fwl/core/ifwl_scrollbar.h" |
14 #include "xfa/fwl/core/ifwl_themeprovider.h" | 14 #include "xfa/fwl/core/ifwl_themeprovider.h" |
15 | 15 |
16 #define FWL_SCROLLBAR_Elapse 500 | 16 #define FWL_SCROLLBAR_Elapse 500 |
17 #define FWL_SCROLLBAR_MinThumb 5 | 17 #define FWL_SCROLLBAR_MinThumb 5 |
18 | 18 |
19 IFWL_ScrollBar::IFWL_ScrollBar(const CFWL_WidgetImpProperties& properties, | 19 IFWL_ScrollBar::IFWL_ScrollBar(const IFWL_App* app, |
| 20 const CFWL_WidgetImpProperties& properties, |
20 IFWL_Widget* pOuter) | 21 IFWL_Widget* pOuter) |
21 : IFWL_Widget(properties, pOuter), | 22 : IFWL_Widget(app, properties, pOuter), |
22 m_pTimerInfo(nullptr), | 23 m_pTimerInfo(nullptr), |
23 m_fRangeMin(0), | 24 m_fRangeMin(0), |
24 m_fRangeMax(-1), | 25 m_fRangeMax(-1), |
25 m_fPageSize(0), | 26 m_fPageSize(0), |
26 m_fStepSize(0), | 27 m_fStepSize(0), |
27 m_fPos(0), | 28 m_fPos(0), |
28 m_fTrackPos(0), | 29 m_fTrackPos(0), |
29 m_iMinButtonState(CFWL_PartState_Normal), | 30 m_iMinButtonState(CFWL_PartState_Normal), |
30 m_iMaxButtonState(CFWL_PartState_Normal), | 31 m_iMaxButtonState(CFWL_PartState_Normal), |
31 m_iThumbButtonState(CFWL_PartState_Normal), | 32 m_iThumbButtonState(CFWL_PartState_Normal), |
32 m_iMinTrackState(CFWL_PartState_Normal), | 33 m_iMinTrackState(CFWL_PartState_Normal), |
33 m_iMaxTrackState(CFWL_PartState_Normal), | 34 m_iMaxTrackState(CFWL_PartState_Normal), |
34 m_fLastTrackPos(0), | 35 m_fLastTrackPos(0), |
35 m_cpTrackPointX(0), | 36 m_cpTrackPointX(0), |
36 m_cpTrackPointY(0), | 37 m_cpTrackPointY(0), |
37 m_iMouseWheel(0), | 38 m_iMouseWheel(0), |
38 m_bTrackMouseLeave(FALSE), | 39 m_bTrackMouseLeave(FALSE), |
39 m_bMouseHover(FALSE), | 40 m_bMouseHover(FALSE), |
40 m_bMouseDown(FALSE), | 41 m_bMouseDown(FALSE), |
41 m_bRepaintThumb(FALSE), | 42 m_bRepaintThumb(FALSE), |
42 m_fButtonLen(0), | 43 m_fButtonLen(0), |
43 m_bMinSize(FALSE), | 44 m_bMinSize(FALSE), |
44 m_bCustomLayout(false), | 45 m_bCustomLayout(false), |
45 m_fMinThumb(FWL_SCROLLBAR_MinThumb) { | 46 m_fMinThumb(FWL_SCROLLBAR_MinThumb), |
| 47 m_Timer(this) { |
46 m_rtClient.Reset(); | 48 m_rtClient.Reset(); |
47 m_rtThumb.Reset(); | 49 m_rtThumb.Reset(); |
48 m_rtMinBtn.Reset(); | 50 m_rtMinBtn.Reset(); |
49 m_rtMaxBtn.Reset(); | 51 m_rtMaxBtn.Reset(); |
50 m_rtMinTrack.Reset(); | 52 m_rtMinTrack.Reset(); |
51 m_rtMaxTrack.Reset(); | 53 m_rtMaxTrack.Reset(); |
52 } | 54 } |
53 | 55 |
54 IFWL_ScrollBar::~IFWL_ScrollBar() {} | 56 IFWL_ScrollBar::~IFWL_ScrollBar() {} |
55 | 57 |
56 FWL_Type IFWL_ScrollBar::GetClassID() const { | 58 void IFWL_ScrollBar::Initialize() { |
57 return FWL_Type::ScrollBar; | 59 IFWL_Widget::Initialize(); |
58 } | |
59 | |
60 FWL_Error IFWL_ScrollBar::Initialize() { | |
61 if (IFWL_Widget::Initialize() != FWL_Error::Succeeded) | |
62 return FWL_Error::Indefinite; | |
63 | |
64 m_pDelegate = new CFWL_ScrollBarImpDelegate(this); | 60 m_pDelegate = new CFWL_ScrollBarImpDelegate(this); |
65 return FWL_Error::Succeeded; | |
66 } | 61 } |
67 | 62 |
68 void IFWL_ScrollBar::Finalize() { | 63 void IFWL_ScrollBar::Finalize() { |
69 delete m_pDelegate; | 64 delete m_pDelegate; |
70 m_pDelegate = nullptr; | 65 m_pDelegate = nullptr; |
71 IFWL_Widget::Finalize(); | 66 IFWL_Widget::Finalize(); |
72 } | 67 } |
73 | 68 |
| 69 FWL_Type IFWL_ScrollBar::GetClassID() const { |
| 70 return FWL_Type::ScrollBar; |
| 71 } |
| 72 |
74 FWL_Error IFWL_ScrollBar::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | 73 FWL_Error IFWL_ScrollBar::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { |
75 if (bAutoSize) { | 74 if (bAutoSize) { |
76 rect.Set(0, 0, 0, 0); | 75 rect.Set(0, 0, 0, 0); |
77 FX_FLOAT* pfMinWidth = static_cast<FX_FLOAT*>( | 76 FX_FLOAT* pfMinWidth = static_cast<FX_FLOAT*>( |
78 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 77 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
79 if (!pfMinWidth) | 78 if (!pfMinWidth) |
80 return FWL_Error::Indefinite; | 79 return FWL_Error::Indefinite; |
81 if (IsVertical()) { | 80 if (IsVertical()) { |
82 rect.Set(0, 0, (*pfMinWidth), (*pfMinWidth) * 3); | 81 rect.Set(0, 0, (*pfMinWidth), (*pfMinWidth) * 3); |
83 } else { | 82 } else { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 break; | 188 break; |
190 case FWL_SCBCODE_Pos: | 189 case FWL_SCBCODE_Pos: |
191 case FWL_SCBCODE_TrackPos: | 190 case FWL_SCBCODE_TrackPos: |
192 case FWL_SCBCODE_EndScroll: | 191 case FWL_SCBCODE_EndScroll: |
193 break; | 192 break; |
194 default: { return FALSE; } | 193 default: { return FALSE; } |
195 } | 194 } |
196 return OnScroll(dwCode, fPos); | 195 return OnScroll(dwCode, fPos); |
197 } | 196 } |
198 | 197 |
199 void IFWL_ScrollBar::Run(IFWL_TimerInfo* pTimerInfo) { | |
200 if (m_pTimerInfo) | |
201 m_pTimerInfo->StopTimer(); | |
202 | |
203 if (!SendEvent()) | |
204 m_pTimerInfo = StartTimer(0, true); | |
205 } | |
206 | |
207 FWL_Error IFWL_ScrollBar::SetOuter(IFWL_Widget* pOuter) { | 198 FWL_Error IFWL_ScrollBar::SetOuter(IFWL_Widget* pOuter) { |
208 m_pOuter = pOuter; | 199 m_pOuter = pOuter; |
209 return FWL_Error::Succeeded; | 200 return FWL_Error::Succeeded; |
210 } | 201 } |
211 | 202 |
212 void IFWL_ScrollBar::DrawTrack(CFX_Graphics* pGraphics, | 203 void IFWL_ScrollBar::DrawTrack(CFX_Graphics* pGraphics, |
213 IFWL_ThemeProvider* pTheme, | 204 IFWL_ThemeProvider* pTheme, |
214 FX_BOOL bLower, | 205 FX_BOOL bLower, |
215 const CFX_Matrix* pMatrix) { | 206 const CFX_Matrix* pMatrix) { |
216 CFWL_ThemeBackground param; | 207 CFWL_ThemeBackground param; |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 DoMouseDown(3, m_pOwner->m_rtMinTrack, m_pOwner->m_iMinTrackState, fx, | 644 DoMouseDown(3, m_pOwner->m_rtMinTrack, m_pOwner->m_iMinTrackState, fx, |
654 fy); | 645 fy); |
655 } else { | 646 } else { |
656 DoMouseDown(4, m_pOwner->m_rtMaxTrack, m_pOwner->m_iMaxTrackState, fx, | 647 DoMouseDown(4, m_pOwner->m_rtMaxTrack, m_pOwner->m_iMaxTrackState, fx, |
657 fy); | 648 fy); |
658 } | 649 } |
659 } | 650 } |
660 } | 651 } |
661 } | 652 } |
662 if (!m_pOwner->SendEvent()) | 653 if (!m_pOwner->SendEvent()) |
663 m_pOwner->m_pTimerInfo = m_pOwner->StartTimer(FWL_SCROLLBAR_Elapse, true); | 654 m_pOwner->m_pTimerInfo = |
| 655 m_pOwner->m_Timer.StartTimer(FWL_SCROLLBAR_Elapse, true); |
664 } | 656 } |
665 | 657 |
666 void CFWL_ScrollBarImpDelegate::OnLButtonUp(uint32_t dwFlags, | 658 void CFWL_ScrollBarImpDelegate::OnLButtonUp(uint32_t dwFlags, |
667 FX_FLOAT fx, | 659 FX_FLOAT fx, |
668 FX_FLOAT fy) { | 660 FX_FLOAT fy) { |
669 m_pOwner->m_pTimerInfo->StopTimer(); | 661 m_pOwner->m_pTimerInfo->StopTimer(); |
670 m_pOwner->m_bMouseDown = FALSE; | 662 m_pOwner->m_bMouseDown = FALSE; |
671 DoMouseUp(0, m_pOwner->m_rtMinBtn, m_pOwner->m_iMinButtonState, fx, fy); | 663 DoMouseUp(0, m_pOwner->m_rtMinBtn, m_pOwner->m_iMinButtonState, fx, fy); |
672 DoMouseUp(1, m_pOwner->m_rtThumb, m_pOwner->m_iThumbButtonState, fx, fy); | 664 DoMouseUp(1, m_pOwner->m_rtThumb, m_pOwner->m_iThumbButtonState, fx, fy); |
673 DoMouseUp(2, m_pOwner->m_rtMaxBtn, m_pOwner->m_iMaxButtonState, fx, fy); | 665 DoMouseUp(2, m_pOwner->m_rtMaxBtn, m_pOwner->m_iMaxButtonState, fx, fy); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 | 759 |
768 void CFWL_ScrollBarImpDelegate::DoMouseHover(int32_t iItem, | 760 void CFWL_ScrollBarImpDelegate::DoMouseHover(int32_t iItem, |
769 const CFX_RectF& rtItem, | 761 const CFX_RectF& rtItem, |
770 int32_t& iState) { | 762 int32_t& iState) { |
771 if (iState == CFWL_PartState_Hovered) { | 763 if (iState == CFWL_PartState_Hovered) { |
772 return; | 764 return; |
773 } | 765 } |
774 iState = CFWL_PartState_Hovered; | 766 iState = CFWL_PartState_Hovered; |
775 m_pOwner->Repaint(&rtItem); | 767 m_pOwner->Repaint(&rtItem); |
776 } | 768 } |
| 769 |
| 770 IFWL_ScrollBar::Timer::Timer(IFWL_ScrollBar* pToolTip) : IFWL_Timer(pToolTip) {} |
| 771 |
| 772 void IFWL_ScrollBar::Timer::Run(IFWL_TimerInfo* pTimerInfo) { |
| 773 IFWL_ScrollBar* pButton = static_cast<IFWL_ScrollBar*>(m_pWidget); |
| 774 |
| 775 if (pButton->m_pTimerInfo) |
| 776 pButton->m_pTimerInfo->StopTimer(); |
| 777 |
| 778 if (!pButton->SendEvent()) |
| 779 pButton->m_pTimerInfo = StartTimer(0, true); |
| 780 } |
OLD | NEW |