John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [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. |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | c411eb9 | 2017-07-25 09:39:30 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/pwl/cpwl_scroll_bar.h" |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 8 | |
Dan Sinclair | fb00ec2 | 2017-07-05 09:28:15 -0400 | [diff] [blame] | 9 | #include <algorithm> |
Henrique Nakashima | f1eae2c | 2017-06-29 11:18:49 -0400 | [diff] [blame] | 10 | #include <sstream> |
Tom Sepez | 9934cc2 | 2018-10-05 17:10:40 +0000 | [diff] [blame] | 11 | #include <utility> |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 12 | #include <vector> |
Henrique Nakashima | f1eae2c | 2017-06-29 11:18:49 -0400 | [diff] [blame] | 13 | |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 14 | #include "core/fxge/cfx_pathdata.h" |
| 15 | #include "core/fxge/cfx_renderdevice.h" |
Dan Sinclair | c411eb9 | 2017-07-25 09:39:30 -0400 | [diff] [blame] | 16 | #include "fpdfsdk/pwl/cpwl_wnd.h" |
Tom Sepez | 43f012f | 2019-08-02 16:16:46 +0000 | [diff] [blame^] | 17 | #include "third_party/base/ptr_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 18 | |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 19 | namespace { |
| 20 | |
| 21 | constexpr float kButtonWidth = 9.0f; |
| 22 | constexpr float kPosButtonMinWidth = 2.0f; |
Lei Zhang | 27d718e | 2018-01-18 21:51:17 +0000 | [diff] [blame] | 23 | constexpr float kScrollBarTriangleHalfLength = 2.0f; |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 24 | |
| 25 | } // namespace |
| 26 | |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 27 | #define PWL_DEFAULT_HEAVYGRAYCOLOR CFX_Color(CFX_Color::kGray, 0.50) |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 28 | |
Tom Sepez | 9934cc2 | 2018-10-05 17:10:40 +0000 | [diff] [blame] | 29 | void PWL_FLOATRANGE::Reset() { |
| 30 | fMin = 0.0f; |
| 31 | fMax = 0.0f; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Andrew Weintraub | ce4e27f | 2019-06-13 18:49:18 +0000 | [diff] [blame] | 34 | void PWL_FLOATRANGE::Set(float min, float max) { |
| 35 | fMin = std::min(min, max); |
| 36 | fMax = std::max(min, max); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 39 | bool PWL_FLOATRANGE::In(float x) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 40 | return (IsFloatBigger(x, fMin) || IsFloatEqual(x, fMin)) && |
| 41 | (IsFloatSmaller(x, fMax) || IsFloatEqual(x, fMax)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 44 | float PWL_FLOATRANGE::GetWidth() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 45 | return fMax - fMin; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | PWL_SCROLL_PRIVATEDATA::PWL_SCROLL_PRIVATEDATA() { |
| 49 | Default(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | void PWL_SCROLL_PRIVATEDATA::Default() { |
Tom Sepez | 9934cc2 | 2018-10-05 17:10:40 +0000 | [diff] [blame] | 53 | ScrollRange.Reset(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 54 | fScrollPos = ScrollRange.fMin; |
| 55 | fClientWidth = 0; |
| 56 | fBigStep = 10; |
| 57 | fSmallStep = 1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 60 | void PWL_SCROLL_PRIVATEDATA::SetScrollRange(float min, float max) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 61 | ScrollRange.Set(min, max); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 62 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | if (IsFloatSmaller(fScrollPos, ScrollRange.fMin)) |
| 64 | fScrollPos = ScrollRange.fMin; |
| 65 | if (IsFloatBigger(fScrollPos, ScrollRange.fMax)) |
| 66 | fScrollPos = ScrollRange.fMax; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 69 | void PWL_SCROLL_PRIVATEDATA::SetClientWidth(float width) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | fClientWidth = width; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 73 | void PWL_SCROLL_PRIVATEDATA::SetSmallStep(float step) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 74 | fSmallStep = step; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 77 | void PWL_SCROLL_PRIVATEDATA::SetBigStep(float step) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 78 | fBigStep = step; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 81 | bool PWL_SCROLL_PRIVATEDATA::SetPos(float pos) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 82 | if (ScrollRange.In(pos)) { |
| 83 | fScrollPos = pos; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 84 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 85 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 86 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | void PWL_SCROLL_PRIVATEDATA::AddSmall() { |
| 90 | if (!SetPos(fScrollPos + fSmallStep)) |
| 91 | SetPos(ScrollRange.fMax); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | void PWL_SCROLL_PRIVATEDATA::SubSmall() { |
| 95 | if (!SetPos(fScrollPos - fSmallStep)) |
| 96 | SetPos(ScrollRange.fMin); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 99 | void PWL_SCROLL_PRIVATEDATA::AddBig() { |
| 100 | if (!SetPos(fScrollPos + fBigStep)) |
| 101 | SetPos(ScrollRange.fMax); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 104 | void PWL_SCROLL_PRIVATEDATA::SubBig() { |
| 105 | if (!SetPos(fScrollPos - fBigStep)) |
| 106 | SetPos(ScrollRange.fMin); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Tom Sepez | b7c4a02 | 2018-10-26 23:56:27 +0000 | [diff] [blame] | 109 | CPWL_SBButton::CPWL_SBButton(const CreateParams& cp, |
| 110 | std::unique_ptr<PrivateData> pAttachedData, |
Tom Sepez | 6fe32f8 | 2018-10-25 23:25:58 +0000 | [diff] [blame] | 111 | PWL_SCROLLBAR_TYPE eScrollBarType, |
| 112 | PWL_SBBUTTON_TYPE eButtonType) |
Tom Sepez | b7c4a02 | 2018-10-26 23:56:27 +0000 | [diff] [blame] | 113 | : CPWL_Wnd(cp, std::move(pAttachedData)), |
Tom Sepez | 6fe32f8 | 2018-10-25 23:25:58 +0000 | [diff] [blame] | 114 | m_eScrollBarType(eScrollBarType), |
Tom Sepez | ea08d17 | 2018-10-29 17:29:06 +0000 | [diff] [blame] | 115 | m_eSBButtonType(eButtonType) { |
| 116 | GetCreationParams()->eCursorType = FXCT_ARROW; |
| 117 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 118 | |
Tom Sepez | 6fe32f8 | 2018-10-25 23:25:58 +0000 | [diff] [blame] | 119 | CPWL_SBButton::~CPWL_SBButton() = default; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 120 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 121 | void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 122 | const CFX_Matrix& mtUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 123 | if (!IsVisible()) |
| 124 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 125 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 126 | CFX_FloatRect rectWnd = GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 127 | if (rectWnd.IsEmpty()) |
| 128 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 129 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 130 | CFX_PointF ptCenter = GetCenterPoint(); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 131 | int32_t nTransparency = GetTransparency(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 132 | |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 133 | if (m_eScrollBarType == SBT_HSCROLL) { |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 134 | CPWL_Wnd::DrawThisAppearance(pDevice, mtUser2Device); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 135 | |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 136 | CFX_PointF pt1; |
| 137 | CFX_PointF pt2; |
| 138 | CFX_PointF pt3; |
Lei Zhang | 27d718e | 2018-01-18 21:51:17 +0000 | [diff] [blame] | 139 | static constexpr float kScrollBarTriangleQuarterLength = |
| 140 | kScrollBarTriangleHalfLength * 0.5; |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 141 | if (m_eSBButtonType == PSBT_MIN) { |
Lei Zhang | 27d718e | 2018-01-18 21:51:17 +0000 | [diff] [blame] | 142 | pt1 = |
| 143 | CFX_PointF(ptCenter.x - kScrollBarTriangleQuarterLength, ptCenter.y); |
| 144 | pt2 = CFX_PointF(ptCenter.x + kScrollBarTriangleQuarterLength, |
| 145 | ptCenter.y + kScrollBarTriangleHalfLength); |
| 146 | pt3 = CFX_PointF(ptCenter.x + kScrollBarTriangleQuarterLength, |
| 147 | ptCenter.y - kScrollBarTriangleHalfLength); |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 148 | } else if (m_eSBButtonType == PSBT_MAX) { |
Lei Zhang | 27d718e | 2018-01-18 21:51:17 +0000 | [diff] [blame] | 149 | pt1 = |
| 150 | CFX_PointF(ptCenter.x + kScrollBarTriangleQuarterLength, ptCenter.y); |
| 151 | pt2 = CFX_PointF(ptCenter.x - kScrollBarTriangleQuarterLength, |
| 152 | ptCenter.y + kScrollBarTriangleHalfLength); |
| 153 | pt3 = CFX_PointF(ptCenter.x - kScrollBarTriangleQuarterLength, |
| 154 | ptCenter.y - kScrollBarTriangleHalfLength); |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 155 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 156 | |
Lei Zhang | 27d718e | 2018-01-18 21:51:17 +0000 | [diff] [blame] | 157 | if (rectWnd.right - rectWnd.left > kScrollBarTriangleHalfLength * 2 && |
| 158 | rectWnd.top - rectWnd.bottom > kScrollBarTriangleHalfLength) { |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 159 | CFX_PathData path; |
| 160 | path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false); |
| 161 | path.AppendPoint(pt2, FXPT_TYPE::LineTo, false); |
| 162 | path.AppendPoint(pt3, FXPT_TYPE::LineTo, false); |
| 163 | path.AppendPoint(pt1, FXPT_TYPE::LineTo, false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 164 | |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 165 | pDevice->DrawPath(&path, &mtUser2Device, nullptr, |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 166 | PWL_DEFAULT_BLACKCOLOR.ToFXColor(nTransparency), 0, |
| 167 | FXFILL_ALTERNATE); |
| 168 | } |
| 169 | return; |
| 170 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 171 | |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 172 | // draw border |
Lei Zhang | e6d4559 | 2018-04-12 14:15:33 +0000 | [diff] [blame] | 173 | pDevice->DrawStrokeRect(mtUser2Device, rectWnd, |
Dan Sinclair | 0b7378a | 2017-07-17 12:05:40 -0400 | [diff] [blame] | 174 | ArgbEncode(nTransparency, 100, 100, 100), 0.0f); |
Lei Zhang | e6d4559 | 2018-04-12 14:15:33 +0000 | [diff] [blame] | 175 | pDevice->DrawStrokeRect(mtUser2Device, rectWnd.GetDeflated(0.5f, 0.5f), |
Dan Sinclair | 0b7378a | 2017-07-17 12:05:40 -0400 | [diff] [blame] | 176 | ArgbEncode(nTransparency, 255, 255, 255), 1.0f); |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 177 | |
| 178 | if (m_eSBButtonType != PSBT_POS) { |
| 179 | // draw background |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 180 | if (IsEnabled()) { |
Lei Zhang | e6d4559 | 2018-04-12 14:15:33 +0000 | [diff] [blame] | 181 | pDevice->DrawShadow(mtUser2Device, true, false, |
Dan Sinclair | 0b7378a | 2017-07-17 12:05:40 -0400 | [diff] [blame] | 182 | rectWnd.GetDeflated(1.0f, 1.0f), nTransparency, 80, |
| 183 | 220); |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 184 | } else { |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 185 | pDevice->DrawFillRect(&mtUser2Device, rectWnd.GetDeflated(1.0f, 1.0f), |
Dan Sinclair | 0b7378a | 2017-07-17 12:05:40 -0400 | [diff] [blame] | 186 | ArgbEncode(255, 255, 255, 255)); |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | // draw arrow |
| 190 | if (rectWnd.top - rectWnd.bottom > 6.0f) { |
| 191 | float fX = rectWnd.left + 1.5f; |
| 192 | float fY = rectWnd.bottom; |
| 193 | std::vector<CFX_PointF> pts; |
Lei Zhang | e6d4559 | 2018-04-12 14:15:33 +0000 | [diff] [blame] | 194 | static constexpr float kOffsetsX[] = {2.5f, 2.5f, 4.5f, 6.5f, |
| 195 | 6.5f, 4.5f, 2.5f}; |
| 196 | static constexpr float kOffsetsY[] = {5.0f, 6.0f, 4.0f, 6.0f, |
| 197 | 5.0f, 3.0f, 5.0f}; |
| 198 | static constexpr float kOffsetsMinY[] = {4.0f, 3.0f, 5.0f, 3.0f, |
| 199 | 4.0f, 6.0f, 4.0f}; |
| 200 | static_assert(FX_ArraySize(kOffsetsX) == FX_ArraySize(kOffsetsY), |
| 201 | "Wrong offset count"); |
| 202 | static_assert(FX_ArraySize(kOffsetsX) == FX_ArraySize(kOffsetsMinY), |
| 203 | "Wrong offset count"); |
| 204 | const float* pOffsetsY = |
| 205 | m_eSBButtonType == PSBT_MIN ? kOffsetsMinY : kOffsetsY; |
| 206 | for (size_t i = 0; i < FX_ArraySize(kOffsetsX); ++i) |
| 207 | pts.push_back(CFX_PointF(fX + kOffsetsX[i], fY + pOffsetsY[i])); |
| 208 | pDevice->DrawFillArea(mtUser2Device, pts, |
Dan Sinclair | 0b7378a | 2017-07-17 12:05:40 -0400 | [diff] [blame] | 209 | IsEnabled() |
| 210 | ? ArgbEncode(nTransparency, 255, 255, 255) |
| 211 | : PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255)); |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 212 | } |
| 213 | return; |
| 214 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 215 | |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 216 | if (IsEnabled()) { |
| 217 | // draw shadow effect |
| 218 | CFX_PointF ptTop = CFX_PointF(rectWnd.left, rectWnd.top - 1.0f); |
| 219 | CFX_PointF ptBottom = CFX_PointF(rectWnd.left, rectWnd.bottom + 1.0f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 220 | |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 221 | ptTop.x += 1.5f; |
| 222 | ptBottom.x += 1.5f; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 223 | |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 224 | const FX_COLORREF refs[] = {ArgbEncode(nTransparency, 210, 210, 210), |
| 225 | ArgbEncode(nTransparency, 220, 220, 220), |
| 226 | ArgbEncode(nTransparency, 240, 240, 240), |
| 227 | ArgbEncode(nTransparency, 240, 240, 240), |
| 228 | ArgbEncode(nTransparency, 210, 210, 210), |
| 229 | ArgbEncode(nTransparency, 180, 180, 180), |
| 230 | ArgbEncode(nTransparency, 150, 150, 150), |
| 231 | ArgbEncode(nTransparency, 150, 150, 150), |
| 232 | ArgbEncode(nTransparency, 180, 180, 180), |
| 233 | ArgbEncode(nTransparency, 210, 210, 210)}; |
Dan Sinclair | 0b7378a | 2017-07-17 12:05:40 -0400 | [diff] [blame] | 234 | for (FX_COLORREF ref : refs) { |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 235 | pDevice->DrawStrokeLine(&mtUser2Device, ptTop, ptBottom, ref, 1.0f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 236 | |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 237 | ptTop.x += 1.0f; |
| 238 | ptBottom.x += 1.0f; |
| 239 | } |
| 240 | } else { |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 241 | pDevice->DrawFillRect(&mtUser2Device, rectWnd.GetDeflated(0.5f, 0.5f), |
Dan Sinclair | 0b7378a | 2017-07-17 12:05:40 -0400 | [diff] [blame] | 242 | ArgbEncode(255, 255, 255, 255)); |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 243 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 244 | |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 245 | // draw friction |
| 246 | if (rectWnd.Height() <= 8.0f) |
| 247 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 248 | |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 249 | FX_COLORREF crStroke = ArgbEncode(nTransparency, 120, 120, 120); |
| 250 | if (!IsEnabled()) |
| 251 | crStroke = PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 252 | |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 253 | float nFrictionWidth = 5.0f; |
| 254 | float nFrictionHeight = 5.5f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 255 | |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 256 | CFX_PointF ptLeft = CFX_PointF(ptCenter.x - nFrictionWidth / 2.0f, |
| 257 | ptCenter.y - nFrictionHeight / 2.0f + 0.5f); |
| 258 | CFX_PointF ptRight = CFX_PointF(ptCenter.x + nFrictionWidth / 2.0f, |
| 259 | ptCenter.y - nFrictionHeight / 2.0f + 0.5f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 260 | |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 261 | for (size_t i = 0; i < 3; ++i) { |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 262 | pDevice->DrawStrokeLine(&mtUser2Device, ptLeft, ptRight, crStroke, 1.0f); |
Dan Sinclair | c099381 | 2017-07-05 17:17:08 -0400 | [diff] [blame] | 263 | ptLeft.y += 2.0f; |
| 264 | ptRight.y += 2.0f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 265 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 268 | bool CPWL_SBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 269 | CPWL_Wnd::OnLButtonDown(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 270 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 271 | if (CPWL_Wnd* pParent = GetParentWindow()) |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 272 | pParent->NotifyLButtonDown(this, point); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 273 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 274 | m_bMouseDown = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 275 | SetCapture(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 276 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 277 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 280 | bool CPWL_SBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 281 | CPWL_Wnd::OnLButtonUp(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 282 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 283 | if (CPWL_Wnd* pParent = GetParentWindow()) |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 284 | pParent->NotifyLButtonUp(this, point); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 285 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 286 | m_bMouseDown = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 287 | ReleaseCapture(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 288 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 289 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 292 | bool CPWL_SBButton::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 293 | CPWL_Wnd::OnMouseMove(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 294 | |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 295 | if (CPWL_Wnd* pParent = GetParentWindow()) |
| 296 | pParent->NotifyMouseMove(this, point); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 297 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 298 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Tom Sepez | b7c4a02 | 2018-10-26 23:56:27 +0000 | [diff] [blame] | 301 | CPWL_ScrollBar::CPWL_ScrollBar(const CreateParams& cp, |
| 302 | std::unique_ptr<PrivateData> pAttachedData, |
Tom Sepez | 6fe32f8 | 2018-10-25 23:25:58 +0000 | [diff] [blame] | 303 | PWL_SCROLLBAR_TYPE sbType) |
Tom Sepez | ea08d17 | 2018-10-29 17:29:06 +0000 | [diff] [blame] | 304 | : CPWL_Wnd(cp, std::move(pAttachedData)), m_sbType(sbType) { |
| 305 | GetCreationParams()->eCursorType = FXCT_ARROW; |
| 306 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 307 | |
Tom Sepez | 6fe32f8 | 2018-10-25 23:25:58 +0000 | [diff] [blame] | 308 | CPWL_ScrollBar::~CPWL_ScrollBar() = default; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 309 | |
Tom Sepez | 5e042a1 | 2017-05-30 14:13:44 -0700 | [diff] [blame] | 310 | void CPWL_ScrollBar::OnDestroy() { |
| 311 | // Until cleanup takes place in the virtual destructor for CPWL_Wnd |
| 312 | // subclasses, implement the virtual OnDestroy method that does the |
| 313 | // cleanup first, then invokes the superclass OnDestroy ... gee, |
| 314 | // like a dtor would. |
| 315 | m_pMinButton.Release(); |
| 316 | m_pMaxButton.Release(); |
| 317 | m_pPosButton.Release(); |
| 318 | CPWL_Wnd::OnDestroy(); |
| 319 | } |
| 320 | |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 321 | bool CPWL_ScrollBar::RePosChildWnd() { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 322 | CFX_FloatRect rcClient = GetClientRect(); |
| 323 | CFX_FloatRect rcMinButton, rcMaxButton; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 324 | float fBWidth = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 325 | |
| 326 | switch (m_sbType) { |
| 327 | case SBT_HSCROLL: |
| 328 | if (rcClient.right - rcClient.left > |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 329 | kButtonWidth * 2 + kPosButtonMinWidth + 2) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 330 | rcMinButton = CFX_FloatRect(rcClient.left, rcClient.bottom, |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 331 | rcClient.left + kButtonWidth, rcClient.top); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 332 | rcMaxButton = |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 333 | CFX_FloatRect(rcClient.right - kButtonWidth, rcClient.bottom, |
| 334 | rcClient.right, rcClient.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 335 | } else { |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 336 | fBWidth = (rcClient.right - rcClient.left - kPosButtonMinWidth - 2) / 2; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 337 | |
| 338 | if (fBWidth > 0) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 339 | rcMinButton = CFX_FloatRect(rcClient.left, rcClient.bottom, |
| 340 | rcClient.left + fBWidth, rcClient.top); |
| 341 | rcMaxButton = CFX_FloatRect(rcClient.right - fBWidth, rcClient.bottom, |
| 342 | rcClient.right, rcClient.top); |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 343 | } else { |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 344 | if (!SetVisible(false)) |
| 345 | return false; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 346 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 347 | } |
| 348 | break; |
| 349 | case SBT_VSCROLL: |
| 350 | if (IsFloatBigger(rcClient.top - rcClient.bottom, |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 351 | kButtonWidth * 2 + kPosButtonMinWidth + 2)) { |
| 352 | rcMinButton = CFX_FloatRect(rcClient.left, rcClient.top - kButtonWidth, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 353 | rcClient.right, rcClient.top); |
| 354 | rcMaxButton = |
| 355 | CFX_FloatRect(rcClient.left, rcClient.bottom, rcClient.right, |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 356 | rcClient.bottom + kButtonWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 357 | } else { |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 358 | fBWidth = (rcClient.top - rcClient.bottom - kPosButtonMinWidth - 2) / 2; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 359 | |
| 360 | if (IsFloatBigger(fBWidth, 0)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 361 | rcMinButton = CFX_FloatRect(rcClient.left, rcClient.top - fBWidth, |
| 362 | rcClient.right, rcClient.top); |
| 363 | rcMaxButton = |
| 364 | CFX_FloatRect(rcClient.left, rcClient.bottom, rcClient.right, |
| 365 | rcClient.bottom + fBWidth); |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 366 | } else { |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 367 | if (!SetVisible(false)) |
| 368 | return false; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 369 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 370 | } |
| 371 | break; |
| 372 | } |
| 373 | |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 374 | ObservedPtr<CPWL_ScrollBar> thisObserved(this); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 375 | if (m_pMinButton) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 376 | m_pMinButton->Move(rcMinButton, true, false); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 377 | if (!thisObserved) |
| 378 | return false; |
| 379 | } |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 380 | if (m_pMaxButton) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 381 | m_pMaxButton->Move(rcMaxButton, true, false); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 382 | if (!thisObserved) |
| 383 | return false; |
| 384 | } |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 385 | if (!MovePosButton(false)) |
| 386 | return false; |
| 387 | |
| 388 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 391 | void CPWL_ScrollBar::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 392 | const CFX_Matrix& mtUser2Device) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 393 | CFX_FloatRect rectWnd = GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 394 | |
| 395 | if (IsVisible() && !rectWnd.IsEmpty()) { |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 396 | pDevice->DrawFillRect(&mtUser2Device, rectWnd, GetBackgroundColor(), |
Dan Sinclair | 0b7378a | 2017-07-17 12:05:40 -0400 | [diff] [blame] | 397 | GetTransparency()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 398 | |
Dan Sinclair | 0b7378a | 2017-07-17 12:05:40 -0400 | [diff] [blame] | 399 | pDevice->DrawStrokeLine( |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 400 | &mtUser2Device, CFX_PointF(rectWnd.left + 2.0f, rectWnd.top - 2.0f), |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 401 | CFX_PointF(rectWnd.left + 2.0f, rectWnd.bottom + 2.0f), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 402 | ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f); |
| 403 | |
Dan Sinclair | 0b7378a | 2017-07-17 12:05:40 -0400 | [diff] [blame] | 404 | pDevice->DrawStrokeLine( |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 405 | &mtUser2Device, CFX_PointF(rectWnd.right - 2.0f, rectWnd.top - 2.0f), |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 406 | CFX_PointF(rectWnd.right - 2.0f, rectWnd.bottom + 2.0f), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 407 | ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f); |
| 408 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 411 | bool CPWL_ScrollBar::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 412 | CPWL_Wnd::OnLButtonDown(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 413 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 414 | if (HasFlag(PWS_AUTOTRANSPARENT)) { |
| 415 | if (GetTransparency() != 255) { |
| 416 | SetTransparency(255); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 417 | if (!InvalidateRect(nullptr)) |
| 418 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 419 | } |
| 420 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 421 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 422 | CFX_FloatRect rcMinArea, rcMaxArea; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 423 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 424 | if (m_pPosButton && m_pPosButton->IsVisible()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 425 | CFX_FloatRect rcClient = GetClientRect(); |
| 426 | CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect(); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 427 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 428 | switch (m_sbType) { |
| 429 | case SBT_HSCROLL: |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 430 | rcMinArea = CFX_FloatRect(rcClient.left + kButtonWidth, rcClient.bottom, |
| 431 | rcPosButton.left, rcClient.top); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 432 | rcMaxArea = CFX_FloatRect(rcPosButton.right, rcClient.bottom, |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 433 | rcClient.right - kButtonWidth, rcClient.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 434 | |
| 435 | break; |
| 436 | case SBT_VSCROLL: |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 437 | rcMinArea = CFX_FloatRect(rcClient.left, rcPosButton.top, |
| 438 | rcClient.right, rcClient.top - kButtonWidth); |
| 439 | rcMaxArea = CFX_FloatRect(rcClient.left, rcClient.bottom + kButtonWidth, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 440 | rcClient.right, rcPosButton.bottom); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 441 | break; |
| 442 | } |
| 443 | |
| 444 | rcMinArea.Normalize(); |
| 445 | rcMaxArea.Normalize(); |
| 446 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 447 | if (rcMinArea.Contains(point)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 448 | m_sData.SubBig(); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 449 | if (!MovePosButton(true)) |
| 450 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 451 | NotifyScrollWindow(); |
| 452 | } |
| 453 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 454 | if (rcMaxArea.Contains(point)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 455 | m_sData.AddBig(); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 456 | if (!MovePosButton(true)) |
| 457 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 458 | NotifyScrollWindow(); |
| 459 | } |
| 460 | } |
| 461 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 462 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 465 | bool CPWL_ScrollBar::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 466 | CPWL_Wnd::OnLButtonUp(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 467 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 468 | if (HasFlag(PWS_AUTOTRANSPARENT)) { |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 469 | if (GetTransparency() != PWL_SCROLLBAR_TRANSPARENCY) { |
| 470 | SetTransparency(PWL_SCROLLBAR_TRANSPARENCY); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 471 | if (!InvalidateRect(nullptr)) |
| 472 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 473 | } |
| 474 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 475 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 476 | EndTimer(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 477 | m_bMouseDown = false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 478 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 479 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Dan Sinclair | fb00ec2 | 2017-07-05 09:28:15 -0400 | [diff] [blame] | 482 | void CPWL_ScrollBar::SetScrollInfo(const PWL_SCROLL_INFO& info) { |
| 483 | if (info == m_OriginInfo) |
| 484 | return; |
| 485 | |
| 486 | m_OriginInfo = info; |
| 487 | float fMax = |
| 488 | std::max(0.0f, info.fContentMax - info.fContentMin - info.fPlateWidth); |
| 489 | SetScrollRange(0, fMax, info.fPlateWidth); |
| 490 | SetScrollStep(info.fBigStep, info.fSmallStep); |
| 491 | } |
| 492 | |
Dan Sinclair | 7e0336e | 2017-07-05 09:39:50 -0400 | [diff] [blame] | 493 | void CPWL_ScrollBar::SetScrollPosition(float pos) { |
| 494 | switch (m_sbType) { |
| 495 | case SBT_HSCROLL: |
| 496 | pos = pos - m_OriginInfo.fContentMin; |
| 497 | break; |
| 498 | case SBT_VSCROLL: |
| 499 | pos = m_OriginInfo.fContentMax - pos; |
| 500 | break; |
| 501 | } |
| 502 | SetScrollPos(pos); |
| 503 | } |
| 504 | |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 505 | void CPWL_ScrollBar::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) { |
| 506 | if (child == m_pMinButton) |
| 507 | OnMinButtonLBDown(pos); |
| 508 | else if (child == m_pMaxButton) |
| 509 | OnMaxButtonLBDown(pos); |
| 510 | else if (child == m_pPosButton) |
| 511 | OnPosButtonLBDown(pos); |
| 512 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 513 | |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 514 | void CPWL_ScrollBar::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) { |
| 515 | if (child == m_pMinButton) |
| 516 | OnMinButtonLBUp(pos); |
| 517 | else if (child == m_pMaxButton) |
| 518 | OnMaxButtonLBUp(pos); |
| 519 | else if (child == m_pPosButton) |
| 520 | OnPosButtonLBUp(pos); |
| 521 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 522 | |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 523 | void CPWL_ScrollBar::NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) { |
| 524 | if (child == m_pMinButton) |
| 525 | OnMinButtonMouseMove(pos); |
| 526 | else if (child == m_pMaxButton) |
| 527 | OnMaxButtonMouseMove(pos); |
| 528 | else if (child == m_pPosButton) |
| 529 | OnPosButtonMouseMove(pos); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Tom Sepez | bf15730 | 2017-09-15 13:26:32 -0700 | [diff] [blame] | 532 | void CPWL_ScrollBar::CreateButtons(const CreateParams& cp) { |
| 533 | CreateParams scp = cp; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 534 | scp.dwBorderWidth = 2; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 535 | scp.nBorderStyle = BorderStyle::BEVELED; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 536 | scp.dwFlags = |
| 537 | PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PWS_NOREFRESHCLIP; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 538 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 539 | if (!m_pMinButton) { |
Tom Sepez | b7c4a02 | 2018-10-26 23:56:27 +0000 | [diff] [blame] | 540 | auto pButton = pdfium::MakeUnique<CPWL_SBButton>(scp, CloneAttachedData(), |
Tom Sepez | 9590dee | 2018-10-26 22:08:43 +0000 | [diff] [blame] | 541 | m_sbType, PSBT_MIN); |
| 542 | m_pMinButton = pButton.get(); |
| 543 | AddChild(std::move(pButton)); |
Tom Sepez | b7c4a02 | 2018-10-26 23:56:27 +0000 | [diff] [blame] | 544 | m_pMinButton->Realize(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 545 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 546 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 547 | if (!m_pMaxButton) { |
Tom Sepez | b7c4a02 | 2018-10-26 23:56:27 +0000 | [diff] [blame] | 548 | auto pButton = pdfium::MakeUnique<CPWL_SBButton>(scp, CloneAttachedData(), |
Tom Sepez | 9590dee | 2018-10-26 22:08:43 +0000 | [diff] [blame] | 549 | m_sbType, PSBT_MAX); |
| 550 | m_pMaxButton = pButton.get(); |
| 551 | AddChild(std::move(pButton)); |
Tom Sepez | b7c4a02 | 2018-10-26 23:56:27 +0000 | [diff] [blame] | 552 | m_pMaxButton->Realize(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 553 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 554 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 555 | if (!m_pPosButton) { |
Tom Sepez | b7c4a02 | 2018-10-26 23:56:27 +0000 | [diff] [blame] | 556 | auto pButton = pdfium::MakeUnique<CPWL_SBButton>(scp, CloneAttachedData(), |
Tom Sepez | 9590dee | 2018-10-26 22:08:43 +0000 | [diff] [blame] | 557 | m_sbType, PSBT_POS); |
| 558 | m_pPosButton = pButton.get(); |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 559 | ObservedPtr<CPWL_ScrollBar> thisObserved(this); |
Tom Sepez | 7df950a | 2018-10-26 19:42:40 +0000 | [diff] [blame] | 560 | if (m_pPosButton->SetVisible(false) && thisObserved) { |
Tom Sepez | 9590dee | 2018-10-26 22:08:43 +0000 | [diff] [blame] | 561 | AddChild(std::move(pButton)); |
Tom Sepez | b7c4a02 | 2018-10-26 23:56:27 +0000 | [diff] [blame] | 562 | m_pPosButton->Realize(); |
Tom Sepez | 7df950a | 2018-10-26 19:42:40 +0000 | [diff] [blame] | 563 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 564 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 567 | float CPWL_ScrollBar::GetScrollBarWidth() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 568 | if (!IsVisible()) |
| 569 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 570 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 571 | return PWL_SCROLLBAR_WIDTH; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 574 | void CPWL_ScrollBar::SetScrollRange(float fMin, |
| 575 | float fMax, |
| 576 | float fClientWidth) { |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 577 | if (!m_pPosButton) |
| 578 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 579 | |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 580 | ObservedPtr<CPWL_ScrollBar> thisObserved(this); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 581 | m_sData.SetScrollRange(fMin, fMax); |
| 582 | m_sData.SetClientWidth(fClientWidth); |
| 583 | |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 584 | if (IsFloatSmaller(m_sData.ScrollRange.GetWidth(), 0.0f)) { |
| 585 | m_pPosButton->SetVisible(false); |
| 586 | // Note, |this| may no longer be viable at this point. If more work needs |
| 587 | // to be done, check thisObserved. |
| 588 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 589 | } |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 590 | |
| 591 | if (!m_pPosButton->SetVisible(true) || !thisObserved) |
| 592 | return; |
| 593 | |
| 594 | MovePosButton(true); |
| 595 | // Note, |this| may no longer be viable at this point. If more work needs |
| 596 | // to be done, check the return value of MovePosButton(). |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 599 | void CPWL_ScrollBar::SetScrollPos(float fPos) { |
| 600 | float fOldPos = m_sData.fScrollPos; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 601 | m_sData.SetPos(fPos); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 602 | if (!IsFloatEqual(m_sData.fScrollPos, fOldPos)) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 603 | MovePosButton(true); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 604 | // Note, |this| may no longer be viable at this point. If more work needs |
| 605 | // to be done, check the return value of MovePosButton(). |
| 606 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 609 | void CPWL_ScrollBar::SetScrollStep(float fBigStep, float fSmallStep) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 610 | m_sData.SetBigStep(fBigStep); |
| 611 | m_sData.SetSmallStep(fSmallStep); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 614 | bool CPWL_ScrollBar::MovePosButton(bool bRefresh) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 615 | ASSERT(m_pMinButton); |
| 616 | ASSERT(m_pMaxButton); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 617 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 618 | if (m_pPosButton->IsVisible()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 619 | CFX_FloatRect rcClient; |
| 620 | CFX_FloatRect rcPosArea, rcPosButton; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 621 | |
| 622 | rcClient = GetClientRect(); |
| 623 | rcPosArea = GetScrollArea(); |
| 624 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 625 | float fLeft, fRight, fTop, fBottom; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 626 | |
| 627 | switch (m_sbType) { |
| 628 | case SBT_HSCROLL: |
| 629 | fLeft = TrueToFace(m_sData.fScrollPos); |
| 630 | fRight = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth); |
| 631 | |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 632 | if (fRight - fLeft < kPosButtonMinWidth) |
| 633 | fRight = fLeft + kPosButtonMinWidth; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 634 | |
| 635 | if (fRight > rcPosArea.right) { |
| 636 | fRight = rcPosArea.right; |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 637 | fLeft = fRight - kPosButtonMinWidth; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 640 | rcPosButton = |
| 641 | CFX_FloatRect(fLeft, rcPosArea.bottom, fRight, rcPosArea.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 642 | |
| 643 | break; |
| 644 | case SBT_VSCROLL: |
| 645 | fBottom = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth); |
| 646 | fTop = TrueToFace(m_sData.fScrollPos); |
| 647 | |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 648 | if (IsFloatSmaller(fTop - fBottom, kPosButtonMinWidth)) |
| 649 | fBottom = fTop - kPosButtonMinWidth; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 650 | |
| 651 | if (IsFloatSmaller(fBottom, rcPosArea.bottom)) { |
| 652 | fBottom = rcPosArea.bottom; |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 653 | fTop = fBottom + kPosButtonMinWidth; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 656 | rcPosButton = |
| 657 | CFX_FloatRect(rcPosArea.left, fBottom, rcPosArea.right, fTop); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 658 | |
| 659 | break; |
| 660 | } |
| 661 | |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 662 | ObservedPtr<CPWL_ScrollBar> thisObserved(this); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 663 | m_pPosButton->Move(rcPosButton, true, bRefresh); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 664 | if (!thisObserved) |
| 665 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 666 | } |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 667 | |
| 668 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 669 | } |
| 670 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 671 | void CPWL_ScrollBar::OnMinButtonLBDown(const CFX_PointF& point) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 672 | m_sData.SubSmall(); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 673 | if (!MovePosButton(true)) |
| 674 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 675 | NotifyScrollWindow(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 676 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 677 | m_bMinOrMax = true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 678 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 679 | EndTimer(); |
| 680 | BeginTimer(100); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 683 | void CPWL_ScrollBar::OnMinButtonLBUp(const CFX_PointF& point) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 684 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 685 | void CPWL_ScrollBar::OnMinButtonMouseMove(const CFX_PointF& point) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 686 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 687 | void CPWL_ScrollBar::OnMaxButtonLBDown(const CFX_PointF& point) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 688 | m_sData.AddSmall(); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 689 | if (!MovePosButton(true)) |
| 690 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 691 | NotifyScrollWindow(); |
| 692 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 693 | m_bMinOrMax = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 694 | |
| 695 | EndTimer(); |
| 696 | BeginTimer(100); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 699 | void CPWL_ScrollBar::OnMaxButtonLBUp(const CFX_PointF& point) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 700 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 701 | void CPWL_ScrollBar::OnMaxButtonMouseMove(const CFX_PointF& point) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 702 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 703 | void CPWL_ScrollBar::OnPosButtonLBDown(const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 704 | m_bMouseDown = true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 705 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 706 | if (m_pPosButton) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 707 | CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 708 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 709 | switch (m_sbType) { |
| 710 | case SBT_HSCROLL: |
| 711 | m_nOldPos = point.x; |
| 712 | m_fOldPosButton = rcPosButton.left; |
| 713 | break; |
| 714 | case SBT_VSCROLL: |
| 715 | m_nOldPos = point.y; |
| 716 | m_fOldPosButton = rcPosButton.top; |
| 717 | break; |
| 718 | } |
| 719 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 722 | void CPWL_ScrollBar::OnPosButtonLBUp(const CFX_PointF& point) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 723 | if (m_bMouseDown) { |
| 724 | if (!m_bNotifyForever) |
| 725 | NotifyScrollWindow(); |
| 726 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 727 | m_bMouseDown = false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 730 | void CPWL_ScrollBar::OnPosButtonMouseMove(const CFX_PointF& point) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 731 | float fOldScrollPos = m_sData.fScrollPos; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 732 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 733 | float fNewPos = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 734 | |
| 735 | switch (m_sbType) { |
| 736 | case SBT_HSCROLL: |
Dan Sinclair | 669a418 | 2017-04-03 14:51:45 -0400 | [diff] [blame] | 737 | if (fabs(point.x - m_nOldPos) < 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 738 | return; |
| 739 | fNewPos = FaceToTrue(m_fOldPosButton + point.x - m_nOldPos); |
| 740 | break; |
| 741 | case SBT_VSCROLL: |
Dan Sinclair | 669a418 | 2017-04-03 14:51:45 -0400 | [diff] [blame] | 742 | if (fabs(point.y - m_nOldPos) < 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 743 | return; |
| 744 | fNewPos = FaceToTrue(m_fOldPosButton + point.y - m_nOldPos); |
| 745 | break; |
| 746 | } |
| 747 | |
| 748 | if (m_bMouseDown) { |
| 749 | switch (m_sbType) { |
| 750 | case SBT_HSCROLL: |
| 751 | |
| 752 | if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) { |
| 753 | fNewPos = m_sData.ScrollRange.fMin; |
| 754 | } |
| 755 | |
| 756 | if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) { |
| 757 | fNewPos = m_sData.ScrollRange.fMax; |
| 758 | } |
| 759 | |
| 760 | m_sData.SetPos(fNewPos); |
| 761 | |
| 762 | break; |
| 763 | case SBT_VSCROLL: |
| 764 | |
| 765 | if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) { |
| 766 | fNewPos = m_sData.ScrollRange.fMin; |
| 767 | } |
| 768 | |
| 769 | if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) { |
| 770 | fNewPos = m_sData.ScrollRange.fMax; |
| 771 | } |
| 772 | |
| 773 | m_sData.SetPos(fNewPos); |
| 774 | |
| 775 | break; |
| 776 | } |
| 777 | |
| 778 | if (!IsFloatEqual(fOldScrollPos, m_sData.fScrollPos)) { |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 779 | if (!MovePosButton(true)) |
| 780 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 781 | |
| 782 | if (m_bNotifyForever) |
| 783 | NotifyScrollWindow(); |
| 784 | } |
| 785 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 788 | void CPWL_ScrollBar::NotifyScrollWindow() { |
Dan Sinclair | 63fbd8d | 2017-07-05 14:10:36 -0400 | [diff] [blame] | 789 | CPWL_Wnd* pParent = GetParentWindow(); |
| 790 | if (!pParent || m_sbType != SBT_VSCROLL) |
| 791 | return; |
| 792 | |
| 793 | pParent->ScrollWindowVertically(m_OriginInfo.fContentMax - |
| 794 | m_sData.fScrollPos); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 795 | } |
| 796 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 797 | CFX_FloatRect CPWL_ScrollBar::GetScrollArea() const { |
| 798 | CFX_FloatRect rcClient = GetClientRect(); |
| 799 | CFX_FloatRect rcArea; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 800 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 801 | if (!m_pMinButton || !m_pMaxButton) |
| 802 | return rcClient; |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 803 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 804 | CFX_FloatRect rcMin = m_pMinButton->GetWindowRect(); |
| 805 | CFX_FloatRect rcMax = m_pMaxButton->GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 806 | |
Lei Zhang | 9875889 | 2018-03-15 15:02:22 +0000 | [diff] [blame] | 807 | float fMinWidth = rcMin.Width(); |
| 808 | float fMinHeight = rcMin.Height(); |
| 809 | float fMaxWidth = rcMax.Width(); |
| 810 | float fMaxHeight = rcMax.Height(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 811 | |
| 812 | switch (m_sbType) { |
| 813 | case SBT_HSCROLL: |
| 814 | if (rcClient.right - rcClient.left > fMinWidth + fMaxWidth + 2) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 815 | rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom, |
| 816 | rcClient.right - fMaxWidth - 1, rcClient.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 817 | } else { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 818 | rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom, |
| 819 | rcClient.left + fMinWidth + 1, rcClient.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 820 | } |
| 821 | break; |
| 822 | case SBT_VSCROLL: |
| 823 | if (rcClient.top - rcClient.bottom > fMinHeight + fMaxHeight + 2) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 824 | rcArea = CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1, |
| 825 | rcClient.right, rcClient.top - fMaxHeight - 1); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 826 | } else { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 827 | rcArea = |
| 828 | CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1, |
| 829 | rcClient.right, rcClient.bottom + fMinHeight + 1); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 830 | } |
| 831 | break; |
| 832 | } |
| 833 | |
| 834 | rcArea.Normalize(); |
| 835 | |
| 836 | return rcArea; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 837 | } |
| 838 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 839 | float CPWL_ScrollBar::TrueToFace(float fTrue) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 840 | CFX_FloatRect rcPosArea; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 841 | rcPosArea = GetScrollArea(); |
| 842 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 843 | float fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 844 | fFactWidth = fFactWidth == 0 ? 1 : fFactWidth; |
| 845 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 846 | float fFace = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 847 | |
| 848 | switch (m_sbType) { |
| 849 | case SBT_HSCROLL: |
| 850 | fFace = rcPosArea.left + |
| 851 | fTrue * (rcPosArea.right - rcPosArea.left) / fFactWidth; |
| 852 | break; |
| 853 | case SBT_VSCROLL: |
| 854 | fFace = rcPosArea.top - |
| 855 | fTrue * (rcPosArea.top - rcPosArea.bottom) / fFactWidth; |
| 856 | break; |
| 857 | } |
| 858 | |
| 859 | return fFace; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 860 | } |
| 861 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 862 | float CPWL_ScrollBar::FaceToTrue(float fFace) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 863 | CFX_FloatRect rcPosArea; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 864 | rcPosArea = GetScrollArea(); |
| 865 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 866 | float fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 867 | fFactWidth = fFactWidth == 0 ? 1 : fFactWidth; |
| 868 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 869 | float fTrue = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 870 | |
| 871 | switch (m_sbType) { |
| 872 | case SBT_HSCROLL: |
| 873 | fTrue = (fFace - rcPosArea.left) * fFactWidth / |
| 874 | (rcPosArea.right - rcPosArea.left); |
| 875 | break; |
| 876 | case SBT_VSCROLL: |
| 877 | fTrue = (rcPosArea.top - fFace) * fFactWidth / |
| 878 | (rcPosArea.top - rcPosArea.bottom); |
| 879 | break; |
| 880 | } |
| 881 | |
| 882 | return fTrue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 883 | } |
| 884 | |
Tom Sepez | bf15730 | 2017-09-15 13:26:32 -0700 | [diff] [blame] | 885 | void CPWL_ScrollBar::CreateChildWnd(const CreateParams& cp) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 886 | CreateButtons(cp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 889 | void CPWL_ScrollBar::TimerProc() { |
| 890 | PWL_SCROLL_PRIVATEDATA sTemp = m_sData; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 891 | if (m_bMinOrMax) |
| 892 | m_sData.SubSmall(); |
| 893 | else |
| 894 | m_sData.AddSmall(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 895 | |
tsepez | f86ca38 | 2016-09-13 12:23:30 -0700 | [diff] [blame] | 896 | if (sTemp != m_sData) { |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 897 | if (!MovePosButton(true)) |
| 898 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 899 | NotifyScrollWindow(); |
| 900 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 901 | } |