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