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 | |
Lei Zhang | 633a3b7 | 2017-06-02 15:27:22 -0700 | [diff] [blame^] | 7 | #include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h" |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 8 | |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 9 | #include "core/fxge/cfx_pathdata.h" |
| 10 | #include "core/fxge/cfx_renderdevice.h" |
Lei Zhang | 633a3b7 | 2017-06-02 15:27:22 -0700 | [diff] [blame^] | 11 | #include "fpdfsdk/pdfwindow/cpwl_utils.h" |
| 12 | #include "fpdfsdk/pdfwindow/cpwl_wnd.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 13 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 14 | PWL_FLOATRANGE::PWL_FLOATRANGE() { |
| 15 | Default(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 16 | } |
| 17 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 18 | PWL_FLOATRANGE::PWL_FLOATRANGE(float min, float max) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 19 | Set(min, max); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 20 | } |
| 21 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 22 | void PWL_FLOATRANGE::Default() { |
| 23 | fMin = 0; |
| 24 | fMax = 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 25 | } |
| 26 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 27 | void PWL_FLOATRANGE::Set(float min, float max) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 28 | if (min > max) { |
| 29 | fMin = max; |
| 30 | fMax = min; |
| 31 | } else { |
| 32 | fMin = min; |
| 33 | fMax = max; |
| 34 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 37 | bool PWL_FLOATRANGE::In(float x) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 38 | return (IsFloatBigger(x, fMin) || IsFloatEqual(x, fMin)) && |
| 39 | (IsFloatSmaller(x, fMax) || IsFloatEqual(x, fMax)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 42 | float PWL_FLOATRANGE::GetWidth() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 43 | return fMax - fMin; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 46 | PWL_SCROLL_PRIVATEDATA::PWL_SCROLL_PRIVATEDATA() { |
| 47 | Default(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | void PWL_SCROLL_PRIVATEDATA::Default() { |
| 51 | ScrollRange.Default(); |
| 52 | fScrollPos = ScrollRange.fMin; |
| 53 | fClientWidth = 0; |
| 54 | fBigStep = 10; |
| 55 | fSmallStep = 1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 58 | void PWL_SCROLL_PRIVATEDATA::SetScrollRange(float min, float max) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 59 | ScrollRange.Set(min, max); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 60 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 61 | if (IsFloatSmaller(fScrollPos, ScrollRange.fMin)) |
| 62 | fScrollPos = ScrollRange.fMin; |
| 63 | if (IsFloatBigger(fScrollPos, ScrollRange.fMax)) |
| 64 | fScrollPos = ScrollRange.fMax; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 67 | void PWL_SCROLL_PRIVATEDATA::SetClientWidth(float width) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | fClientWidth = width; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 71 | void PWL_SCROLL_PRIVATEDATA::SetSmallStep(float step) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 72 | fSmallStep = step; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 75 | void PWL_SCROLL_PRIVATEDATA::SetBigStep(float step) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 76 | fBigStep = step; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 79 | bool PWL_SCROLL_PRIVATEDATA::SetPos(float pos) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | if (ScrollRange.In(pos)) { |
| 81 | fScrollPos = pos; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 82 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 84 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | void PWL_SCROLL_PRIVATEDATA::AddSmall() { |
| 88 | if (!SetPos(fScrollPos + fSmallStep)) |
| 89 | SetPos(ScrollRange.fMax); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 92 | void PWL_SCROLL_PRIVATEDATA::SubSmall() { |
| 93 | if (!SetPos(fScrollPos - fSmallStep)) |
| 94 | SetPos(ScrollRange.fMin); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 97 | void PWL_SCROLL_PRIVATEDATA::AddBig() { |
| 98 | if (!SetPos(fScrollPos + fBigStep)) |
| 99 | SetPos(ScrollRange.fMax); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 102 | void PWL_SCROLL_PRIVATEDATA::SubBig() { |
| 103 | if (!SetPos(fScrollPos - fBigStep)) |
| 104 | SetPos(ScrollRange.fMin); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 107 | CPWL_SBButton::CPWL_SBButton(PWL_SCROLLBAR_TYPE eScrollBarType, |
| 108 | PWL_SBBUTTON_TYPE eButtonType) { |
| 109 | m_eScrollBarType = eScrollBarType; |
| 110 | m_eSBButtonType = eButtonType; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 111 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 112 | m_bMouseDown = false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 115 | CPWL_SBButton::~CPWL_SBButton() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 116 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 117 | CFX_ByteString CPWL_SBButton::GetClassName() const { |
| 118 | return "CPWL_SBButton"; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 121 | void CPWL_SBButton::OnCreate(PWL_CREATEPARAM& cp) { |
| 122 | cp.eCursorType = FXCT_ARROW; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 125 | void CPWL_SBButton::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
| 126 | CPWL_Wnd::GetThisAppearanceStream(sAppStream); |
| 127 | |
| 128 | if (!IsVisible()) |
| 129 | return; |
| 130 | |
| 131 | CFX_ByteTextBuf sButton; |
| 132 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 133 | CFX_FloatRect rectWnd = GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 134 | |
| 135 | if (rectWnd.IsEmpty()) |
| 136 | return; |
| 137 | |
| 138 | sAppStream << "q\n"; |
| 139 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 140 | CFX_PointF ptCenter = GetCenterPoint(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 141 | |
| 142 | switch (m_eScrollBarType) { |
| 143 | case SBT_HSCROLL: |
| 144 | switch (m_eSBButtonType) { |
| 145 | case PSBT_MIN: { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 146 | CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); |
| 147 | CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, |
| 148 | ptCenter.y + PWL_TRIANGLE_HALFLEN); |
| 149 | CFX_PointF pt3(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, |
| 150 | ptCenter.y - PWL_TRIANGLE_HALFLEN); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 151 | |
| 152 | if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && |
| 153 | rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { |
| 154 | sButton << "0 g\n"; |
| 155 | sButton << pt1.x << " " << pt1.y << " m\n"; |
| 156 | sButton << pt2.x << " " << pt2.y << " l\n"; |
| 157 | sButton << pt3.x << " " << pt3.y << " l\n"; |
| 158 | sButton << pt1.x << " " << pt1.y << " l f\n"; |
| 159 | |
| 160 | sAppStream << sButton; |
| 161 | } |
| 162 | } break; |
| 163 | case PSBT_MAX: { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 164 | CFX_PointF pt1(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); |
| 165 | CFX_PointF pt2(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, |
| 166 | ptCenter.y + PWL_TRIANGLE_HALFLEN); |
| 167 | CFX_PointF pt3(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, |
| 168 | ptCenter.y - PWL_TRIANGLE_HALFLEN); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 169 | |
| 170 | if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && |
| 171 | rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { |
| 172 | sButton << "0 g\n"; |
| 173 | sButton << pt1.x << " " << pt1.y << " m\n"; |
| 174 | sButton << pt2.x << " " << pt2.y << " l\n"; |
| 175 | sButton << pt3.x << " " << pt3.y << " l\n"; |
| 176 | sButton << pt1.x << " " << pt1.y << " l f\n"; |
| 177 | |
| 178 | sAppStream << sButton; |
| 179 | } |
| 180 | } break; |
| 181 | default: |
| 182 | break; |
| 183 | } |
| 184 | break; |
| 185 | case SBT_VSCROLL: |
| 186 | switch (m_eSBButtonType) { |
| 187 | case PSBT_MIN: { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 188 | CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN, |
| 189 | ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f); |
| 190 | CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN, |
| 191 | ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f); |
| 192 | CFX_PointF pt3(ptCenter.x, ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 193 | |
| 194 | if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && |
| 195 | rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { |
| 196 | sButton << "0 g\n"; |
| 197 | sButton << pt1.x << " " << pt1.y << " m\n"; |
| 198 | sButton << pt2.x << " " << pt2.y << " l\n"; |
| 199 | sButton << pt3.x << " " << pt3.y << " l\n"; |
| 200 | sButton << pt1.x << " " << pt1.y << " l f\n"; |
| 201 | |
| 202 | sAppStream << sButton; |
| 203 | } |
| 204 | } break; |
| 205 | case PSBT_MAX: { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 206 | CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN, |
| 207 | ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f); |
| 208 | CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN, |
| 209 | ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f); |
| 210 | CFX_PointF pt3(ptCenter.x, ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 211 | |
| 212 | if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && |
| 213 | rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { |
| 214 | sButton << "0 g\n"; |
| 215 | sButton << pt1.x << " " << pt1.y << " m\n"; |
| 216 | sButton << pt2.x << " " << pt2.y << " l\n"; |
| 217 | sButton << pt3.x << " " << pt3.y << " l\n"; |
| 218 | sButton << pt1.x << " " << pt1.y << " l f\n"; |
| 219 | |
| 220 | sAppStream << sButton; |
| 221 | } |
| 222 | } break; |
| 223 | default: |
| 224 | break; |
| 225 | } |
| 226 | break; |
| 227 | default: |
| 228 | break; |
| 229 | } |
| 230 | |
| 231 | sAppStream << "Q\n"; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 234 | void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 235 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 236 | if (!IsVisible()) |
| 237 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 238 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 239 | CFX_FloatRect rectWnd = GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 240 | if (rectWnd.IsEmpty()) |
| 241 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 242 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 243 | CFX_PointF ptCenter = GetCenterPoint(); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 244 | int32_t nTransparency = GetTransparency(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 245 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 246 | switch (m_eScrollBarType) { |
| 247 | case SBT_HSCROLL: |
| 248 | CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); |
| 249 | switch (m_eSBButtonType) { |
| 250 | case PSBT_MIN: { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 251 | CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); |
| 252 | CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, |
| 253 | ptCenter.y + PWL_TRIANGLE_HALFLEN); |
| 254 | CFX_PointF pt3(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, |
| 255 | ptCenter.y - PWL_TRIANGLE_HALFLEN); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 256 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 257 | if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && |
| 258 | rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { |
| 259 | CFX_PathData path; |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 260 | path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false); |
| 261 | path.AppendPoint(pt2, FXPT_TYPE::LineTo, false); |
| 262 | path.AppendPoint(pt3, FXPT_TYPE::LineTo, false); |
| 263 | path.AppendPoint(pt1, FXPT_TYPE::LineTo, false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 264 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 265 | pDevice->DrawPath(&path, pUser2Device, nullptr, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 266 | PWL_DEFAULT_BLACKCOLOR.ToFXColor(nTransparency), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 267 | 0, FXFILL_ALTERNATE); |
| 268 | } |
| 269 | } break; |
| 270 | case PSBT_MAX: { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 271 | CFX_PointF pt1(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); |
| 272 | CFX_PointF pt2(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, |
| 273 | ptCenter.y + PWL_TRIANGLE_HALFLEN); |
| 274 | CFX_PointF pt3(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, |
| 275 | ptCenter.y - PWL_TRIANGLE_HALFLEN); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 276 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 277 | if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && |
| 278 | rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { |
| 279 | CFX_PathData path; |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 280 | path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false); |
| 281 | path.AppendPoint(pt2, FXPT_TYPE::LineTo, false); |
| 282 | path.AppendPoint(pt3, FXPT_TYPE::LineTo, false); |
| 283 | path.AppendPoint(pt1, FXPT_TYPE::LineTo, false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 284 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 285 | pDevice->DrawPath(&path, pUser2Device, nullptr, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 286 | PWL_DEFAULT_BLACKCOLOR.ToFXColor(nTransparency), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 287 | 0, FXFILL_ALTERNATE); |
| 288 | } |
| 289 | } break; |
| 290 | default: |
| 291 | break; |
| 292 | } |
| 293 | break; |
| 294 | case SBT_VSCROLL: |
| 295 | switch (m_eSBButtonType) { |
| 296 | case PSBT_MIN: { |
| 297 | // draw border |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 298 | CFX_FloatRect rcDraw = rectWnd; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 299 | CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 300 | ArgbEncode(nTransparency, 100, 100, 100), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | 0.0f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 302 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 303 | // draw inner border |
| 304 | rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f); |
| 305 | CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 306 | ArgbEncode(nTransparency, 255, 255, 255), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 307 | 1.0f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 308 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 309 | // draw background |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 310 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 311 | rcDraw = CPWL_Utils::DeflateRect(rectWnd, 1.0f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 312 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 313 | if (IsEnabled()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 314 | CPWL_Utils::DrawShadow(pDevice, pUser2Device, true, false, rcDraw, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 315 | nTransparency, 80, 220); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 316 | else |
| 317 | CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, |
| 318 | ArgbEncode(255, 255, 255, 255)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 319 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 320 | // draw arrow |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 321 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 322 | if (rectWnd.top - rectWnd.bottom > 6.0f) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 323 | float fX = rectWnd.left + 1.5f; |
| 324 | float fY = rectWnd.bottom; |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 325 | CFX_PointF pts[7] = {CFX_PointF(fX + 2.5f, fY + 4.0f), |
| 326 | CFX_PointF(fX + 2.5f, fY + 3.0f), |
| 327 | CFX_PointF(fX + 4.5f, fY + 5.0f), |
| 328 | CFX_PointF(fX + 6.5f, fY + 3.0f), |
| 329 | CFX_PointF(fX + 6.5f, fY + 4.0f), |
| 330 | CFX_PointF(fX + 4.5f, fY + 6.0f), |
| 331 | CFX_PointF(fX + 2.5f, fY + 4.0f)}; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 332 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 333 | if (IsEnabled()) |
| 334 | CPWL_Utils::DrawFillArea( |
| 335 | pDevice, pUser2Device, pts, 7, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 336 | ArgbEncode(nTransparency, 255, 255, 255)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 337 | else |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 338 | CPWL_Utils::DrawFillArea( |
| 339 | pDevice, pUser2Device, pts, 7, |
| 340 | PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 341 | } |
| 342 | } break; |
| 343 | case PSBT_MAX: { |
| 344 | // draw border |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 345 | CFX_FloatRect rcDraw = rectWnd; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 346 | CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 347 | ArgbEncode(nTransparency, 100, 100, 100), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 348 | 0.0f); |
| 349 | |
| 350 | // draw inner border |
| 351 | rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f); |
| 352 | CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 353 | ArgbEncode(nTransparency, 255, 255, 255), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 354 | 1.0f); |
| 355 | |
| 356 | // draw background |
| 357 | rcDraw = CPWL_Utils::DeflateRect(rectWnd, 1.0f); |
| 358 | if (IsEnabled()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 359 | CPWL_Utils::DrawShadow(pDevice, pUser2Device, true, false, rcDraw, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 360 | nTransparency, 80, 220); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 361 | else |
| 362 | CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, |
| 363 | ArgbEncode(255, 255, 255, 255)); |
| 364 | |
| 365 | // draw arrow |
| 366 | |
| 367 | if (rectWnd.top - rectWnd.bottom > 6.0f) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 368 | float fX = rectWnd.left + 1.5f; |
| 369 | float fY = rectWnd.bottom; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 370 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 371 | CFX_PointF pts[7] = {CFX_PointF(fX + 2.5f, fY + 5.0f), |
| 372 | CFX_PointF(fX + 2.5f, fY + 6.0f), |
| 373 | CFX_PointF(fX + 4.5f, fY + 4.0f), |
| 374 | CFX_PointF(fX + 6.5f, fY + 6.0f), |
| 375 | CFX_PointF(fX + 6.5f, fY + 5.0f), |
| 376 | CFX_PointF(fX + 4.5f, fY + 3.0f), |
| 377 | CFX_PointF(fX + 2.5f, fY + 5.0f)}; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 378 | |
| 379 | if (IsEnabled()) |
| 380 | CPWL_Utils::DrawFillArea( |
| 381 | pDevice, pUser2Device, pts, 7, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 382 | ArgbEncode(nTransparency, 255, 255, 255)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 383 | else |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 384 | CPWL_Utils::DrawFillArea( |
| 385 | pDevice, pUser2Device, pts, 7, |
| 386 | PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 387 | } |
| 388 | } break; |
| 389 | case PSBT_POS: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 390 | // draw border |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 391 | CFX_FloatRect rcDraw = rectWnd; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 392 | CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 393 | ArgbEncode(nTransparency, 100, 100, 100), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 394 | 0.0f); |
| 395 | |
| 396 | // draw inner border |
| 397 | rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f); |
| 398 | CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 399 | ArgbEncode(nTransparency, 255, 255, 255), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 400 | 1.0f); |
| 401 | |
| 402 | if (IsEnabled()) { |
| 403 | // draw shadow effect |
| 404 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 405 | CFX_PointF ptTop = CFX_PointF(rectWnd.left, rectWnd.top - 1.0f); |
| 406 | CFX_PointF ptBottom = |
| 407 | CFX_PointF(rectWnd.left, rectWnd.bottom + 1.0f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 408 | |
| 409 | ptTop.x += 1.5f; |
| 410 | ptBottom.x += 1.5f; |
| 411 | |
| 412 | CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 413 | ArgbEncode(nTransparency, 210, 210, 210), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 414 | 1.0f); |
| 415 | |
| 416 | ptTop.x += 1.0f; |
| 417 | ptBottom.x += 1.0f; |
| 418 | |
| 419 | CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 420 | ArgbEncode(nTransparency, 220, 220, 220), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 421 | 1.0f); |
| 422 | |
| 423 | ptTop.x += 1.0f; |
| 424 | ptBottom.x += 1.0f; |
| 425 | |
| 426 | CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 427 | ArgbEncode(nTransparency, 240, 240, 240), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 428 | 1.0f); |
| 429 | |
| 430 | ptTop.x += 1.0f; |
| 431 | ptBottom.x += 1.0f; |
| 432 | |
| 433 | CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 434 | ArgbEncode(nTransparency, 240, 240, 240), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 435 | 1.0f); |
| 436 | |
| 437 | ptTop.x += 1.0f; |
| 438 | ptBottom.x += 1.0f; |
| 439 | |
| 440 | CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 441 | ArgbEncode(nTransparency, 210, 210, 210), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 442 | 1.0f); |
| 443 | |
| 444 | ptTop.x += 1.0f; |
| 445 | ptBottom.x += 1.0f; |
| 446 | |
| 447 | CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 448 | ArgbEncode(nTransparency, 180, 180, 180), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 449 | 1.0f); |
| 450 | |
| 451 | ptTop.x += 1.0f; |
| 452 | ptBottom.x += 1.0f; |
| 453 | |
| 454 | CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 455 | ArgbEncode(nTransparency, 150, 150, 150), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 456 | 1.0f); |
| 457 | |
| 458 | ptTop.x += 1.0f; |
| 459 | ptBottom.x += 1.0f; |
| 460 | |
| 461 | CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 462 | ArgbEncode(nTransparency, 150, 150, 150), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 463 | 1.0f); |
| 464 | |
| 465 | ptTop.x += 1.0f; |
| 466 | ptBottom.x += 1.0f; |
| 467 | |
| 468 | CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 469 | ArgbEncode(nTransparency, 180, 180, 180), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 470 | 1.0f); |
| 471 | |
| 472 | ptTop.x += 1.0f; |
| 473 | ptBottom.x += 1.0f; |
| 474 | |
| 475 | CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 476 | ArgbEncode(nTransparency, 210, 210, 210), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 477 | 1.0f); |
| 478 | } else { |
| 479 | CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, |
| 480 | ArgbEncode(255, 255, 255, 255)); |
| 481 | } |
| 482 | |
| 483 | // draw friction |
| 484 | |
| 485 | if (rectWnd.Height() > 8.0f) { |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 486 | FX_COLORREF crStroke = ArgbEncode(nTransparency, 120, 120, 120); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 487 | if (!IsEnabled()) |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 488 | crStroke = PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 489 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 490 | float nFrictionWidth = 5.0f; |
| 491 | float nFrictionHeight = 5.5f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 492 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 493 | CFX_PointF ptLeft = |
| 494 | CFX_PointF(ptCenter.x - nFrictionWidth / 2.0f, |
| 495 | ptCenter.y - nFrictionHeight / 2.0f + 0.5f); |
| 496 | CFX_PointF ptRight = |
| 497 | CFX_PointF(ptCenter.x + nFrictionWidth / 2.0f, |
| 498 | ptCenter.y - nFrictionHeight / 2.0f + 0.5f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 499 | |
| 500 | CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight, |
| 501 | crStroke, 1.0f); |
| 502 | |
| 503 | ptLeft.y += 2.0f; |
| 504 | ptRight.y += 2.0f; |
| 505 | |
| 506 | CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight, |
| 507 | crStroke, 1.0f); |
| 508 | |
| 509 | ptLeft.y += 2.0f; |
| 510 | ptRight.y += 2.0f; |
| 511 | |
| 512 | CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight, |
| 513 | crStroke, 1.0f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 514 | } |
| 515 | } break; |
| 516 | default: |
| 517 | break; |
| 518 | } |
| 519 | break; |
| 520 | default: |
| 521 | break; |
| 522 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 525 | bool CPWL_SBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 526 | CPWL_Wnd::OnLButtonDown(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 527 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 528 | if (CPWL_Wnd* pParent = GetParentWindow()) |
| 529 | pParent->OnNotify(this, PNM_LBUTTONDOWN, 0, (intptr_t)&point); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 530 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 531 | m_bMouseDown = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 532 | SetCapture(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 533 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 534 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 537 | bool CPWL_SBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 538 | CPWL_Wnd::OnLButtonUp(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 539 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 540 | if (CPWL_Wnd* pParent = GetParentWindow()) |
| 541 | pParent->OnNotify(this, PNM_LBUTTONUP, 0, (intptr_t)&point); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 542 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 543 | m_bMouseDown = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 544 | ReleaseCapture(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 545 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 546 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 549 | bool CPWL_SBButton::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 550 | CPWL_Wnd::OnMouseMove(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 551 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 552 | if (CPWL_Wnd* pParent = GetParentWindow()) { |
| 553 | pParent->OnNotify(this, PNM_MOUSEMOVE, 0, (intptr_t)&point); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 554 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 555 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 556 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 559 | CPWL_ScrollBar::CPWL_ScrollBar(PWL_SCROLLBAR_TYPE sbType) |
| 560 | : m_sbType(sbType), |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 561 | m_pMinButton(nullptr), |
| 562 | m_pMaxButton(nullptr), |
| 563 | m_pPosButton(nullptr), |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 564 | m_bMouseDown(false), |
| 565 | m_bMinOrMax(false), |
| 566 | m_bNotifyForever(true) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 567 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 568 | CPWL_ScrollBar::~CPWL_ScrollBar() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 569 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 570 | CFX_ByteString CPWL_ScrollBar::GetClassName() const { |
| 571 | return "CPWL_ScrollBar"; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 574 | void CPWL_ScrollBar::OnCreate(PWL_CREATEPARAM& cp) { |
| 575 | cp.eCursorType = FXCT_ARROW; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 576 | } |
| 577 | |
Tom Sepez | 5e042a1 | 2017-05-30 14:13:44 -0700 | [diff] [blame] | 578 | void CPWL_ScrollBar::OnDestroy() { |
| 579 | // Until cleanup takes place in the virtual destructor for CPWL_Wnd |
| 580 | // subclasses, implement the virtual OnDestroy method that does the |
| 581 | // cleanup first, then invokes the superclass OnDestroy ... gee, |
| 582 | // like a dtor would. |
| 583 | m_pMinButton.Release(); |
| 584 | m_pMaxButton.Release(); |
| 585 | m_pPosButton.Release(); |
| 586 | CPWL_Wnd::OnDestroy(); |
| 587 | } |
| 588 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 589 | void CPWL_ScrollBar::RePosChildWnd() { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 590 | CFX_FloatRect rcClient = GetClientRect(); |
| 591 | CFX_FloatRect rcMinButton, rcMaxButton; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 592 | float fBWidth = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 593 | |
| 594 | switch (m_sbType) { |
| 595 | case SBT_HSCROLL: |
| 596 | if (rcClient.right - rcClient.left > |
| 597 | PWL_SCROLLBAR_BUTTON_WIDTH * 2 + PWL_SCROLLBAR_POSBUTTON_MINWIDTH + |
| 598 | 2) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 599 | rcMinButton = CFX_FloatRect(rcClient.left, rcClient.bottom, |
| 600 | rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH, |
| 601 | rcClient.top); |
| 602 | rcMaxButton = |
| 603 | CFX_FloatRect(rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH, |
| 604 | rcClient.bottom, rcClient.right, rcClient.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 605 | } else { |
| 606 | fBWidth = (rcClient.right - rcClient.left - |
| 607 | PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) / |
| 608 | 2; |
| 609 | |
| 610 | if (fBWidth > 0) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 611 | rcMinButton = CFX_FloatRect(rcClient.left, rcClient.bottom, |
| 612 | rcClient.left + fBWidth, rcClient.top); |
| 613 | rcMaxButton = CFX_FloatRect(rcClient.right - fBWidth, rcClient.bottom, |
| 614 | rcClient.right, rcClient.top); |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 615 | } else { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 616 | SetVisible(false); |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 617 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 618 | } |
| 619 | break; |
| 620 | case SBT_VSCROLL: |
| 621 | if (IsFloatBigger(rcClient.top - rcClient.bottom, |
| 622 | PWL_SCROLLBAR_BUTTON_WIDTH * 2 + |
| 623 | PWL_SCROLLBAR_POSBUTTON_MINWIDTH + 2)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 624 | rcMinButton = CFX_FloatRect(rcClient.left, |
| 625 | rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH, |
| 626 | rcClient.right, rcClient.top); |
| 627 | rcMaxButton = |
| 628 | CFX_FloatRect(rcClient.left, rcClient.bottom, rcClient.right, |
| 629 | rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 630 | } else { |
| 631 | fBWidth = (rcClient.top - rcClient.bottom - |
| 632 | PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) / |
| 633 | 2; |
| 634 | |
| 635 | if (IsFloatBigger(fBWidth, 0)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 636 | rcMinButton = CFX_FloatRect(rcClient.left, rcClient.top - fBWidth, |
| 637 | rcClient.right, rcClient.top); |
| 638 | rcMaxButton = |
| 639 | CFX_FloatRect(rcClient.left, rcClient.bottom, rcClient.right, |
| 640 | rcClient.bottom + fBWidth); |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 641 | } else { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 642 | SetVisible(false); |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 643 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 644 | } |
| 645 | break; |
| 646 | } |
| 647 | |
| 648 | if (m_pMinButton) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 649 | m_pMinButton->Move(rcMinButton, true, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 650 | if (m_pMaxButton) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 651 | m_pMaxButton->Move(rcMaxButton, true, false); |
| 652 | MovePosButton(false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 655 | void CPWL_ScrollBar::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 656 | CFX_FloatRect rectWnd = GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 657 | |
| 658 | if (IsVisible() && !rectWnd.IsEmpty()) { |
| 659 | CFX_ByteTextBuf sButton; |
| 660 | |
| 661 | sButton << "q\n"; |
| 662 | sButton << "0 w\n" |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 663 | << CPWL_Utils::GetColorAppStream(GetBackgroundColor(), true) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 664 | .AsStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 665 | sButton << rectWnd.left << " " << rectWnd.bottom << " " |
| 666 | << rectWnd.right - rectWnd.left << " " |
| 667 | << rectWnd.top - rectWnd.bottom << " re b Q\n"; |
| 668 | |
| 669 | sAppStream << sButton; |
| 670 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 673 | void CPWL_ScrollBar::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 674 | CFX_Matrix* pUser2Device) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 675 | CFX_FloatRect rectWnd = GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 676 | |
| 677 | if (IsVisible() && !rectWnd.IsEmpty()) { |
| 678 | CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rectWnd, |
| 679 | GetBackgroundColor(), GetTransparency()); |
| 680 | |
| 681 | CPWL_Utils::DrawStrokeLine( |
| 682 | pDevice, pUser2Device, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 683 | CFX_PointF(rectWnd.left + 2.0f, rectWnd.top - 2.0f), |
| 684 | CFX_PointF(rectWnd.left + 2.0f, rectWnd.bottom + 2.0f), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 685 | ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f); |
| 686 | |
| 687 | CPWL_Utils::DrawStrokeLine( |
| 688 | pDevice, pUser2Device, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 689 | CFX_PointF(rectWnd.right - 2.0f, rectWnd.top - 2.0f), |
| 690 | CFX_PointF(rectWnd.right - 2.0f, rectWnd.bottom + 2.0f), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 691 | ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f); |
| 692 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 693 | } |
| 694 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 695 | bool CPWL_ScrollBar::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 696 | CPWL_Wnd::OnLButtonDown(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 697 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 698 | if (HasFlag(PWS_AUTOTRANSPARENT)) { |
| 699 | if (GetTransparency() != 255) { |
| 700 | SetTransparency(255); |
| 701 | InvalidateRect(); |
| 702 | } |
| 703 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 704 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 705 | CFX_FloatRect rcMinArea, rcMaxArea; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 706 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 707 | if (m_pPosButton && m_pPosButton->IsVisible()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 708 | CFX_FloatRect rcClient = GetClientRect(); |
| 709 | CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect(); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 710 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 711 | switch (m_sbType) { |
| 712 | case SBT_HSCROLL: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 713 | rcMinArea = |
| 714 | CFX_FloatRect(rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH, |
| 715 | rcClient.bottom, rcPosButton.left, rcClient.top); |
| 716 | rcMaxArea = CFX_FloatRect(rcPosButton.right, rcClient.bottom, |
| 717 | rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH, |
| 718 | rcClient.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 719 | |
| 720 | break; |
| 721 | case SBT_VSCROLL: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 722 | rcMinArea = |
| 723 | CFX_FloatRect(rcClient.left, rcPosButton.top, rcClient.right, |
| 724 | rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH); |
| 725 | rcMaxArea = CFX_FloatRect(rcClient.left, |
| 726 | rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH, |
| 727 | rcClient.right, rcPosButton.bottom); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 728 | break; |
| 729 | } |
| 730 | |
| 731 | rcMinArea.Normalize(); |
| 732 | rcMaxArea.Normalize(); |
| 733 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 734 | if (rcMinArea.Contains(point)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 735 | m_sData.SubBig(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 736 | MovePosButton(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 737 | NotifyScrollWindow(); |
| 738 | } |
| 739 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 740 | if (rcMaxArea.Contains(point)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 741 | m_sData.AddBig(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 742 | MovePosButton(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 743 | NotifyScrollWindow(); |
| 744 | } |
| 745 | } |
| 746 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 747 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 750 | bool CPWL_ScrollBar::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 751 | CPWL_Wnd::OnLButtonUp(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 752 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 753 | if (HasFlag(PWS_AUTOTRANSPARENT)) { |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 754 | if (GetTransparency() != PWL_SCROLLBAR_TRANSPARENCY) { |
| 755 | SetTransparency(PWL_SCROLLBAR_TRANSPARENCY); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 756 | InvalidateRect(); |
| 757 | } |
| 758 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 759 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 760 | EndTimer(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 761 | m_bMouseDown = false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 762 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 763 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 766 | void CPWL_ScrollBar::OnNotify(CPWL_Wnd* pWnd, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 767 | uint32_t msg, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 768 | intptr_t wParam, |
| 769 | intptr_t lParam) { |
| 770 | CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 771 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 772 | switch (msg) { |
| 773 | case PNM_LBUTTONDOWN: |
| 774 | if (pWnd == m_pMinButton) { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 775 | OnMinButtonLBDown(*(CFX_PointF*)lParam); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 776 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 777 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 778 | if (pWnd == m_pMaxButton) { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 779 | OnMaxButtonLBDown(*(CFX_PointF*)lParam); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 780 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 781 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 782 | if (pWnd == m_pPosButton) { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 783 | OnPosButtonLBDown(*(CFX_PointF*)lParam); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 784 | } |
| 785 | break; |
| 786 | case PNM_LBUTTONUP: |
| 787 | if (pWnd == m_pMinButton) { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 788 | OnMinButtonLBUp(*(CFX_PointF*)lParam); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | if (pWnd == m_pMaxButton) { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 792 | OnMaxButtonLBUp(*(CFX_PointF*)lParam); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | if (pWnd == m_pPosButton) { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 796 | OnPosButtonLBUp(*(CFX_PointF*)lParam); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 797 | } |
| 798 | break; |
| 799 | case PNM_MOUSEMOVE: |
| 800 | if (pWnd == m_pMinButton) { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 801 | OnMinButtonMouseMove(*(CFX_PointF*)lParam); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | if (pWnd == m_pMaxButton) { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 805 | OnMaxButtonMouseMove(*(CFX_PointF*)lParam); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | if (pWnd == m_pPosButton) { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 809 | OnPosButtonMouseMove(*(CFX_PointF*)lParam); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 810 | } |
| 811 | break; |
| 812 | case PNM_SETSCROLLINFO: { |
tsepez | f86ca38 | 2016-09-13 12:23:30 -0700 | [diff] [blame] | 813 | PWL_SCROLL_INFO* pInfo = reinterpret_cast<PWL_SCROLL_INFO*>(lParam); |
| 814 | if (pInfo && *pInfo != m_OriginInfo) { |
| 815 | m_OriginInfo = *pInfo; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 816 | float fMax = |
tsepez | f86ca38 | 2016-09-13 12:23:30 -0700 | [diff] [blame] | 817 | pInfo->fContentMax - pInfo->fContentMin - pInfo->fPlateWidth; |
| 818 | fMax = fMax > 0.0f ? fMax : 0.0f; |
| 819 | SetScrollRange(0, fMax, pInfo->fPlateWidth); |
| 820 | SetScrollStep(pInfo->fBigStep, pInfo->fSmallStep); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 821 | } |
| 822 | } break; |
| 823 | case PNM_SETSCROLLPOS: { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 824 | float fPos = *(float*)lParam; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 825 | switch (m_sbType) { |
| 826 | case SBT_HSCROLL: |
| 827 | fPos = fPos - m_OriginInfo.fContentMin; |
| 828 | break; |
| 829 | case SBT_VSCROLL: |
| 830 | fPos = m_OriginInfo.fContentMax - fPos; |
| 831 | break; |
| 832 | } |
| 833 | SetScrollPos(fPos); |
| 834 | } break; |
| 835 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 838 | void CPWL_ScrollBar::CreateButtons(const PWL_CREATEPARAM& cp) { |
| 839 | PWL_CREATEPARAM scp = cp; |
| 840 | scp.pParentWnd = this; |
| 841 | scp.dwBorderWidth = 2; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 842 | scp.nBorderStyle = BorderStyle::BEVELED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 843 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 844 | scp.dwFlags = |
| 845 | PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PWS_NOREFRESHCLIP; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 846 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 847 | if (!m_pMinButton) { |
| 848 | m_pMinButton = new CPWL_SBButton(m_sbType, PSBT_MIN); |
| 849 | m_pMinButton->Create(scp); |
| 850 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 851 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 852 | if (!m_pMaxButton) { |
| 853 | m_pMaxButton = new CPWL_SBButton(m_sbType, PSBT_MAX); |
| 854 | m_pMaxButton->Create(scp); |
| 855 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 856 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 857 | if (!m_pPosButton) { |
| 858 | m_pPosButton = new CPWL_SBButton(m_sbType, PSBT_POS); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 859 | m_pPosButton->SetVisible(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 860 | m_pPosButton->Create(scp); |
| 861 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 862 | } |
| 863 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 864 | float CPWL_ScrollBar::GetScrollBarWidth() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 865 | if (!IsVisible()) |
| 866 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 867 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 868 | return PWL_SCROLLBAR_WIDTH; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 871 | void CPWL_ScrollBar::SetScrollRange(float fMin, |
| 872 | float fMax, |
| 873 | float fClientWidth) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 874 | if (m_pPosButton) { |
| 875 | m_sData.SetScrollRange(fMin, fMax); |
| 876 | m_sData.SetClientWidth(fClientWidth); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 877 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 878 | if (IsFloatSmaller(m_sData.ScrollRange.GetWidth(), 0.0f)) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 879 | m_pPosButton->SetVisible(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 880 | } else { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 881 | m_pPosButton->SetVisible(true); |
| 882 | MovePosButton(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 883 | } |
| 884 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 887 | void CPWL_ScrollBar::SetScrollPos(float fPos) { |
| 888 | float fOldPos = m_sData.fScrollPos; |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 889 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 890 | m_sData.SetPos(fPos); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 891 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 892 | if (!IsFloatEqual(m_sData.fScrollPos, fOldPos)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 893 | MovePosButton(true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 894 | } |
| 895 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 896 | void CPWL_ScrollBar::SetScrollStep(float fBigStep, float fSmallStep) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 897 | m_sData.SetBigStep(fBigStep); |
| 898 | m_sData.SetSmallStep(fSmallStep); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 899 | } |
| 900 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 901 | void CPWL_ScrollBar::MovePosButton(bool bRefresh) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 902 | ASSERT(m_pMinButton); |
| 903 | ASSERT(m_pMaxButton); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 904 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 905 | if (m_pPosButton->IsVisible()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 906 | CFX_FloatRect rcClient; |
| 907 | CFX_FloatRect rcPosArea, rcPosButton; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 908 | |
| 909 | rcClient = GetClientRect(); |
| 910 | rcPosArea = GetScrollArea(); |
| 911 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 912 | float fLeft, fRight, fTop, fBottom; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 913 | |
| 914 | switch (m_sbType) { |
| 915 | case SBT_HSCROLL: |
| 916 | fLeft = TrueToFace(m_sData.fScrollPos); |
| 917 | fRight = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth); |
| 918 | |
| 919 | if (fRight - fLeft < PWL_SCROLLBAR_POSBUTTON_MINWIDTH) |
| 920 | fRight = fLeft + PWL_SCROLLBAR_POSBUTTON_MINWIDTH; |
| 921 | |
| 922 | if (fRight > rcPosArea.right) { |
| 923 | fRight = rcPosArea.right; |
| 924 | fLeft = fRight - PWL_SCROLLBAR_POSBUTTON_MINWIDTH; |
| 925 | } |
| 926 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 927 | rcPosButton = |
| 928 | CFX_FloatRect(fLeft, rcPosArea.bottom, fRight, rcPosArea.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 929 | |
| 930 | break; |
| 931 | case SBT_VSCROLL: |
| 932 | fBottom = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth); |
| 933 | fTop = TrueToFace(m_sData.fScrollPos); |
| 934 | |
| 935 | if (IsFloatSmaller(fTop - fBottom, PWL_SCROLLBAR_POSBUTTON_MINWIDTH)) |
| 936 | fBottom = fTop - PWL_SCROLLBAR_POSBUTTON_MINWIDTH; |
| 937 | |
| 938 | if (IsFloatSmaller(fBottom, rcPosArea.bottom)) { |
| 939 | fBottom = rcPosArea.bottom; |
| 940 | fTop = fBottom + PWL_SCROLLBAR_POSBUTTON_MINWIDTH; |
| 941 | } |
| 942 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 943 | rcPosButton = |
| 944 | CFX_FloatRect(rcPosArea.left, fBottom, rcPosArea.right, fTop); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 945 | |
| 946 | break; |
| 947 | } |
| 948 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 949 | m_pPosButton->Move(rcPosButton, true, bRefresh); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 950 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 951 | } |
| 952 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 953 | void CPWL_ScrollBar::OnMinButtonLBDown(const CFX_PointF& point) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 954 | m_sData.SubSmall(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 955 | MovePosButton(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 956 | NotifyScrollWindow(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 957 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 958 | m_bMinOrMax = true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 959 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 960 | EndTimer(); |
| 961 | BeginTimer(100); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 962 | } |
| 963 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 964 | void CPWL_ScrollBar::OnMinButtonLBUp(const CFX_PointF& point) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 965 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 966 | void CPWL_ScrollBar::OnMinButtonMouseMove(const CFX_PointF& point) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 967 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 968 | void CPWL_ScrollBar::OnMaxButtonLBDown(const CFX_PointF& point) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 969 | m_sData.AddSmall(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 970 | MovePosButton(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 971 | NotifyScrollWindow(); |
| 972 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 973 | m_bMinOrMax = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 974 | |
| 975 | EndTimer(); |
| 976 | BeginTimer(100); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 977 | } |
| 978 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 979 | void CPWL_ScrollBar::OnMaxButtonLBUp(const CFX_PointF& point) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 980 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 981 | void CPWL_ScrollBar::OnMaxButtonMouseMove(const CFX_PointF& point) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 982 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 983 | void CPWL_ScrollBar::OnPosButtonLBDown(const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 984 | m_bMouseDown = true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 985 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 986 | if (m_pPosButton) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 987 | CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 988 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 989 | switch (m_sbType) { |
| 990 | case SBT_HSCROLL: |
| 991 | m_nOldPos = point.x; |
| 992 | m_fOldPosButton = rcPosButton.left; |
| 993 | break; |
| 994 | case SBT_VSCROLL: |
| 995 | m_nOldPos = point.y; |
| 996 | m_fOldPosButton = rcPosButton.top; |
| 997 | break; |
| 998 | } |
| 999 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1002 | void CPWL_ScrollBar::OnPosButtonLBUp(const CFX_PointF& point) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1003 | if (m_bMouseDown) { |
| 1004 | if (!m_bNotifyForever) |
| 1005 | NotifyScrollWindow(); |
| 1006 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1007 | m_bMouseDown = false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1010 | void CPWL_ScrollBar::OnPosButtonMouseMove(const CFX_PointF& point) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1011 | float fOldScrollPos = m_sData.fScrollPos; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1012 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1013 | float fNewPos = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1014 | |
| 1015 | switch (m_sbType) { |
| 1016 | case SBT_HSCROLL: |
Dan Sinclair | 669a418 | 2017-04-03 14:51:45 -0400 | [diff] [blame] | 1017 | if (fabs(point.x - m_nOldPos) < 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1018 | return; |
| 1019 | fNewPos = FaceToTrue(m_fOldPosButton + point.x - m_nOldPos); |
| 1020 | break; |
| 1021 | case SBT_VSCROLL: |
Dan Sinclair | 669a418 | 2017-04-03 14:51:45 -0400 | [diff] [blame] | 1022 | if (fabs(point.y - m_nOldPos) < 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1023 | return; |
| 1024 | fNewPos = FaceToTrue(m_fOldPosButton + point.y - m_nOldPos); |
| 1025 | break; |
| 1026 | } |
| 1027 | |
| 1028 | if (m_bMouseDown) { |
| 1029 | switch (m_sbType) { |
| 1030 | case SBT_HSCROLL: |
| 1031 | |
| 1032 | if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) { |
| 1033 | fNewPos = m_sData.ScrollRange.fMin; |
| 1034 | } |
| 1035 | |
| 1036 | if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) { |
| 1037 | fNewPos = m_sData.ScrollRange.fMax; |
| 1038 | } |
| 1039 | |
| 1040 | m_sData.SetPos(fNewPos); |
| 1041 | |
| 1042 | break; |
| 1043 | case SBT_VSCROLL: |
| 1044 | |
| 1045 | if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) { |
| 1046 | fNewPos = m_sData.ScrollRange.fMin; |
| 1047 | } |
| 1048 | |
| 1049 | if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) { |
| 1050 | fNewPos = m_sData.ScrollRange.fMax; |
| 1051 | } |
| 1052 | |
| 1053 | m_sData.SetPos(fNewPos); |
| 1054 | |
| 1055 | break; |
| 1056 | } |
| 1057 | |
| 1058 | if (!IsFloatEqual(fOldScrollPos, m_sData.fScrollPos)) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1059 | MovePosButton(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1060 | |
| 1061 | if (m_bNotifyForever) |
| 1062 | NotifyScrollWindow(); |
| 1063 | } |
| 1064 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1067 | void CPWL_ScrollBar::NotifyScrollWindow() { |
| 1068 | if (CPWL_Wnd* pParent = GetParentWindow()) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1069 | float fPos; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1070 | switch (m_sbType) { |
| 1071 | case SBT_HSCROLL: |
| 1072 | fPos = m_OriginInfo.fContentMin + m_sData.fScrollPos; |
| 1073 | break; |
| 1074 | case SBT_VSCROLL: |
| 1075 | fPos = m_OriginInfo.fContentMax - m_sData.fScrollPos; |
| 1076 | break; |
| 1077 | } |
| 1078 | pParent->OnNotify(this, PNM_SCROLLWINDOW, (intptr_t)m_sbType, |
| 1079 | (intptr_t)&fPos); |
| 1080 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1081 | } |
| 1082 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1083 | CFX_FloatRect CPWL_ScrollBar::GetScrollArea() const { |
| 1084 | CFX_FloatRect rcClient = GetClientRect(); |
| 1085 | CFX_FloatRect rcArea; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1086 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1087 | if (!m_pMinButton || !m_pMaxButton) |
| 1088 | return rcClient; |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 1089 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1090 | CFX_FloatRect rcMin = m_pMinButton->GetWindowRect(); |
| 1091 | CFX_FloatRect rcMax = m_pMaxButton->GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1092 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1093 | float fMinWidth = rcMin.right - rcMin.left; |
| 1094 | float fMinHeight = rcMin.top - rcMin.bottom; |
| 1095 | float fMaxWidth = rcMax.right - rcMax.left; |
| 1096 | float fMaxHeight = rcMax.top - rcMax.bottom; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1097 | |
| 1098 | switch (m_sbType) { |
| 1099 | case SBT_HSCROLL: |
| 1100 | if (rcClient.right - rcClient.left > fMinWidth + fMaxWidth + 2) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1101 | rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom, |
| 1102 | rcClient.right - fMaxWidth - 1, rcClient.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1103 | } else { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1104 | rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom, |
| 1105 | rcClient.left + fMinWidth + 1, rcClient.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1106 | } |
| 1107 | break; |
| 1108 | case SBT_VSCROLL: |
| 1109 | if (rcClient.top - rcClient.bottom > fMinHeight + fMaxHeight + 2) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1110 | rcArea = CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1, |
| 1111 | rcClient.right, rcClient.top - fMaxHeight - 1); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1112 | } else { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1113 | rcArea = |
| 1114 | CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1, |
| 1115 | rcClient.right, rcClient.bottom + fMinHeight + 1); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1116 | } |
| 1117 | break; |
| 1118 | } |
| 1119 | |
| 1120 | rcArea.Normalize(); |
| 1121 | |
| 1122 | return rcArea; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1125 | float CPWL_ScrollBar::TrueToFace(float fTrue) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1126 | CFX_FloatRect rcPosArea; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1127 | rcPosArea = GetScrollArea(); |
| 1128 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1129 | float fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1130 | fFactWidth = fFactWidth == 0 ? 1 : fFactWidth; |
| 1131 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1132 | float fFace = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1133 | |
| 1134 | switch (m_sbType) { |
| 1135 | case SBT_HSCROLL: |
| 1136 | fFace = rcPosArea.left + |
| 1137 | fTrue * (rcPosArea.right - rcPosArea.left) / fFactWidth; |
| 1138 | break; |
| 1139 | case SBT_VSCROLL: |
| 1140 | fFace = rcPosArea.top - |
| 1141 | fTrue * (rcPosArea.top - rcPosArea.bottom) / fFactWidth; |
| 1142 | break; |
| 1143 | } |
| 1144 | |
| 1145 | return fFace; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1148 | float CPWL_ScrollBar::FaceToTrue(float fFace) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1149 | CFX_FloatRect rcPosArea; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1150 | rcPosArea = GetScrollArea(); |
| 1151 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1152 | float fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1153 | fFactWidth = fFactWidth == 0 ? 1 : fFactWidth; |
| 1154 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1155 | float fTrue = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1156 | |
| 1157 | switch (m_sbType) { |
| 1158 | case SBT_HSCROLL: |
| 1159 | fTrue = (fFace - rcPosArea.left) * fFactWidth / |
| 1160 | (rcPosArea.right - rcPosArea.left); |
| 1161 | break; |
| 1162 | case SBT_VSCROLL: |
| 1163 | fTrue = (rcPosArea.top - fFace) * fFactWidth / |
| 1164 | (rcPosArea.top - rcPosArea.bottom); |
| 1165 | break; |
| 1166 | } |
| 1167 | |
| 1168 | return fTrue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1171 | void CPWL_ScrollBar::CreateChildWnd(const PWL_CREATEPARAM& cp) { |
| 1172 | CreateButtons(cp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1175 | void CPWL_ScrollBar::TimerProc() { |
| 1176 | PWL_SCROLL_PRIVATEDATA sTemp = m_sData; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1177 | if (m_bMinOrMax) |
| 1178 | m_sData.SubSmall(); |
| 1179 | else |
| 1180 | m_sData.AddSmall(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1181 | |
tsepez | f86ca38 | 2016-09-13 12:23:30 -0700 | [diff] [blame] | 1182 | if (sTemp != m_sData) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1183 | MovePosButton(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1184 | NotifyScrollWindow(); |
| 1185 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1186 | } |