blob: 2aa2c7e35f47a3dd2ed894bb73a90e647ae720a3 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhang60f507b2015-06-13 00:41:00 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
dan sinclair89e904b2016-03-23 19:29:15 -04007#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h"
Dan Sinclairaa403d32016-03-15 14:57:22 -04008
dsinclair74a34fc2016-09-29 16:41:42 -07009#include "core/fxge/cfx_pathdata.h"
10#include "core/fxge/cfx_renderdevice.h"
dan sinclair89e904b2016-03-23 19:29:15 -040011#include "fpdfsdk/pdfwindow/PWL_Utils.h"
12#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070013
Nico Weber9d8ec5a2015-08-04 13:00:21 -070014PWL_FLOATRANGE::PWL_FLOATRANGE() {
15 Default();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070016}
17
Nico Weber9d8ec5a2015-08-04 13:00:21 -070018PWL_FLOATRANGE::PWL_FLOATRANGE(FX_FLOAT min, FX_FLOAT max) {
19 Set(min, max);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020}
21
Nico Weber9d8ec5a2015-08-04 13:00:21 -070022void PWL_FLOATRANGE::Default() {
23 fMin = 0;
24 fMax = 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025}
26
Nico Weber9d8ec5a2015-08-04 13:00:21 -070027void 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-Malek3f3b45c2014-05-23 17:28:10 -070035}
36
tsepez4cf55152016-11-02 14:37:54 -070037bool PWL_FLOATRANGE::In(FX_FLOAT x) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070038 return (IsFloatBigger(x, fMin) || IsFloatEqual(x, fMin)) &&
39 (IsFloatSmaller(x, fMax) || IsFloatEqual(x, fMax));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070040}
41
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042FX_FLOAT PWL_FLOATRANGE::GetWidth() const {
43 return fMax - fMin;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044}
45
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046PWL_SCROLL_PRIVATEDATA::PWL_SCROLL_PRIVATEDATA() {
47 Default();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070048}
49
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050void PWL_SCROLL_PRIVATEDATA::Default() {
51 ScrollRange.Default();
52 fScrollPos = ScrollRange.fMin;
53 fClientWidth = 0;
54 fBigStep = 10;
55 fSmallStep = 1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070056}
57
Nico Weber9d8ec5a2015-08-04 13:00:21 -070058void PWL_SCROLL_PRIVATEDATA::SetScrollRange(FX_FLOAT min, FX_FLOAT max) {
59 ScrollRange.Set(min, max);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070060
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061 if (IsFloatSmaller(fScrollPos, ScrollRange.fMin))
62 fScrollPos = ScrollRange.fMin;
63 if (IsFloatBigger(fScrollPos, ScrollRange.fMax))
64 fScrollPos = ScrollRange.fMax;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065}
66
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067void PWL_SCROLL_PRIVATEDATA::SetClientWidth(FX_FLOAT width) {
68 fClientWidth = width;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070069}
70
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071void PWL_SCROLL_PRIVATEDATA::SetSmallStep(FX_FLOAT step) {
72 fSmallStep = step;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070073}
74
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075void PWL_SCROLL_PRIVATEDATA::SetBigStep(FX_FLOAT step) {
76 fBigStep = step;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070077}
78
tsepez4cf55152016-11-02 14:37:54 -070079bool PWL_SCROLL_PRIVATEDATA::SetPos(FX_FLOAT pos) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 if (ScrollRange.In(pos)) {
81 fScrollPos = pos;
tsepez4cf55152016-11-02 14:37:54 -070082 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 }
tsepez4cf55152016-11-02 14:37:54 -070084 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070085}
86
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087void PWL_SCROLL_PRIVATEDATA::AddSmall() {
88 if (!SetPos(fScrollPos + fSmallStep))
89 SetPos(ScrollRange.fMax);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090}
91
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092void PWL_SCROLL_PRIVATEDATA::SubSmall() {
93 if (!SetPos(fScrollPos - fSmallStep))
94 SetPos(ScrollRange.fMin);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095}
96
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097void PWL_SCROLL_PRIVATEDATA::AddBig() {
98 if (!SetPos(fScrollPos + fBigStep))
99 SetPos(ScrollRange.fMax);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100}
101
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102void PWL_SCROLL_PRIVATEDATA::SubBig() {
103 if (!SetPos(fScrollPos - fBigStep))
104 SetPos(ScrollRange.fMin);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700105}
106
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107CPWL_SBButton::CPWL_SBButton(PWL_SCROLLBAR_TYPE eScrollBarType,
108 PWL_SBBUTTON_TYPE eButtonType) {
109 m_eScrollBarType = eScrollBarType;
110 m_eSBButtonType = eButtonType;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700111
tsepez4cf55152016-11-02 14:37:54 -0700112 m_bMouseDown = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113}
114
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700115CPWL_SBButton::~CPWL_SBButton() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700116
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117CFX_ByteString CPWL_SBButton::GetClassName() const {
118 return "CPWL_SBButton";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700119}
120
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121void CPWL_SBButton::OnCreate(PWL_CREATEPARAM& cp) {
122 cp.eCursorType = FXCT_ARROW;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700123}
124
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125void CPWL_SBButton::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
126 CPWL_Wnd::GetThisAppearanceStream(sAppStream);
127
128 if (!IsVisible())
129 return;
130
131 CFX_ByteTextBuf sButton;
132
Tom Sepez281a9ea2016-02-26 14:24:28 -0800133 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700134
135 if (rectWnd.IsEmpty())
136 return;
137
138 sAppStream << "q\n";
139
Dan Sinclairf528eee2017-02-14 11:52:07 -0500140 CFX_PointF ptCenter = GetCenterPoint();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700141
142 switch (m_eScrollBarType) {
143 case SBT_HSCROLL:
144 switch (m_eSBButtonType) {
145 case PSBT_MIN: {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500146 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 Weber9d8ec5a2015-08-04 13:00:21 -0700151
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 Sinclairf528eee2017-02-14 11:52:07 -0500164 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 Weber9d8ec5a2015-08-04 13:00:21 -0700169
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 Sinclairf528eee2017-02-14 11:52:07 -0500188 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 Weber9d8ec5a2015-08-04 13:00:21 -0700193
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 Sinclairf528eee2017-02-14 11:52:07 -0500206 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 Weber9d8ec5a2015-08-04 13:00:21 -0700211
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-Malek3f3b45c2014-05-23 17:28:10 -0700232}
233
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800235 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236 if (!IsVisible())
237 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700238
Tom Sepez281a9ea2016-02-26 14:24:28 -0800239 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240 if (rectWnd.IsEmpty())
241 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700242
Dan Sinclairf528eee2017-02-14 11:52:07 -0500243 CFX_PointF ptCenter = GetCenterPoint();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244 int32_t nTransparancy = GetTransparency();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700245
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246 switch (m_eScrollBarType) {
247 case SBT_HSCROLL:
248 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
249 switch (m_eSBButtonType) {
250 case PSBT_MIN: {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500251 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-Malek3f3b45c2014-05-23 17:28:10 -0700256
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700257 if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
258 rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) {
259 CFX_PathData path;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700260
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261 path.SetPointCount(4);
Nicolas Pena79365f72017-02-07 14:21:36 -0500262 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-Malek3f3b45c2014-05-23 17:28:10 -0700266
thestig1cd352e2016-06-07 17:53:06 -0700267 pDevice->DrawPath(&path, pUser2Device, nullptr,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700268 CPWL_Utils::PWLColorToFXColor(
269 PWL_DEFAULT_BLACKCOLOR, nTransparancy),
270 0, FXFILL_ALTERNATE);
271 }
272 } break;
273 case PSBT_MAX: {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500274 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-Malek3f3b45c2014-05-23 17:28:10 -0700279
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280 if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
281 rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) {
282 CFX_PathData path;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700283
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700284 path.SetPointCount(4);
Nicolas Pena79365f72017-02-07 14:21:36 -0500285 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-Malek3f3b45c2014-05-23 17:28:10 -0700289
thestig1cd352e2016-06-07 17:53:06 -0700290 pDevice->DrawPath(&path, pUser2Device, nullptr,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700291 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 Sepez281a9ea2016-02-26 14:24:28 -0800304 CFX_FloatRect rcDraw = rectWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700305 CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
306 ArgbEncode(nTransparancy, 100, 100, 100),
307 0.0f);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700308
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 // 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-Malek3f3b45c2014-05-23 17:28:10 -0700314
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315 // draw background
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700316
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317 rcDraw = CPWL_Utils::DeflateRect(rectWnd, 1.0f);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700318
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319 if (IsEnabled())
tsepez4cf55152016-11-02 14:37:54 -0700320 CPWL_Utils::DrawShadow(pDevice, pUser2Device, true, false, rcDraw,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700321 nTransparancy, 80, 220);
322 else
323 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw,
324 ArgbEncode(255, 255, 255, 255));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700325
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700326 // draw arrow
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700327
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328 if (rectWnd.top - rectWnd.bottom > 6.0f) {
329 FX_FLOAT fX = rectWnd.left + 1.5f;
330 FX_FLOAT fY = rectWnd.bottom;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500331 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-Malek3f3b45c2014-05-23 17:28:10 -0700338
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700339 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 Sepez281a9ea2016-02-26 14:24:28 -0800351 CFX_FloatRect rcDraw = rectWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700352 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())
tsepez4cf55152016-11-02 14:37:54 -0700365 CPWL_Utils::DrawShadow(pDevice, pUser2Device, true, false, rcDraw,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366 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 Sinclairf528eee2017-02-14 11:52:07 -0500377 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 Weber9d8ec5a2015-08-04 13:00:21 -0700384
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 Weber9d8ec5a2015-08-04 13:00:21 -0700396 // draw border
Tom Sepez281a9ea2016-02-26 14:24:28 -0800397 CFX_FloatRect rcDraw = rectWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700398 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 Sinclairf528eee2017-02-14 11:52:07 -0500411 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 Weber9d8ec5a2015-08-04 13:00:21 -0700414
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 Sinclairf528eee2017-02-14 11:52:07 -0500500 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 Weber9d8ec5a2015-08-04 13:00:21 -0700506
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 Weber9d8ec5a2015-08-04 13:00:21 -0700521 }
522 } break;
523 default:
524 break;
525 }
526 break;
527 default:
528 break;
529 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700530}
531
Dan Sinclairf528eee2017-02-14 11:52:07 -0500532bool CPWL_SBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700534
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535 if (CPWL_Wnd* pParent = GetParentWindow())
536 pParent->OnNotify(this, PNM_LBUTTONDOWN, 0, (intptr_t)&point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700537
tsepez4cf55152016-11-02 14:37:54 -0700538 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539 SetCapture();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700540
tsepez4cf55152016-11-02 14:37:54 -0700541 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700542}
543
Dan Sinclairf528eee2017-02-14 11:52:07 -0500544bool CPWL_SBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700545 CPWL_Wnd::OnLButtonUp(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700546
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 if (CPWL_Wnd* pParent = GetParentWindow())
548 pParent->OnNotify(this, PNM_LBUTTONUP, 0, (intptr_t)&point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700549
tsepez4cf55152016-11-02 14:37:54 -0700550 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700551 ReleaseCapture();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700552
tsepez4cf55152016-11-02 14:37:54 -0700553 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700554}
555
Dan Sinclairf528eee2017-02-14 11:52:07 -0500556bool CPWL_SBButton::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 CPWL_Wnd::OnMouseMove(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700558
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559 if (CPWL_Wnd* pParent = GetParentWindow()) {
560 pParent->OnNotify(this, PNM_MOUSEMOVE, 0, (intptr_t)&point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700562
tsepez4cf55152016-11-02 14:37:54 -0700563 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700564}
565
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566CPWL_ScrollBar::CPWL_ScrollBar(PWL_SCROLLBAR_TYPE sbType)
567 : m_sbType(sbType),
thestig1cd352e2016-06-07 17:53:06 -0700568 m_pMinButton(nullptr),
569 m_pMaxButton(nullptr),
570 m_pPosButton(nullptr),
tsepez4cf55152016-11-02 14:37:54 -0700571 m_bMouseDown(false),
572 m_bMinOrMax(false),
573 m_bNotifyForever(true) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700574
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575CPWL_ScrollBar::~CPWL_ScrollBar() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700576
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700577CFX_ByteString CPWL_ScrollBar::GetClassName() const {
578 return "CPWL_ScrollBar";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700579}
580
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581void CPWL_ScrollBar::OnCreate(PWL_CREATEPARAM& cp) {
582 cp.eCursorType = FXCT_ARROW;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700583}
584
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585void CPWL_ScrollBar::RePosChildWnd() {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800586 CFX_FloatRect rcClient = GetClientRect();
587 CFX_FloatRect rcMinButton, rcMaxButton;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700588 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 Sepez281a9ea2016-02-26 14:24:28 -0800595 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 Weber9d8ec5a2015-08-04 13:00:21 -0700601 } else {
602 fBWidth = (rcClient.right - rcClient.left -
603 PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) /
604 2;
605
606 if (fBWidth > 0) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800607 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 Zhangc2fb35f2016-01-05 16:46:58 -0800611 } else {
tsepez4cf55152016-11-02 14:37:54 -0700612 SetVisible(false);
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800613 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 }
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 Sepez281a9ea2016-02-26 14:24:28 -0800620 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 Weber9d8ec5a2015-08-04 13:00:21 -0700626 } else {
627 fBWidth = (rcClient.top - rcClient.bottom -
628 PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) /
629 2;
630
631 if (IsFloatBigger(fBWidth, 0)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800632 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 Zhangc2fb35f2016-01-05 16:46:58 -0800637 } else {
tsepez4cf55152016-11-02 14:37:54 -0700638 SetVisible(false);
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800639 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700640 }
641 break;
642 }
643
644 if (m_pMinButton)
tsepez4cf55152016-11-02 14:37:54 -0700645 m_pMinButton->Move(rcMinButton, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700646 if (m_pMaxButton)
tsepez4cf55152016-11-02 14:37:54 -0700647 m_pMaxButton->Move(rcMaxButton, true, false);
648 MovePosButton(false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700649}
650
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700651void CPWL_ScrollBar::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800652 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700653
654 if (IsVisible() && !rectWnd.IsEmpty()) {
655 CFX_ByteTextBuf sButton;
656
657 sButton << "q\n";
658 sButton << "0 w\n"
tsepez4cf55152016-11-02 14:37:54 -0700659 << CPWL_Utils::GetColorAppStream(GetBackgroundColor(), true)
tsepez4c3debb2016-04-08 12:20:38 -0700660 .AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700661 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-Malek3f3b45c2014-05-23 17:28:10 -0700667}
668
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669void CPWL_ScrollBar::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800670 CFX_Matrix* pUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800671 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700672
673 if (IsVisible() && !rectWnd.IsEmpty()) {
674 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rectWnd,
675 GetBackgroundColor(), GetTransparency());
676
677 CPWL_Utils::DrawStrokeLine(
678 pDevice, pUser2Device,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500679 CFX_PointF(rectWnd.left + 2.0f, rectWnd.top - 2.0f),
680 CFX_PointF(rectWnd.left + 2.0f, rectWnd.bottom + 2.0f),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681 ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f);
682
683 CPWL_Utils::DrawStrokeLine(
684 pDevice, pUser2Device,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500685 CFX_PointF(rectWnd.right - 2.0f, rectWnd.top - 2.0f),
686 CFX_PointF(rectWnd.right - 2.0f, rectWnd.bottom + 2.0f),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700687 ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f);
688 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700689}
690
Dan Sinclairf528eee2017-02-14 11:52:07 -0500691bool CPWL_ScrollBar::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700693
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700694 if (HasFlag(PWS_AUTOTRANSPARENT)) {
695 if (GetTransparency() != 255) {
696 SetTransparency(255);
697 InvalidateRect();
698 }
699 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700700
Tom Sepez281a9ea2016-02-26 14:24:28 -0800701 CFX_FloatRect rcMinArea, rcMaxArea;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700702
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700703 if (m_pPosButton && m_pPosButton->IsVisible()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800704 CFX_FloatRect rcClient = GetClientRect();
705 CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect();
Lei Zhang60f507b2015-06-13 00:41:00 -0700706
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707 switch (m_sbType) {
708 case SBT_HSCROLL:
Tom Sepez281a9ea2016-02-26 14:24:28 -0800709 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 Weber9d8ec5a2015-08-04 13:00:21 -0700715
716 break;
717 case SBT_VSCROLL:
Tom Sepez281a9ea2016-02-26 14:24:28 -0800718 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 Weber9d8ec5a2015-08-04 13:00:21 -0700724 break;
725 }
726
727 rcMinArea.Normalize();
728 rcMaxArea.Normalize();
729
730 if (rcMinArea.Contains(point.x, point.y)) {
731 m_sData.SubBig();
tsepez4cf55152016-11-02 14:37:54 -0700732 MovePosButton(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700733 NotifyScrollWindow();
734 }
735
736 if (rcMaxArea.Contains(point.x, point.y)) {
737 m_sData.AddBig();
tsepez4cf55152016-11-02 14:37:54 -0700738 MovePosButton(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739 NotifyScrollWindow();
740 }
741 }
742
tsepez4cf55152016-11-02 14:37:54 -0700743 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700744}
745
Dan Sinclairf528eee2017-02-14 11:52:07 -0500746bool CPWL_ScrollBar::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747 CPWL_Wnd::OnLButtonUp(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700748
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700749 if (HasFlag(PWS_AUTOTRANSPARENT)) {
750 if (GetTransparency() != PWL_SCROLLBAR_TRANSPARANCY) {
751 SetTransparency(PWL_SCROLLBAR_TRANSPARANCY);
752 InvalidateRect();
753 }
754 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700755
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700756 EndTimer();
tsepez4cf55152016-11-02 14:37:54 -0700757 m_bMouseDown = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700758
tsepez4cf55152016-11-02 14:37:54 -0700759 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700760}
761
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700762void CPWL_ScrollBar::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -0700763 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700764 intptr_t wParam,
765 intptr_t lParam) {
766 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700767
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700768 switch (msg) {
769 case PNM_LBUTTONDOWN:
770 if (pWnd == m_pMinButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500771 OnMinButtonLBDown(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700772 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700773
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700774 if (pWnd == m_pMaxButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500775 OnMaxButtonLBDown(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700776 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700777
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700778 if (pWnd == m_pPosButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500779 OnPosButtonLBDown(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700780 }
781 break;
782 case PNM_LBUTTONUP:
783 if (pWnd == m_pMinButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500784 OnMinButtonLBUp(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700785 }
786
787 if (pWnd == m_pMaxButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500788 OnMaxButtonLBUp(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700789 }
790
791 if (pWnd == m_pPosButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500792 OnPosButtonLBUp(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700793 }
794 break;
795 case PNM_MOUSEMOVE:
796 if (pWnd == m_pMinButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500797 OnMinButtonMouseMove(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700798 }
799
800 if (pWnd == m_pMaxButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500801 OnMaxButtonMouseMove(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700802 }
803
804 if (pWnd == m_pPosButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500805 OnPosButtonMouseMove(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700806 }
807 break;
808 case PNM_SETSCROLLINFO: {
tsepezf86ca382016-09-13 12:23:30 -0700809 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 Weber9d8ec5a2015-08-04 13:00:21 -0700817 }
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-Malek3f3b45c2014-05-23 17:28:10 -0700832}
833
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700834void CPWL_ScrollBar::CreateButtons(const PWL_CREATEPARAM& cp) {
835 PWL_CREATEPARAM scp = cp;
836 scp.pParentWnd = this;
837 scp.dwBorderWidth = 2;
dsinclair92cb5e52016-05-16 11:38:28 -0700838 scp.nBorderStyle = BorderStyle::BEVELED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700839
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700840 scp.dwFlags =
841 PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PWS_NOREFRESHCLIP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700842
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700843 if (!m_pMinButton) {
844 m_pMinButton = new CPWL_SBButton(m_sbType, PSBT_MIN);
845 m_pMinButton->Create(scp);
846 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700847
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700848 if (!m_pMaxButton) {
849 m_pMaxButton = new CPWL_SBButton(m_sbType, PSBT_MAX);
850 m_pMaxButton->Create(scp);
851 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700852
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700853 if (!m_pPosButton) {
854 m_pPosButton = new CPWL_SBButton(m_sbType, PSBT_POS);
tsepez4cf55152016-11-02 14:37:54 -0700855 m_pPosButton->SetVisible(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700856 m_pPosButton->Create(scp);
857 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700858}
859
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700860FX_FLOAT CPWL_ScrollBar::GetScrollBarWidth() const {
861 if (!IsVisible())
862 return 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700863
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700864 return PWL_SCROLLBAR_WIDTH;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700865}
866
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700867void 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-Malek3f3b45c2014-05-23 17:28:10 -0700873
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700874 if (IsFloatSmaller(m_sData.ScrollRange.GetWidth(), 0.0f)) {
tsepez4cf55152016-11-02 14:37:54 -0700875 m_pPosButton->SetVisible(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700876 } else {
tsepez4cf55152016-11-02 14:37:54 -0700877 m_pPosButton->SetVisible(true);
878 MovePosButton(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700879 }
880 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700881}
882
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700883void CPWL_ScrollBar::SetScrollPos(FX_FLOAT fPos) {
884 FX_FLOAT fOldPos = m_sData.fScrollPos;
Lei Zhang60f507b2015-06-13 00:41:00 -0700885
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700886 m_sData.SetPos(fPos);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700887
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700888 if (!IsFloatEqual(m_sData.fScrollPos, fOldPos))
tsepez4cf55152016-11-02 14:37:54 -0700889 MovePosButton(true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700890}
891
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700892void CPWL_ScrollBar::SetScrollStep(FX_FLOAT fBigStep, FX_FLOAT fSmallStep) {
893 m_sData.SetBigStep(fBigStep);
894 m_sData.SetSmallStep(fSmallStep);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700895}
896
tsepez4cf55152016-11-02 14:37:54 -0700897void CPWL_ScrollBar::MovePosButton(bool bRefresh) {
Lei Zhang96660d62015-12-14 18:27:25 -0800898 ASSERT(m_pMinButton);
899 ASSERT(m_pMaxButton);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700900
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700901 if (m_pPosButton->IsVisible()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800902 CFX_FloatRect rcClient;
903 CFX_FloatRect rcPosArea, rcPosButton;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700904
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 Sepez281a9ea2016-02-26 14:24:28 -0800923 rcPosButton =
924 CFX_FloatRect(fLeft, rcPosArea.bottom, fRight, rcPosArea.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700925
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 Sepez281a9ea2016-02-26 14:24:28 -0800939 rcPosButton =
940 CFX_FloatRect(rcPosArea.left, fBottom, rcPosArea.right, fTop);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700941
942 break;
943 }
944
tsepez4cf55152016-11-02 14:37:54 -0700945 m_pPosButton->Move(rcPosButton, true, bRefresh);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700946 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700947}
948
Dan Sinclairf528eee2017-02-14 11:52:07 -0500949void CPWL_ScrollBar::OnMinButtonLBDown(const CFX_PointF& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700950 m_sData.SubSmall();
tsepez4cf55152016-11-02 14:37:54 -0700951 MovePosButton(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700952 NotifyScrollWindow();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700953
tsepez4cf55152016-11-02 14:37:54 -0700954 m_bMinOrMax = true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700955
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700956 EndTimer();
957 BeginTimer(100);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700958}
959
Dan Sinclairf528eee2017-02-14 11:52:07 -0500960void CPWL_ScrollBar::OnMinButtonLBUp(const CFX_PointF& point) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700961
Dan Sinclairf528eee2017-02-14 11:52:07 -0500962void CPWL_ScrollBar::OnMinButtonMouseMove(const CFX_PointF& point) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700963
Dan Sinclairf528eee2017-02-14 11:52:07 -0500964void CPWL_ScrollBar::OnMaxButtonLBDown(const CFX_PointF& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700965 m_sData.AddSmall();
tsepez4cf55152016-11-02 14:37:54 -0700966 MovePosButton(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700967 NotifyScrollWindow();
968
tsepez4cf55152016-11-02 14:37:54 -0700969 m_bMinOrMax = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700970
971 EndTimer();
972 BeginTimer(100);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700973}
974
Dan Sinclairf528eee2017-02-14 11:52:07 -0500975void CPWL_ScrollBar::OnMaxButtonLBUp(const CFX_PointF& point) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700976
Dan Sinclairf528eee2017-02-14 11:52:07 -0500977void CPWL_ScrollBar::OnMaxButtonMouseMove(const CFX_PointF& point) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700978
Dan Sinclairf528eee2017-02-14 11:52:07 -0500979void CPWL_ScrollBar::OnPosButtonLBDown(const CFX_PointF& point) {
tsepez4cf55152016-11-02 14:37:54 -0700980 m_bMouseDown = true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700981
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700982 if (m_pPosButton) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800983 CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700984
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700985 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-Malek3f3b45c2014-05-23 17:28:10 -0700996}
997
Dan Sinclairf528eee2017-02-14 11:52:07 -0500998void CPWL_ScrollBar::OnPosButtonLBUp(const CFX_PointF& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700999 if (m_bMouseDown) {
1000 if (!m_bNotifyForever)
1001 NotifyScrollWindow();
1002 }
tsepez4cf55152016-11-02 14:37:54 -07001003 m_bMouseDown = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001004}
1005
Dan Sinclairf528eee2017-02-14 11:52:07 -05001006void CPWL_ScrollBar::OnPosButtonMouseMove(const CFX_PointF& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001007 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)) {
tsepez4cf55152016-11-02 14:37:54 -07001055 MovePosButton(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001056
1057 if (m_bNotifyForever)
1058 NotifyScrollWindow();
1059 }
1060 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001061}
1062
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001063void 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-Malek3f3b45c2014-05-23 17:28:10 -07001077}
1078
Tom Sepez281a9ea2016-02-26 14:24:28 -08001079CFX_FloatRect CPWL_ScrollBar::GetScrollArea() const {
1080 CFX_FloatRect rcClient = GetClientRect();
1081 CFX_FloatRect rcArea;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001082
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001083 if (!m_pMinButton || !m_pMaxButton)
1084 return rcClient;
Lei Zhang60f507b2015-06-13 00:41:00 -07001085
Tom Sepez281a9ea2016-02-26 14:24:28 -08001086 CFX_FloatRect rcMin = m_pMinButton->GetWindowRect();
1087 CFX_FloatRect rcMax = m_pMaxButton->GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001088
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 Sepez281a9ea2016-02-26 14:24:28 -08001097 rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom,
1098 rcClient.right - fMaxWidth - 1, rcClient.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001099 } else {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001100 rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom,
1101 rcClient.left + fMinWidth + 1, rcClient.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001102 }
1103 break;
1104 case SBT_VSCROLL:
1105 if (rcClient.top - rcClient.bottom > fMinHeight + fMaxHeight + 2) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001106 rcArea = CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1,
1107 rcClient.right, rcClient.top - fMaxHeight - 1);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001108 } else {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001109 rcArea =
1110 CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1,
1111 rcClient.right, rcClient.bottom + fMinHeight + 1);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001112 }
1113 break;
1114 }
1115
1116 rcArea.Normalize();
1117
1118 return rcArea;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001119}
1120
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001121FX_FLOAT CPWL_ScrollBar::TrueToFace(FX_FLOAT fTrue) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001122 CFX_FloatRect rcPosArea;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001123 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-Malek3f3b45c2014-05-23 17:28:10 -07001142}
1143
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001144FX_FLOAT CPWL_ScrollBar::FaceToTrue(FX_FLOAT fFace) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001145 CFX_FloatRect rcPosArea;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001146 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-Malek3f3b45c2014-05-23 17:28:10 -07001165}
1166
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001167void CPWL_ScrollBar::CreateChildWnd(const PWL_CREATEPARAM& cp) {
1168 CreateButtons(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001169}
1170
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001171void CPWL_ScrollBar::TimerProc() {
1172 PWL_SCROLL_PRIVATEDATA sTemp = m_sData;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001173 if (m_bMinOrMax)
1174 m_sData.SubSmall();
1175 else
1176 m_sData.AddSmall();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001177
tsepezf86ca382016-09-13 12:23:30 -07001178 if (sTemp != m_sData) {
tsepez4cf55152016-11-02 14:37:54 -07001179 MovePosButton(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001180 NotifyScrollWindow();
1181 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001182}