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