Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 7 | #include "xfa/fwl/cfwl_scrollbar.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 8 | |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 9 | #include <algorithm> |
| 10 | #include <memory> |
| 11 | #include <utility> |
| 12 | |
dsinclair | 6fe8795 | 2016-11-01 18:48:19 -0700 | [diff] [blame] | 13 | #include "third_party/base/ptr_util.h" |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 14 | #include "xfa/fwl/cfwl_messagemouse.h" |
| 15 | #include "xfa/fwl/cfwl_messagemousewheel.h" |
| 16 | #include "xfa/fwl/cfwl_notedriver.h" |
| 17 | #include "xfa/fwl/cfwl_themebackground.h" |
| 18 | #include "xfa/fwl/cfwl_themepart.h" |
| 19 | #include "xfa/fwl/cfwl_timerinfo.h" |
| 20 | #include "xfa/fwl/ifwl_themeprovider.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 21 | |
| 22 | #define FWL_SCROLLBAR_Elapse 500 |
| 23 | #define FWL_SCROLLBAR_MinThumb 5 |
| 24 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 25 | CFWL_ScrollBar::CFWL_ScrollBar( |
dsinclair | 1a7534a | 2016-11-22 15:56:11 -0800 | [diff] [blame] | 26 | const CFWL_App* app, |
dsinclair | a5811f0 | 2016-11-03 12:27:25 -0700 | [diff] [blame] | 27 | std::unique_ptr<CFWL_WidgetProperties> properties, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 28 | CFWL_Widget* pOuter) |
| 29 | : CFWL_Widget(app, std::move(properties), pOuter), |
tsepez | 6f4f233 | 2016-06-06 13:23:55 -0700 | [diff] [blame] | 30 | m_pTimerInfo(nullptr), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 31 | m_fRangeMin(0), |
| 32 | m_fRangeMax(-1), |
| 33 | m_fPageSize(0), |
| 34 | m_fStepSize(0), |
| 35 | m_fPos(0), |
| 36 | m_fTrackPos(0), |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 37 | m_iMinButtonState(CFWL_PartState_Normal), |
| 38 | m_iMaxButtonState(CFWL_PartState_Normal), |
| 39 | m_iThumbButtonState(CFWL_PartState_Normal), |
| 40 | m_iMinTrackState(CFWL_PartState_Normal), |
| 41 | m_iMaxTrackState(CFWL_PartState_Normal), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 42 | m_fLastTrackPos(0), |
| 43 | m_cpTrackPointX(0), |
| 44 | m_cpTrackPointY(0), |
| 45 | m_iMouseWheel(0), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 46 | m_bMouseDown(false), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 47 | m_fButtonLen(0), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 48 | m_bMinSize(false), |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 49 | m_fMinThumb(FWL_SCROLLBAR_MinThumb), |
| 50 | m_Timer(this) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 51 | m_rtClient.Reset(); |
| 52 | m_rtThumb.Reset(); |
| 53 | m_rtMinBtn.Reset(); |
| 54 | m_rtMaxBtn.Reset(); |
| 55 | m_rtMinTrack.Reset(); |
| 56 | m_rtMaxTrack.Reset(); |
| 57 | } |
dsinclair | b4d40ff | 2016-05-05 10:28:02 -0700 | [diff] [blame] | 58 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 59 | CFWL_ScrollBar::~CFWL_ScrollBar() {} |
dsinclair | b4d40ff | 2016-05-05 10:28:02 -0700 | [diff] [blame] | 60 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 61 | FWL_Type CFWL_ScrollBar::GetClassID() const { |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 62 | return FWL_Type::ScrollBar; |
| 63 | } |
| 64 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 65 | void CFWL_ScrollBar::Update() { |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 66 | if (IsLocked()) |
dsinclair | 98329fe | 2016-11-10 09:40:14 -0800 | [diff] [blame] | 67 | return; |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 68 | if (!m_pProperties->m_pThemeProvider) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 69 | m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 70 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 71 | Layout(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 72 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 73 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 74 | void CFWL_ScrollBar::DrawWidget(CFX_Graphics* pGraphics, |
dsinclair | 98329fe | 2016-11-10 09:40:14 -0800 | [diff] [blame] | 75 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 76 | if (!pGraphics) |
dsinclair | 98329fe | 2016-11-10 09:40:14 -0800 | [diff] [blame] | 77 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 78 | if (!m_pProperties->m_pThemeProvider) |
dsinclair | 98329fe | 2016-11-10 09:40:14 -0800 | [diff] [blame] | 79 | return; |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 80 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 81 | IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 82 | if (HasBorder()) |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 83 | DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 84 | DrawTrack(pGraphics, pTheme, true, pMatrix); |
| 85 | DrawTrack(pGraphics, pTheme, false, pMatrix); |
| 86 | DrawArrowBtn(pGraphics, pTheme, true, pMatrix); |
| 87 | DrawArrowBtn(pGraphics, pTheme, false, pMatrix); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 88 | DrawThumb(pGraphics, pTheme, pMatrix); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 89 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 90 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 91 | void CFWL_ScrollBar::SetTrackPos(FX_FLOAT fTrackPos) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 92 | m_fTrackPos = fTrackPos; |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 93 | m_rtThumb = CalcThumbButtonRect(m_rtThumb); |
| 94 | m_rtMinTrack = CalcMinTrackRect(m_rtMinTrack); |
| 95 | m_rtMaxTrack = CalcMaxTrackRect(m_rtMaxTrack); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 96 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 97 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 98 | bool CFWL_ScrollBar::DoScroll(CFWL_EventScroll::Code dwCode, FX_FLOAT fPos) { |
| 99 | if (dwCode == CFWL_EventScroll::Code::None) |
dsinclair | 3e577c2 | 2016-11-10 11:01:16 -0800 | [diff] [blame] | 100 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 101 | return OnScroll(dwCode, fPos); |
| 102 | } |
tsepez | 6f4f233 | 2016-06-06 13:23:55 -0700 | [diff] [blame] | 103 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 104 | void CFWL_ScrollBar::DrawTrack(CFX_Graphics* pGraphics, |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 105 | IFWL_ThemeProvider* pTheme, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 106 | bool bLower, |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 107 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 108 | CFWL_ThemeBackground param; |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 109 | param.m_pWidget = this; |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 110 | param.m_iPart = bLower ? CFWL_Part::LowerTrack : CFWL_Part::UpperTrack; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 111 | param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 112 | ? CFWL_PartState_Disabled |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 113 | : (bLower ? m_iMinTrackState : m_iMaxTrackState); |
| 114 | param.m_pGraphics = pGraphics; |
| 115 | param.m_matrix.Concat(*pMatrix); |
| 116 | param.m_rtPart = bLower ? m_rtMinTrack : m_rtMaxTrack; |
| 117 | pTheme->DrawBackground(¶m); |
| 118 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 119 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 120 | void CFWL_ScrollBar::DrawArrowBtn(CFX_Graphics* pGraphics, |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 121 | IFWL_ThemeProvider* pTheme, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 122 | bool bMinBtn, |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 123 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 124 | CFWL_ThemeBackground param; |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 125 | param.m_pWidget = this; |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 126 | param.m_iPart = bMinBtn ? CFWL_Part::ForeArrow : CFWL_Part::BackArrow; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 127 | param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 128 | ? CFWL_PartState_Disabled |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 129 | : (bMinBtn ? m_iMinButtonState : m_iMaxButtonState); |
| 130 | param.m_pGraphics = pGraphics; |
| 131 | param.m_matrix.Concat(*pMatrix); |
| 132 | param.m_rtPart = bMinBtn ? m_rtMinBtn : m_rtMaxBtn; |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 133 | if (param.m_rtPart.height > 0 && param.m_rtPart.width > 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 134 | pTheme->DrawBackground(¶m); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 135 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 136 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 137 | void CFWL_ScrollBar::DrawThumb(CFX_Graphics* pGraphics, |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 138 | IFWL_ThemeProvider* pTheme, |
| 139 | const CFX_Matrix* pMatrix) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 140 | CFWL_ThemeBackground param; |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 141 | param.m_pWidget = this; |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 142 | param.m_iPart = CFWL_Part::Thumb; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 143 | param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 144 | ? CFWL_PartState_Disabled |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 145 | : m_iThumbButtonState; |
| 146 | param.m_pGraphics = pGraphics; |
| 147 | param.m_matrix.Concat(*pMatrix); |
| 148 | param.m_rtPart = m_rtThumb; |
| 149 | pTheme->DrawBackground(¶m); |
| 150 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 151 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 152 | void CFWL_ScrollBar::Layout() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 153 | IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
| 154 | CFWL_ThemePart part; |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 155 | part.m_pWidget = this; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 156 | m_fMinThumb = *static_cast<FX_FLOAT*>( |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 157 | pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Size)); |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 158 | m_rtClient = GetClientRect(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 159 | CalcButtonLen(); |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 160 | m_rtMinBtn = CalcMinButtonRect(); |
| 161 | m_rtMaxBtn = CalcMaxButtonRect(); |
| 162 | m_rtThumb = CalcThumbButtonRect(m_rtThumb); |
| 163 | m_rtMinTrack = CalcMinTrackRect(m_rtMinTrack); |
| 164 | m_rtMaxTrack = CalcMaxTrackRect(m_rtMaxTrack); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 165 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 166 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 167 | void CFWL_ScrollBar::CalcButtonLen() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 168 | m_fButtonLen = IsVertical() ? m_rtClient.width : m_rtClient.height; |
| 169 | FX_FLOAT fLength = IsVertical() ? m_rtClient.height : m_rtClient.width; |
| 170 | if (fLength < m_fButtonLen * 2) { |
| 171 | m_fButtonLen = fLength / 2; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 172 | m_bMinSize = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 173 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 174 | m_bMinSize = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 175 | } |
| 176 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 177 | |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 178 | CFX_RectF CFWL_ScrollBar::CalcMinButtonRect() { |
| 179 | CFX_RectF rect; |
| 180 | if (IsVertical()) |
| 181 | rect.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width, m_fButtonLen); |
| 182 | else |
| 183 | rect.Set(m_rtClient.left, m_rtClient.top, m_fButtonLen, m_rtClient.height); |
| 184 | return rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 185 | } |
dsinclair | 878dd5b | 2016-10-17 18:14:25 -0700 | [diff] [blame] | 186 | |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 187 | CFX_RectF CFWL_ScrollBar::CalcMaxButtonRect() { |
| 188 | CFX_RectF rect; |
| 189 | if (IsVertical()) { |
| 190 | rect.Set(m_rtClient.left, m_rtClient.bottom() - m_fButtonLen, |
| 191 | m_rtClient.width, m_fButtonLen); |
| 192 | } else { |
| 193 | rect.Set(m_rtClient.right() - m_fButtonLen, m_rtClient.top, m_fButtonLen, |
| 194 | m_rtClient.height); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 195 | } |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 196 | return rect; |
| 197 | } |
| 198 | |
| 199 | CFX_RectF CFWL_ScrollBar::CalcThumbButtonRect(const CFX_RectF& rtThumb) { |
| 200 | CFX_RectF rect; |
| 201 | rect.Reset(); |
| 202 | |
| 203 | if (!IsEnabled()) |
| 204 | return rect; |
| 205 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 206 | if (m_bMinSize) { |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 207 | rect.left = rtThumb.left; |
| 208 | rect.top = rtThumb.top; |
| 209 | return rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 210 | } |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 211 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 212 | FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 213 | if (fRange < 0) { |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 214 | if (IsVertical()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 215 | rect.Set(m_rtClient.left, m_rtMaxBtn.bottom(), m_rtClient.width, 0); |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 216 | else |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 217 | rect.Set(m_rtMaxBtn.right(), m_rtClient.top, 0, m_rtClient.height); |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 218 | return rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 219 | } |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 220 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 221 | CFX_RectF rtClient = m_rtClient; |
| 222 | FX_FLOAT fLength = IsVertical() ? rtClient.height : rtClient.width; |
| 223 | FX_FLOAT fSize = m_fButtonLen; |
dsinclair | 30e5f30 | 2016-11-21 12:18:28 -0800 | [diff] [blame] | 224 | fLength -= fSize * 2.0f; |
| 225 | if (fLength < fSize) |
| 226 | fLength = 0.0f; |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 227 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 228 | FX_FLOAT fThumbSize = fLength * fLength / (fRange + fLength); |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 229 | fThumbSize = std::max(fThumbSize, m_fMinThumb); |
| 230 | |
| 231 | FX_FLOAT fDiff = std::max(fLength - fThumbSize, 0.0f); |
| 232 | FX_FLOAT fTrackPos = |
| 233 | std::max(std::min(m_fTrackPos, m_fRangeMax), m_fRangeMin); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 234 | if (!fRange) |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 235 | return rect; |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 236 | |
dsinclair | 30e5f30 | 2016-11-21 12:18:28 -0800 | [diff] [blame] | 237 | FX_FLOAT iPos = fSize + fDiff * (fTrackPos - m_fRangeMin) / fRange; |
| 238 | rect.left = rtClient.left; |
dsinclair | 30e5f30 | 2016-11-21 12:18:28 -0800 | [diff] [blame] | 239 | rect.top = rtClient.top; |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 240 | if (IsVertical()) { |
dsinclair | 30e5f30 | 2016-11-21 12:18:28 -0800 | [diff] [blame] | 241 | rect.top += iPos; |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 242 | rect.width = rtClient.width; |
| 243 | rect.height = fThumbSize; |
| 244 | } else { |
| 245 | rect.left += iPos; |
| 246 | rect.width = fThumbSize; |
| 247 | rect.height = rtClient.height; |
| 248 | } |
| 249 | return rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 250 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 251 | |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 252 | CFX_RectF CFWL_ScrollBar::CalcMinTrackRect(const CFX_RectF& rtMinRect) { |
| 253 | CFX_RectF rect; |
| 254 | rect.Reset(); |
| 255 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 256 | if (m_bMinSize) { |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 257 | rect.left = rtMinRect.left; |
| 258 | rect.top = rtMinRect.top; |
| 259 | return rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 260 | } |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 261 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 262 | rect.left = m_rtClient.left; |
| 263 | rect.top = m_rtClient.top; |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 264 | if (IsVertical()) { |
| 265 | rect.width = m_rtClient.width; |
| 266 | rect.height = (m_rtThumb.top + m_rtThumb.bottom()) / 2; |
| 267 | } else { |
| 268 | rect.width = (m_rtThumb.left + m_rtThumb.right()) / 2; |
| 269 | rect.height = m_rtClient.height; |
| 270 | } |
| 271 | return rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 272 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 273 | |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 274 | CFX_RectF CFWL_ScrollBar::CalcMaxTrackRect(const CFX_RectF& rtMaxRect) { |
| 275 | CFX_RectF rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 276 | if (m_bMinSize) { |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 277 | rect.Set(rtMaxRect.left, rtMaxRect.top, 0, 0); |
| 278 | return rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 279 | } |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 280 | |
Dan Sinclair | db194cf | 2017-01-02 15:45:12 -0500 | [diff] [blame^] | 281 | if (IsVertical()) { |
| 282 | FX_FLOAT iy = (m_rtThumb.top + m_rtThumb.bottom()) / 2; |
| 283 | rect.Set(m_rtClient.left, iy, m_rtClient.width, m_rtClient.bottom() - iy); |
| 284 | } else { |
| 285 | FX_FLOAT ix = (m_rtThumb.left + m_rtThumb.right()) / 2; |
| 286 | rect.Set(ix, m_rtClient.top, m_rtClient.height - ix, m_rtClient.height); |
| 287 | } |
| 288 | return rect; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 289 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 290 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 291 | FX_FLOAT CFWL_ScrollBar::GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 292 | FX_FLOAT fDiffX = fx - m_cpTrackPointX; |
| 293 | FX_FLOAT fDiffY = fy - m_cpTrackPointY; |
| 294 | FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; |
| 295 | FX_FLOAT fPos; |
dsinclair | 30e5f30 | 2016-11-21 12:18:28 -0800 | [diff] [blame] | 296 | |
| 297 | if (IsVertical()) { |
| 298 | fPos = fRange * fDiffY / |
| 299 | (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 300 | } else { |
dsinclair | 30e5f30 | 2016-11-21 12:18:28 -0800 | [diff] [blame] | 301 | fPos = fRange * fDiffX / |
| 302 | (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 303 | } |
dsinclair | 30e5f30 | 2016-11-21 12:18:28 -0800 | [diff] [blame] | 304 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 305 | fPos += m_fLastTrackPos; |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 306 | return std::min(std::max(fPos, m_fRangeMin), m_fRangeMax); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 307 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 308 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 309 | bool CFWL_ScrollBar::SendEvent() { |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 310 | if (m_iMinButtonState == CFWL_PartState_Pressed) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 311 | DoScroll(CFWL_EventScroll::Code::StepBackward, m_fTrackPos); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 312 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 313 | } |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 314 | if (m_iMaxButtonState == CFWL_PartState_Pressed) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 315 | DoScroll(CFWL_EventScroll::Code::StepForward, m_fTrackPos); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 316 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 317 | } |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 318 | if (m_iMinTrackState == CFWL_PartState_Pressed) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 319 | DoScroll(CFWL_EventScroll::Code::PageBackward, m_fTrackPos); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 320 | return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); |
| 321 | } |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 322 | if (m_iMaxTrackState == CFWL_PartState_Pressed) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 323 | DoScroll(CFWL_EventScroll::Code::PageForward, m_fTrackPos); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 324 | return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); |
| 325 | } |
| 326 | if (m_iMouseWheel) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 327 | CFWL_EventScroll::Code dwCode = m_iMouseWheel < 0 |
| 328 | ? CFWL_EventScroll::Code::StepForward |
| 329 | : CFWL_EventScroll::Code::StepBackward; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 330 | DoScroll(dwCode, m_fTrackPos); |
| 331 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 332 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 333 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 334 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 335 | bool CFWL_ScrollBar::OnScroll(CFWL_EventScroll::Code dwCode, FX_FLOAT fPos) { |
| 336 | CFWL_EventScroll ev(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 337 | ev.m_iScrollCode = dwCode; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 338 | ev.m_fPos = fPos; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 339 | DispatchEvent(&ev); |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 340 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 341 | } |
dsinclair | 5d9da0c | 2016-04-21 13:12:06 -0700 | [diff] [blame] | 342 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 343 | void CFWL_ScrollBar::OnProcessMessage(CFWL_Message* pMessage) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 344 | if (!pMessage) |
dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 345 | return; |
dsinclair | 5d9da0c | 2016-04-21 13:12:06 -0700 | [diff] [blame] | 346 | |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 347 | CFWL_Message::Type type = pMessage->GetType(); |
| 348 | if (type == CFWL_Message::Type::Mouse) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 349 | CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage); |
dsinclair | 8f4bf9a | 2016-05-04 13:51:51 -0700 | [diff] [blame] | 350 | switch (pMsg->m_dwCmd) { |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 351 | case FWL_MouseCommand::LeftButtonDown: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 352 | OnLButtonDown(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); |
| 353 | break; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 354 | case FWL_MouseCommand::LeftButtonUp: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 355 | OnLButtonUp(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); |
| 356 | break; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 357 | case FWL_MouseCommand::Move: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 358 | OnMouseMove(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); |
| 359 | break; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 360 | case FWL_MouseCommand::Leave: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 361 | OnMouseLeave(); |
| 362 | break; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 363 | default: |
| 364 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 365 | } |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 366 | } else if (type == CFWL_Message::Type::MouseWheel) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 367 | CFWL_MessageMouseWheel* pMsg = |
| 368 | static_cast<CFWL_MessageMouseWheel*>(pMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 369 | OnMouseWheel(pMsg->m_fx, pMsg->m_fy, pMsg->m_dwFlags, pMsg->m_fDeltaX, |
| 370 | pMsg->m_fDeltaY); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 371 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 372 | } |
dsinclair | 5d9da0c | 2016-04-21 13:12:06 -0700 | [diff] [blame] | 373 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 374 | void CFWL_ScrollBar::OnDrawWidget(CFX_Graphics* pGraphics, |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 375 | const CFX_Matrix* pMatrix) { |
| 376 | DrawWidget(pGraphics, pMatrix); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 377 | } |
dsinclair | c777f48 | 2016-05-04 17:57:03 -0700 | [diff] [blame] | 378 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 379 | void CFWL_ScrollBar::OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 380 | if (!IsEnabled()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 381 | return; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 382 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 383 | m_bMouseDown = true; |
| 384 | SetGrab(true); |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 385 | m_cpTrackPointX = fx; |
| 386 | m_cpTrackPointY = fy; |
| 387 | m_fLastTrackPos = m_fTrackPos; |
| 388 | if (m_rtMinBtn.Contains(fx, fy)) |
| 389 | DoMouseDown(0, m_rtMinBtn, m_iMinButtonState, fx, fy); |
| 390 | else if (m_rtThumb.Contains(fx, fy)) |
| 391 | DoMouseDown(1, m_rtThumb, m_iThumbButtonState, fx, fy); |
| 392 | else if (m_rtMaxBtn.Contains(fx, fy)) |
| 393 | DoMouseDown(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); |
| 394 | else if (m_rtMinTrack.Contains(fx, fy)) |
| 395 | DoMouseDown(3, m_rtMinTrack, m_iMinTrackState, fx, fy); |
| 396 | else |
| 397 | DoMouseDown(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); |
| 398 | |
| 399 | if (!SendEvent()) |
| 400 | m_pTimerInfo = m_Timer.StartTimer(FWL_SCROLLBAR_Elapse, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 401 | } |
tsepez | 6f4f233 | 2016-06-06 13:23:55 -0700 | [diff] [blame] | 402 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 403 | void CFWL_ScrollBar::OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 404 | m_pTimerInfo->StopTimer(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 405 | m_bMouseDown = false; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 406 | DoMouseUp(0, m_rtMinBtn, m_iMinButtonState, fx, fy); |
| 407 | DoMouseUp(1, m_rtThumb, m_iThumbButtonState, fx, fy); |
| 408 | DoMouseUp(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); |
| 409 | DoMouseUp(3, m_rtMinTrack, m_iMinTrackState, fx, fy); |
| 410 | DoMouseUp(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 411 | SetGrab(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 412 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 413 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 414 | void CFWL_ScrollBar::OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 415 | DoMouseMove(0, m_rtMinBtn, m_iMinButtonState, fx, fy); |
| 416 | DoMouseMove(1, m_rtThumb, m_iThumbButtonState, fx, fy); |
| 417 | DoMouseMove(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); |
| 418 | DoMouseMove(3, m_rtMinTrack, m_iMinTrackState, fx, fy); |
| 419 | DoMouseMove(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 420 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 421 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 422 | void CFWL_ScrollBar::OnMouseLeave() { |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 423 | DoMouseLeave(0, m_rtMinBtn, m_iMinButtonState); |
| 424 | DoMouseLeave(1, m_rtThumb, m_iThumbButtonState); |
| 425 | DoMouseLeave(2, m_rtMaxBtn, m_iMaxButtonState); |
| 426 | DoMouseLeave(3, m_rtMinTrack, m_iMinTrackState); |
| 427 | DoMouseLeave(4, m_rtMaxTrack, m_iMaxTrackState); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 428 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 429 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 430 | void CFWL_ScrollBar::OnMouseWheel(FX_FLOAT fx, |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 431 | FX_FLOAT fy, |
| 432 | uint32_t dwFlags, |
| 433 | FX_FLOAT fDeltaX, |
| 434 | FX_FLOAT fDeltaY) { |
| 435 | m_iMouseWheel = (int32_t)fDeltaX; |
| 436 | SendEvent(); |
| 437 | m_iMouseWheel = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 438 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 439 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 440 | void CFWL_ScrollBar::DoMouseDown(int32_t iItem, |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 441 | const CFX_RectF& rtItem, |
| 442 | int32_t& iState, |
| 443 | FX_FLOAT fx, |
| 444 | FX_FLOAT fy) { |
| 445 | if (!rtItem.Contains(fx, fy)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 446 | return; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 447 | if (iState == CFWL_PartState_Pressed) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 448 | return; |
dsinclair | 058d2d6 | 2016-11-16 13:54:01 -0800 | [diff] [blame] | 449 | |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 450 | iState = CFWL_PartState_Pressed; |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 451 | RepaintRect(rtItem); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 452 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 453 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 454 | void CFWL_ScrollBar::DoMouseUp(int32_t iItem, |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 455 | const CFX_RectF& rtItem, |
| 456 | int32_t& iState, |
| 457 | FX_FLOAT fx, |
| 458 | FX_FLOAT fy) { |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 459 | int32_t iNewState = |
| 460 | rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered : CFWL_PartState_Normal; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 461 | if (iState == iNewState) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 462 | return; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 463 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 464 | iState = iNewState; |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 465 | RepaintRect(rtItem); |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 466 | OnScroll(CFWL_EventScroll::Code::EndScroll, m_fTrackPos); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 467 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 468 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 469 | void CFWL_ScrollBar::DoMouseMove(int32_t iItem, |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 470 | const CFX_RectF& rtItem, |
| 471 | int32_t& iState, |
| 472 | FX_FLOAT fx, |
| 473 | FX_FLOAT fy) { |
| 474 | if (!m_bMouseDown) { |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 475 | int32_t iNewState = rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered |
| 476 | : CFWL_PartState_Normal; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 477 | if (iState == iNewState) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 478 | return; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 479 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 480 | iState = iNewState; |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 481 | RepaintRect(rtItem); |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 482 | } else if ((2 == iItem) && (m_iThumbButtonState == CFWL_PartState_Pressed)) { |
| 483 | FX_FLOAT fPos = GetTrackPointPos(fx, fy); |
| 484 | m_fTrackPos = fPos; |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 485 | OnScroll(CFWL_EventScroll::Code::TrackPos, fPos); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 486 | } |
| 487 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 488 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 489 | void CFWL_ScrollBar::DoMouseLeave(int32_t iItem, |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 490 | const CFX_RectF& rtItem, |
| 491 | int32_t& iState) { |
| 492 | if (iState == CFWL_PartState_Normal) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 493 | return; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 494 | |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 495 | iState = CFWL_PartState_Normal; |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 496 | RepaintRect(rtItem); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 497 | } |
dsinclair | fb50559 | 2016-10-20 06:44:03 -0700 | [diff] [blame] | 498 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 499 | void CFWL_ScrollBar::DoMouseHover(int32_t iItem, |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 500 | const CFX_RectF& rtItem, |
| 501 | int32_t& iState) { |
| 502 | if (iState == CFWL_PartState_Hovered) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 503 | return; |
dsinclair | 3b3ce1a | 2016-11-02 14:51:25 -0700 | [diff] [blame] | 504 | |
dsinclair | f87058d | 2016-04-21 06:22:11 -0700 | [diff] [blame] | 505 | iState = CFWL_PartState_Hovered; |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 506 | RepaintRect(rtItem); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 507 | } |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 508 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 509 | CFWL_ScrollBar::Timer::Timer(CFWL_ScrollBar* pToolTip) : CFWL_Timer(pToolTip) {} |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 510 | |
dsinclair | 0ce11ee | 2016-11-23 16:03:10 -0800 | [diff] [blame] | 511 | void CFWL_ScrollBar::Timer::Run(CFWL_TimerInfo* pTimerInfo) { |
| 512 | CFWL_ScrollBar* pButton = static_cast<CFWL_ScrollBar*>(m_pWidget); |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 513 | |
| 514 | if (pButton->m_pTimerInfo) |
| 515 | pButton->m_pTimerInfo->StopTimer(); |
| 516 | |
| 517 | if (!pButton->SendEvent()) |
| 518 | pButton->m_pTimerInfo = StartTimer(0, true); |
| 519 | } |