blob: 2f234b243220b613940b1c5729eb331c3845f255 [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
Lei Zhang633a3b72017-06-02 15:27:22 -07007#include "fpdfsdk/pdfwindow/cpwl_scroll_bar.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"
Lei Zhang633a3b72017-06-02 15:27:22 -070011#include "fpdfsdk/pdfwindow/cpwl_utils.h"
12#include "fpdfsdk/pdfwindow/cpwl_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
Dan Sinclair05df0752017-03-14 14:43:42 -040018PWL_FLOATRANGE::PWL_FLOATRANGE(float min, float max) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070019 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
Dan Sinclair05df0752017-03-14 14:43:42 -040027void PWL_FLOATRANGE::Set(float min, float max) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028 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
Dan Sinclair05df0752017-03-14 14:43:42 -040037bool PWL_FLOATRANGE::In(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
Dan Sinclair05df0752017-03-14 14:43:42 -040042float PWL_FLOATRANGE::GetWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043 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
Dan Sinclair05df0752017-03-14 14:43:42 -040058void PWL_SCROLL_PRIVATEDATA::SetScrollRange(float min, float max) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059 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
Dan Sinclair05df0752017-03-14 14:43:42 -040067void PWL_SCROLL_PRIVATEDATA::SetClientWidth(float width) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 fClientWidth = width;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070069}
70
Dan Sinclair05df0752017-03-14 14:43:42 -040071void PWL_SCROLL_PRIVATEDATA::SetSmallStep(float step) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 fSmallStep = step;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070073}
74
Dan Sinclair05df0752017-03-14 14:43:42 -040075void PWL_SCROLL_PRIVATEDATA::SetBigStep(float step) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076 fBigStep = step;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070077}
78
Dan Sinclair05df0752017-03-14 14:43:42 -040079bool PWL_SCROLL_PRIVATEDATA::SetPos(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();
Dan Sinclairfc54e052017-02-23 09:59:05 -0500244 int32_t nTransparency = 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;
dan sinclairb147e072017-02-22 19:56:15 -0500260 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-Malek3f3b45c2014-05-23 17:28:10 -0700264
thestig1cd352e2016-06-07 17:53:06 -0700265 pDevice->DrawPath(&path, pUser2Device, nullptr,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500266 PWL_DEFAULT_BLACKCOLOR.ToFXColor(nTransparency),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700267 0, FXFILL_ALTERNATE);
268 }
269 } break;
270 case PSBT_MAX: {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500271 CFX_PointF pt1(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y);
272 CFX_PointF pt2(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,
273 ptCenter.y + PWL_TRIANGLE_HALFLEN);
274 CFX_PointF pt3(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f,
275 ptCenter.y - PWL_TRIANGLE_HALFLEN);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700276
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277 if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 &&
278 rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) {
279 CFX_PathData path;
dan sinclairb147e072017-02-22 19:56:15 -0500280 path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false);
281 path.AppendPoint(pt2, FXPT_TYPE::LineTo, false);
282 path.AppendPoint(pt3, FXPT_TYPE::LineTo, false);
283 path.AppendPoint(pt1, FXPT_TYPE::LineTo, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700284
thestig1cd352e2016-06-07 17:53:06 -0700285 pDevice->DrawPath(&path, pUser2Device, nullptr,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500286 PWL_DEFAULT_BLACKCOLOR.ToFXColor(nTransparency),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287 0, FXFILL_ALTERNATE);
288 }
289 } break;
290 default:
291 break;
292 }
293 break;
294 case SBT_VSCROLL:
295 switch (m_eSBButtonType) {
296 case PSBT_MIN: {
297 // draw border
Tom Sepez281a9ea2016-02-26 14:24:28 -0800298 CFX_FloatRect rcDraw = rectWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700299 CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500300 ArgbEncode(nTransparency, 100, 100, 100),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301 0.0f);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700302
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303 // draw inner border
304 rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f);
305 CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500306 ArgbEncode(nTransparency, 255, 255, 255),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307 1.0f);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700308
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 // draw background
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700310
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700311 rcDraw = CPWL_Utils::DeflateRect(rectWnd, 1.0f);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700312
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700313 if (IsEnabled())
tsepez4cf55152016-11-02 14:37:54 -0700314 CPWL_Utils::DrawShadow(pDevice, pUser2Device, true, false, rcDraw,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500315 nTransparency, 80, 220);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700316 else
317 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw,
318 ArgbEncode(255, 255, 255, 255));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700319
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700320 // draw arrow
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700321
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700322 if (rectWnd.top - rectWnd.bottom > 6.0f) {
Dan Sinclair05df0752017-03-14 14:43:42 -0400323 float fX = rectWnd.left + 1.5f;
324 float fY = rectWnd.bottom;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500325 CFX_PointF pts[7] = {CFX_PointF(fX + 2.5f, fY + 4.0f),
326 CFX_PointF(fX + 2.5f, fY + 3.0f),
327 CFX_PointF(fX + 4.5f, fY + 5.0f),
328 CFX_PointF(fX + 6.5f, fY + 3.0f),
329 CFX_PointF(fX + 6.5f, fY + 4.0f),
330 CFX_PointF(fX + 4.5f, fY + 6.0f),
331 CFX_PointF(fX + 2.5f, fY + 4.0f)};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700332
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333 if (IsEnabled())
334 CPWL_Utils::DrawFillArea(
335 pDevice, pUser2Device, pts, 7,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500336 ArgbEncode(nTransparency, 255, 255, 255));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700337 else
Dan Sinclairfc54e052017-02-23 09:59:05 -0500338 CPWL_Utils::DrawFillArea(
339 pDevice, pUser2Device, pts, 7,
340 PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700341 }
342 } break;
343 case PSBT_MAX: {
344 // draw border
Tom Sepez281a9ea2016-02-26 14:24:28 -0800345 CFX_FloatRect rcDraw = rectWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700346 CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500347 ArgbEncode(nTransparency, 100, 100, 100),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700348 0.0f);
349
350 // draw inner border
351 rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f);
352 CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500353 ArgbEncode(nTransparency, 255, 255, 255),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 1.0f);
355
356 // draw background
357 rcDraw = CPWL_Utils::DeflateRect(rectWnd, 1.0f);
358 if (IsEnabled())
tsepez4cf55152016-11-02 14:37:54 -0700359 CPWL_Utils::DrawShadow(pDevice, pUser2Device, true, false, rcDraw,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500360 nTransparency, 80, 220);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700361 else
362 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw,
363 ArgbEncode(255, 255, 255, 255));
364
365 // draw arrow
366
367 if (rectWnd.top - rectWnd.bottom > 6.0f) {
Dan Sinclair05df0752017-03-14 14:43:42 -0400368 float fX = rectWnd.left + 1.5f;
369 float fY = rectWnd.bottom;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700370
Dan Sinclairf528eee2017-02-14 11:52:07 -0500371 CFX_PointF pts[7] = {CFX_PointF(fX + 2.5f, fY + 5.0f),
372 CFX_PointF(fX + 2.5f, fY + 6.0f),
373 CFX_PointF(fX + 4.5f, fY + 4.0f),
374 CFX_PointF(fX + 6.5f, fY + 6.0f),
375 CFX_PointF(fX + 6.5f, fY + 5.0f),
376 CFX_PointF(fX + 4.5f, fY + 3.0f),
377 CFX_PointF(fX + 2.5f, fY + 5.0f)};
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700378
379 if (IsEnabled())
380 CPWL_Utils::DrawFillArea(
381 pDevice, pUser2Device, pts, 7,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500382 ArgbEncode(nTransparency, 255, 255, 255));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383 else
Dan Sinclairfc54e052017-02-23 09:59:05 -0500384 CPWL_Utils::DrawFillArea(
385 pDevice, pUser2Device, pts, 7,
386 PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387 }
388 } break;
389 case PSBT_POS: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700390 // draw border
Tom Sepez281a9ea2016-02-26 14:24:28 -0800391 CFX_FloatRect rcDraw = rectWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392 CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500393 ArgbEncode(nTransparency, 100, 100, 100),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700394 0.0f);
395
396 // draw inner border
397 rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f);
398 CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500399 ArgbEncode(nTransparency, 255, 255, 255),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700400 1.0f);
401
402 if (IsEnabled()) {
403 // draw shadow effect
404
Dan Sinclairf528eee2017-02-14 11:52:07 -0500405 CFX_PointF ptTop = CFX_PointF(rectWnd.left, rectWnd.top - 1.0f);
406 CFX_PointF ptBottom =
407 CFX_PointF(rectWnd.left, rectWnd.bottom + 1.0f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700408
409 ptTop.x += 1.5f;
410 ptBottom.x += 1.5f;
411
412 CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500413 ArgbEncode(nTransparency, 210, 210, 210),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414 1.0f);
415
416 ptTop.x += 1.0f;
417 ptBottom.x += 1.0f;
418
419 CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500420 ArgbEncode(nTransparency, 220, 220, 220),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700421 1.0f);
422
423 ptTop.x += 1.0f;
424 ptBottom.x += 1.0f;
425
426 CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500427 ArgbEncode(nTransparency, 240, 240, 240),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428 1.0f);
429
430 ptTop.x += 1.0f;
431 ptBottom.x += 1.0f;
432
433 CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500434 ArgbEncode(nTransparency, 240, 240, 240),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435 1.0f);
436
437 ptTop.x += 1.0f;
438 ptBottom.x += 1.0f;
439
440 CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500441 ArgbEncode(nTransparency, 210, 210, 210),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442 1.0f);
443
444 ptTop.x += 1.0f;
445 ptBottom.x += 1.0f;
446
447 CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500448 ArgbEncode(nTransparency, 180, 180, 180),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449 1.0f);
450
451 ptTop.x += 1.0f;
452 ptBottom.x += 1.0f;
453
454 CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500455 ArgbEncode(nTransparency, 150, 150, 150),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 1.0f);
457
458 ptTop.x += 1.0f;
459 ptBottom.x += 1.0f;
460
461 CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500462 ArgbEncode(nTransparency, 150, 150, 150),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463 1.0f);
464
465 ptTop.x += 1.0f;
466 ptBottom.x += 1.0f;
467
468 CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500469 ArgbEncode(nTransparency, 180, 180, 180),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700470 1.0f);
471
472 ptTop.x += 1.0f;
473 ptBottom.x += 1.0f;
474
475 CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500476 ArgbEncode(nTransparency, 210, 210, 210),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700477 1.0f);
478 } else {
479 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw,
480 ArgbEncode(255, 255, 255, 255));
481 }
482
483 // draw friction
484
485 if (rectWnd.Height() > 8.0f) {
Dan Sinclairfc54e052017-02-23 09:59:05 -0500486 FX_COLORREF crStroke = ArgbEncode(nTransparency, 120, 120, 120);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700487 if (!IsEnabled())
Dan Sinclairfc54e052017-02-23 09:59:05 -0500488 crStroke = PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489
Dan Sinclair05df0752017-03-14 14:43:42 -0400490 float nFrictionWidth = 5.0f;
491 float nFrictionHeight = 5.5f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492
Dan Sinclairf528eee2017-02-14 11:52:07 -0500493 CFX_PointF ptLeft =
494 CFX_PointF(ptCenter.x - nFrictionWidth / 2.0f,
495 ptCenter.y - nFrictionHeight / 2.0f + 0.5f);
496 CFX_PointF ptRight =
497 CFX_PointF(ptCenter.x + nFrictionWidth / 2.0f,
498 ptCenter.y - nFrictionHeight / 2.0f + 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499
500 CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight,
501 crStroke, 1.0f);
502
503 ptLeft.y += 2.0f;
504 ptRight.y += 2.0f;
505
506 CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight,
507 crStroke, 1.0f);
508
509 ptLeft.y += 2.0f;
510 ptRight.y += 2.0f;
511
512 CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight,
513 crStroke, 1.0f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514 }
515 } break;
516 default:
517 break;
518 }
519 break;
520 default:
521 break;
522 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700523}
524
Dan Sinclairf528eee2017-02-14 11:52:07 -0500525bool CPWL_SBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700527
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528 if (CPWL_Wnd* pParent = GetParentWindow())
529 pParent->OnNotify(this, PNM_LBUTTONDOWN, 0, (intptr_t)&point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700530
tsepez4cf55152016-11-02 14:37:54 -0700531 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 SetCapture();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700533
tsepez4cf55152016-11-02 14:37:54 -0700534 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700535}
536
Dan Sinclairf528eee2017-02-14 11:52:07 -0500537bool CPWL_SBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 CPWL_Wnd::OnLButtonUp(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700539
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540 if (CPWL_Wnd* pParent = GetParentWindow())
541 pParent->OnNotify(this, PNM_LBUTTONUP, 0, (intptr_t)&point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700542
tsepez4cf55152016-11-02 14:37:54 -0700543 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544 ReleaseCapture();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700545
tsepez4cf55152016-11-02 14:37:54 -0700546 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700547}
548
Dan Sinclairf528eee2017-02-14 11:52:07 -0500549bool CPWL_SBButton::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550 CPWL_Wnd::OnMouseMove(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700551
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552 if (CPWL_Wnd* pParent = GetParentWindow()) {
553 pParent->OnNotify(this, PNM_MOUSEMOVE, 0, (intptr_t)&point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700554 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700555
tsepez4cf55152016-11-02 14:37:54 -0700556 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700557}
558
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559CPWL_ScrollBar::CPWL_ScrollBar(PWL_SCROLLBAR_TYPE sbType)
560 : m_sbType(sbType),
thestig1cd352e2016-06-07 17:53:06 -0700561 m_pMinButton(nullptr),
562 m_pMaxButton(nullptr),
563 m_pPosButton(nullptr),
tsepez4cf55152016-11-02 14:37:54 -0700564 m_bMouseDown(false),
565 m_bMinOrMax(false),
566 m_bNotifyForever(true) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700567
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700568CPWL_ScrollBar::~CPWL_ScrollBar() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700569
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570CFX_ByteString CPWL_ScrollBar::GetClassName() const {
571 return "CPWL_ScrollBar";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700572}
573
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700574void CPWL_ScrollBar::OnCreate(PWL_CREATEPARAM& cp) {
575 cp.eCursorType = FXCT_ARROW;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700576}
577
Tom Sepez5e042a12017-05-30 14:13:44 -0700578void CPWL_ScrollBar::OnDestroy() {
579 // Until cleanup takes place in the virtual destructor for CPWL_Wnd
580 // subclasses, implement the virtual OnDestroy method that does the
581 // cleanup first, then invokes the superclass OnDestroy ... gee,
582 // like a dtor would.
583 m_pMinButton.Release();
584 m_pMaxButton.Release();
585 m_pPosButton.Release();
586 CPWL_Wnd::OnDestroy();
587}
588
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589void CPWL_ScrollBar::RePosChildWnd() {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800590 CFX_FloatRect rcClient = GetClientRect();
591 CFX_FloatRect rcMinButton, rcMaxButton;
Dan Sinclair05df0752017-03-14 14:43:42 -0400592 float fBWidth = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700593
594 switch (m_sbType) {
595 case SBT_HSCROLL:
596 if (rcClient.right - rcClient.left >
597 PWL_SCROLLBAR_BUTTON_WIDTH * 2 + PWL_SCROLLBAR_POSBUTTON_MINWIDTH +
598 2) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800599 rcMinButton = CFX_FloatRect(rcClient.left, rcClient.bottom,
600 rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH,
601 rcClient.top);
602 rcMaxButton =
603 CFX_FloatRect(rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH,
604 rcClient.bottom, rcClient.right, rcClient.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605 } else {
606 fBWidth = (rcClient.right - rcClient.left -
607 PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) /
608 2;
609
610 if (fBWidth > 0) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800611 rcMinButton = CFX_FloatRect(rcClient.left, rcClient.bottom,
612 rcClient.left + fBWidth, rcClient.top);
613 rcMaxButton = CFX_FloatRect(rcClient.right - fBWidth, rcClient.bottom,
614 rcClient.right, rcClient.top);
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800615 } else {
tsepez4cf55152016-11-02 14:37:54 -0700616 SetVisible(false);
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800617 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618 }
619 break;
620 case SBT_VSCROLL:
621 if (IsFloatBigger(rcClient.top - rcClient.bottom,
622 PWL_SCROLLBAR_BUTTON_WIDTH * 2 +
623 PWL_SCROLLBAR_POSBUTTON_MINWIDTH + 2)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800624 rcMinButton = CFX_FloatRect(rcClient.left,
625 rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH,
626 rcClient.right, rcClient.top);
627 rcMaxButton =
628 CFX_FloatRect(rcClient.left, rcClient.bottom, rcClient.right,
629 rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630 } else {
631 fBWidth = (rcClient.top - rcClient.bottom -
632 PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) /
633 2;
634
635 if (IsFloatBigger(fBWidth, 0)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800636 rcMinButton = CFX_FloatRect(rcClient.left, rcClient.top - fBWidth,
637 rcClient.right, rcClient.top);
638 rcMaxButton =
639 CFX_FloatRect(rcClient.left, rcClient.bottom, rcClient.right,
640 rcClient.bottom + fBWidth);
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800641 } else {
tsepez4cf55152016-11-02 14:37:54 -0700642 SetVisible(false);
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800643 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700644 }
645 break;
646 }
647
648 if (m_pMinButton)
tsepez4cf55152016-11-02 14:37:54 -0700649 m_pMinButton->Move(rcMinButton, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650 if (m_pMaxButton)
tsepez4cf55152016-11-02 14:37:54 -0700651 m_pMaxButton->Move(rcMaxButton, true, false);
652 MovePosButton(false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700653}
654
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700655void CPWL_ScrollBar::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800656 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700657
658 if (IsVisible() && !rectWnd.IsEmpty()) {
659 CFX_ByteTextBuf sButton;
660
661 sButton << "q\n";
662 sButton << "0 w\n"
tsepez4cf55152016-11-02 14:37:54 -0700663 << CPWL_Utils::GetColorAppStream(GetBackgroundColor(), true)
tsepez4c3debb2016-04-08 12:20:38 -0700664 .AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700665 sButton << rectWnd.left << " " << rectWnd.bottom << " "
666 << rectWnd.right - rectWnd.left << " "
667 << rectWnd.top - rectWnd.bottom << " re b Q\n";
668
669 sAppStream << sButton;
670 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700671}
672
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700673void CPWL_ScrollBar::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800674 CFX_Matrix* pUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800675 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700676
677 if (IsVisible() && !rectWnd.IsEmpty()) {
678 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rectWnd,
679 GetBackgroundColor(), GetTransparency());
680
681 CPWL_Utils::DrawStrokeLine(
682 pDevice, pUser2Device,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500683 CFX_PointF(rectWnd.left + 2.0f, rectWnd.top - 2.0f),
684 CFX_PointF(rectWnd.left + 2.0f, rectWnd.bottom + 2.0f),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685 ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f);
686
687 CPWL_Utils::DrawStrokeLine(
688 pDevice, pUser2Device,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500689 CFX_PointF(rectWnd.right - 2.0f, rectWnd.top - 2.0f),
690 CFX_PointF(rectWnd.right - 2.0f, rectWnd.bottom + 2.0f),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691 ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f);
692 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700693}
694
Dan Sinclairf528eee2017-02-14 11:52:07 -0500695bool CPWL_ScrollBar::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700697
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700698 if (HasFlag(PWS_AUTOTRANSPARENT)) {
699 if (GetTransparency() != 255) {
700 SetTransparency(255);
701 InvalidateRect();
702 }
703 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700704
Tom Sepez281a9ea2016-02-26 14:24:28 -0800705 CFX_FloatRect rcMinArea, rcMaxArea;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700706
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707 if (m_pPosButton && m_pPosButton->IsVisible()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800708 CFX_FloatRect rcClient = GetClientRect();
709 CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect();
Lei Zhang60f507b2015-06-13 00:41:00 -0700710
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711 switch (m_sbType) {
712 case SBT_HSCROLL:
Tom Sepez281a9ea2016-02-26 14:24:28 -0800713 rcMinArea =
714 CFX_FloatRect(rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH,
715 rcClient.bottom, rcPosButton.left, rcClient.top);
716 rcMaxArea = CFX_FloatRect(rcPosButton.right, rcClient.bottom,
717 rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH,
718 rcClient.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719
720 break;
721 case SBT_VSCROLL:
Tom Sepez281a9ea2016-02-26 14:24:28 -0800722 rcMinArea =
723 CFX_FloatRect(rcClient.left, rcPosButton.top, rcClient.right,
724 rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH);
725 rcMaxArea = CFX_FloatRect(rcClient.left,
726 rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH,
727 rcClient.right, rcPosButton.bottom);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728 break;
729 }
730
731 rcMinArea.Normalize();
732 rcMaxArea.Normalize();
733
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500734 if (rcMinArea.Contains(point)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700735 m_sData.SubBig();
tsepez4cf55152016-11-02 14:37:54 -0700736 MovePosButton(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737 NotifyScrollWindow();
738 }
739
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500740 if (rcMaxArea.Contains(point)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700741 m_sData.AddBig();
tsepez4cf55152016-11-02 14:37:54 -0700742 MovePosButton(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743 NotifyScrollWindow();
744 }
745 }
746
tsepez4cf55152016-11-02 14:37:54 -0700747 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700748}
749
Dan Sinclairf528eee2017-02-14 11:52:07 -0500750bool CPWL_ScrollBar::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700751 CPWL_Wnd::OnLButtonUp(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700752
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700753 if (HasFlag(PWS_AUTOTRANSPARENT)) {
Dan Sinclairfc54e052017-02-23 09:59:05 -0500754 if (GetTransparency() != PWL_SCROLLBAR_TRANSPARENCY) {
755 SetTransparency(PWL_SCROLLBAR_TRANSPARENCY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700756 InvalidateRect();
757 }
758 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700759
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700760 EndTimer();
tsepez4cf55152016-11-02 14:37:54 -0700761 m_bMouseDown = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700762
tsepez4cf55152016-11-02 14:37:54 -0700763 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700764}
765
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700766void CPWL_ScrollBar::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -0700767 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700768 intptr_t wParam,
769 intptr_t lParam) {
770 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700771
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700772 switch (msg) {
773 case PNM_LBUTTONDOWN:
774 if (pWnd == m_pMinButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500775 OnMinButtonLBDown(*(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_pMaxButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500779 OnMaxButtonLBDown(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700780 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700781
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700782 if (pWnd == m_pPosButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500783 OnPosButtonLBDown(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700784 }
785 break;
786 case PNM_LBUTTONUP:
787 if (pWnd == m_pMinButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500788 OnMinButtonLBUp(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700789 }
790
791 if (pWnd == m_pMaxButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500792 OnMaxButtonLBUp(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700793 }
794
795 if (pWnd == m_pPosButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500796 OnPosButtonLBUp(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700797 }
798 break;
799 case PNM_MOUSEMOVE:
800 if (pWnd == m_pMinButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500801 OnMinButtonMouseMove(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700802 }
803
804 if (pWnd == m_pMaxButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500805 OnMaxButtonMouseMove(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700806 }
807
808 if (pWnd == m_pPosButton) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500809 OnPosButtonMouseMove(*(CFX_PointF*)lParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700810 }
811 break;
812 case PNM_SETSCROLLINFO: {
tsepezf86ca382016-09-13 12:23:30 -0700813 PWL_SCROLL_INFO* pInfo = reinterpret_cast<PWL_SCROLL_INFO*>(lParam);
814 if (pInfo && *pInfo != m_OriginInfo) {
815 m_OriginInfo = *pInfo;
Dan Sinclair05df0752017-03-14 14:43:42 -0400816 float fMax =
tsepezf86ca382016-09-13 12:23:30 -0700817 pInfo->fContentMax - pInfo->fContentMin - pInfo->fPlateWidth;
818 fMax = fMax > 0.0f ? fMax : 0.0f;
819 SetScrollRange(0, fMax, pInfo->fPlateWidth);
820 SetScrollStep(pInfo->fBigStep, pInfo->fSmallStep);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700821 }
822 } break;
823 case PNM_SETSCROLLPOS: {
Dan Sinclair05df0752017-03-14 14:43:42 -0400824 float fPos = *(float*)lParam;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700825 switch (m_sbType) {
826 case SBT_HSCROLL:
827 fPos = fPos - m_OriginInfo.fContentMin;
828 break;
829 case SBT_VSCROLL:
830 fPos = m_OriginInfo.fContentMax - fPos;
831 break;
832 }
833 SetScrollPos(fPos);
834 } break;
835 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700836}
837
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700838void CPWL_ScrollBar::CreateButtons(const PWL_CREATEPARAM& cp) {
839 PWL_CREATEPARAM scp = cp;
840 scp.pParentWnd = this;
841 scp.dwBorderWidth = 2;
dsinclair92cb5e52016-05-16 11:38:28 -0700842 scp.nBorderStyle = BorderStyle::BEVELED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700843
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700844 scp.dwFlags =
845 PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PWS_NOREFRESHCLIP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700846
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700847 if (!m_pMinButton) {
848 m_pMinButton = new CPWL_SBButton(m_sbType, PSBT_MIN);
849 m_pMinButton->Create(scp);
850 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700851
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700852 if (!m_pMaxButton) {
853 m_pMaxButton = new CPWL_SBButton(m_sbType, PSBT_MAX);
854 m_pMaxButton->Create(scp);
855 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700856
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700857 if (!m_pPosButton) {
858 m_pPosButton = new CPWL_SBButton(m_sbType, PSBT_POS);
tsepez4cf55152016-11-02 14:37:54 -0700859 m_pPosButton->SetVisible(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700860 m_pPosButton->Create(scp);
861 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700862}
863
Dan Sinclair05df0752017-03-14 14:43:42 -0400864float CPWL_ScrollBar::GetScrollBarWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700865 if (!IsVisible())
866 return 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700867
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700868 return PWL_SCROLLBAR_WIDTH;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700869}
870
Dan Sinclair05df0752017-03-14 14:43:42 -0400871void CPWL_ScrollBar::SetScrollRange(float fMin,
872 float fMax,
873 float fClientWidth) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700874 if (m_pPosButton) {
875 m_sData.SetScrollRange(fMin, fMax);
876 m_sData.SetClientWidth(fClientWidth);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700877
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700878 if (IsFloatSmaller(m_sData.ScrollRange.GetWidth(), 0.0f)) {
tsepez4cf55152016-11-02 14:37:54 -0700879 m_pPosButton->SetVisible(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700880 } else {
tsepez4cf55152016-11-02 14:37:54 -0700881 m_pPosButton->SetVisible(true);
882 MovePosButton(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700883 }
884 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700885}
886
Dan Sinclair05df0752017-03-14 14:43:42 -0400887void CPWL_ScrollBar::SetScrollPos(float fPos) {
888 float fOldPos = m_sData.fScrollPos;
Lei Zhang60f507b2015-06-13 00:41:00 -0700889
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700890 m_sData.SetPos(fPos);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700891
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700892 if (!IsFloatEqual(m_sData.fScrollPos, fOldPos))
tsepez4cf55152016-11-02 14:37:54 -0700893 MovePosButton(true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700894}
895
Dan Sinclair05df0752017-03-14 14:43:42 -0400896void CPWL_ScrollBar::SetScrollStep(float fBigStep, float fSmallStep) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700897 m_sData.SetBigStep(fBigStep);
898 m_sData.SetSmallStep(fSmallStep);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700899}
900
tsepez4cf55152016-11-02 14:37:54 -0700901void CPWL_ScrollBar::MovePosButton(bool bRefresh) {
Lei Zhang96660d62015-12-14 18:27:25 -0800902 ASSERT(m_pMinButton);
903 ASSERT(m_pMaxButton);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700904
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700905 if (m_pPosButton->IsVisible()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800906 CFX_FloatRect rcClient;
907 CFX_FloatRect rcPosArea, rcPosButton;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700908
909 rcClient = GetClientRect();
910 rcPosArea = GetScrollArea();
911
Dan Sinclair05df0752017-03-14 14:43:42 -0400912 float fLeft, fRight, fTop, fBottom;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700913
914 switch (m_sbType) {
915 case SBT_HSCROLL:
916 fLeft = TrueToFace(m_sData.fScrollPos);
917 fRight = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth);
918
919 if (fRight - fLeft < PWL_SCROLLBAR_POSBUTTON_MINWIDTH)
920 fRight = fLeft + PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
921
922 if (fRight > rcPosArea.right) {
923 fRight = rcPosArea.right;
924 fLeft = fRight - PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
925 }
926
Tom Sepez281a9ea2016-02-26 14:24:28 -0800927 rcPosButton =
928 CFX_FloatRect(fLeft, rcPosArea.bottom, fRight, rcPosArea.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700929
930 break;
931 case SBT_VSCROLL:
932 fBottom = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth);
933 fTop = TrueToFace(m_sData.fScrollPos);
934
935 if (IsFloatSmaller(fTop - fBottom, PWL_SCROLLBAR_POSBUTTON_MINWIDTH))
936 fBottom = fTop - PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
937
938 if (IsFloatSmaller(fBottom, rcPosArea.bottom)) {
939 fBottom = rcPosArea.bottom;
940 fTop = fBottom + PWL_SCROLLBAR_POSBUTTON_MINWIDTH;
941 }
942
Tom Sepez281a9ea2016-02-26 14:24:28 -0800943 rcPosButton =
944 CFX_FloatRect(rcPosArea.left, fBottom, rcPosArea.right, fTop);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700945
946 break;
947 }
948
tsepez4cf55152016-11-02 14:37:54 -0700949 m_pPosButton->Move(rcPosButton, true, bRefresh);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700950 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700951}
952
Dan Sinclairf528eee2017-02-14 11:52:07 -0500953void CPWL_ScrollBar::OnMinButtonLBDown(const CFX_PointF& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700954 m_sData.SubSmall();
tsepez4cf55152016-11-02 14:37:54 -0700955 MovePosButton(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700956 NotifyScrollWindow();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700957
tsepez4cf55152016-11-02 14:37:54 -0700958 m_bMinOrMax = true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700959
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700960 EndTimer();
961 BeginTimer(100);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700962}
963
Dan Sinclairf528eee2017-02-14 11:52:07 -0500964void CPWL_ScrollBar::OnMinButtonLBUp(const CFX_PointF& point) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700965
Dan Sinclairf528eee2017-02-14 11:52:07 -0500966void CPWL_ScrollBar::OnMinButtonMouseMove(const CFX_PointF& point) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700967
Dan Sinclairf528eee2017-02-14 11:52:07 -0500968void CPWL_ScrollBar::OnMaxButtonLBDown(const CFX_PointF& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700969 m_sData.AddSmall();
tsepez4cf55152016-11-02 14:37:54 -0700970 MovePosButton(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700971 NotifyScrollWindow();
972
tsepez4cf55152016-11-02 14:37:54 -0700973 m_bMinOrMax = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700974
975 EndTimer();
976 BeginTimer(100);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700977}
978
Dan Sinclairf528eee2017-02-14 11:52:07 -0500979void CPWL_ScrollBar::OnMaxButtonLBUp(const CFX_PointF& point) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700980
Dan Sinclairf528eee2017-02-14 11:52:07 -0500981void CPWL_ScrollBar::OnMaxButtonMouseMove(const CFX_PointF& point) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700982
Dan Sinclairf528eee2017-02-14 11:52:07 -0500983void CPWL_ScrollBar::OnPosButtonLBDown(const CFX_PointF& point) {
tsepez4cf55152016-11-02 14:37:54 -0700984 m_bMouseDown = true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700985
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700986 if (m_pPosButton) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800987 CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700988
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700989 switch (m_sbType) {
990 case SBT_HSCROLL:
991 m_nOldPos = point.x;
992 m_fOldPosButton = rcPosButton.left;
993 break;
994 case SBT_VSCROLL:
995 m_nOldPos = point.y;
996 m_fOldPosButton = rcPosButton.top;
997 break;
998 }
999 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001000}
1001
Dan Sinclairf528eee2017-02-14 11:52:07 -05001002void CPWL_ScrollBar::OnPosButtonLBUp(const CFX_PointF& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001003 if (m_bMouseDown) {
1004 if (!m_bNotifyForever)
1005 NotifyScrollWindow();
1006 }
tsepez4cf55152016-11-02 14:37:54 -07001007 m_bMouseDown = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001008}
1009
Dan Sinclairf528eee2017-02-14 11:52:07 -05001010void CPWL_ScrollBar::OnPosButtonMouseMove(const CFX_PointF& point) {
Dan Sinclair05df0752017-03-14 14:43:42 -04001011 float fOldScrollPos = m_sData.fScrollPos;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001012
Dan Sinclair05df0752017-03-14 14:43:42 -04001013 float fNewPos = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001014
1015 switch (m_sbType) {
1016 case SBT_HSCROLL:
Dan Sinclair669a4182017-04-03 14:51:45 -04001017 if (fabs(point.x - m_nOldPos) < 1)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001018 return;
1019 fNewPos = FaceToTrue(m_fOldPosButton + point.x - m_nOldPos);
1020 break;
1021 case SBT_VSCROLL:
Dan Sinclair669a4182017-04-03 14:51:45 -04001022 if (fabs(point.y - m_nOldPos) < 1)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001023 return;
1024 fNewPos = FaceToTrue(m_fOldPosButton + point.y - m_nOldPos);
1025 break;
1026 }
1027
1028 if (m_bMouseDown) {
1029 switch (m_sbType) {
1030 case SBT_HSCROLL:
1031
1032 if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) {
1033 fNewPos = m_sData.ScrollRange.fMin;
1034 }
1035
1036 if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) {
1037 fNewPos = m_sData.ScrollRange.fMax;
1038 }
1039
1040 m_sData.SetPos(fNewPos);
1041
1042 break;
1043 case SBT_VSCROLL:
1044
1045 if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) {
1046 fNewPos = m_sData.ScrollRange.fMin;
1047 }
1048
1049 if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) {
1050 fNewPos = m_sData.ScrollRange.fMax;
1051 }
1052
1053 m_sData.SetPos(fNewPos);
1054
1055 break;
1056 }
1057
1058 if (!IsFloatEqual(fOldScrollPos, m_sData.fScrollPos)) {
tsepez4cf55152016-11-02 14:37:54 -07001059 MovePosButton(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001060
1061 if (m_bNotifyForever)
1062 NotifyScrollWindow();
1063 }
1064 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001065}
1066
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001067void CPWL_ScrollBar::NotifyScrollWindow() {
1068 if (CPWL_Wnd* pParent = GetParentWindow()) {
Dan Sinclair05df0752017-03-14 14:43:42 -04001069 float fPos;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001070 switch (m_sbType) {
1071 case SBT_HSCROLL:
1072 fPos = m_OriginInfo.fContentMin + m_sData.fScrollPos;
1073 break;
1074 case SBT_VSCROLL:
1075 fPos = m_OriginInfo.fContentMax - m_sData.fScrollPos;
1076 break;
1077 }
1078 pParent->OnNotify(this, PNM_SCROLLWINDOW, (intptr_t)m_sbType,
1079 (intptr_t)&fPos);
1080 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001081}
1082
Tom Sepez281a9ea2016-02-26 14:24:28 -08001083CFX_FloatRect CPWL_ScrollBar::GetScrollArea() const {
1084 CFX_FloatRect rcClient = GetClientRect();
1085 CFX_FloatRect rcArea;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001086
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001087 if (!m_pMinButton || !m_pMaxButton)
1088 return rcClient;
Lei Zhang60f507b2015-06-13 00:41:00 -07001089
Tom Sepez281a9ea2016-02-26 14:24:28 -08001090 CFX_FloatRect rcMin = m_pMinButton->GetWindowRect();
1091 CFX_FloatRect rcMax = m_pMaxButton->GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001092
Dan Sinclair05df0752017-03-14 14:43:42 -04001093 float fMinWidth = rcMin.right - rcMin.left;
1094 float fMinHeight = rcMin.top - rcMin.bottom;
1095 float fMaxWidth = rcMax.right - rcMax.left;
1096 float fMaxHeight = rcMax.top - rcMax.bottom;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001097
1098 switch (m_sbType) {
1099 case SBT_HSCROLL:
1100 if (rcClient.right - rcClient.left > fMinWidth + fMaxWidth + 2) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001101 rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom,
1102 rcClient.right - fMaxWidth - 1, rcClient.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001103 } else {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001104 rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom,
1105 rcClient.left + fMinWidth + 1, rcClient.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001106 }
1107 break;
1108 case SBT_VSCROLL:
1109 if (rcClient.top - rcClient.bottom > fMinHeight + fMaxHeight + 2) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001110 rcArea = CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1,
1111 rcClient.right, rcClient.top - fMaxHeight - 1);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001112 } else {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001113 rcArea =
1114 CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1,
1115 rcClient.right, rcClient.bottom + fMinHeight + 1);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001116 }
1117 break;
1118 }
1119
1120 rcArea.Normalize();
1121
1122 return rcArea;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001123}
1124
Dan Sinclair05df0752017-03-14 14:43:42 -04001125float CPWL_ScrollBar::TrueToFace(float fTrue) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001126 CFX_FloatRect rcPosArea;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001127 rcPosArea = GetScrollArea();
1128
Dan Sinclair05df0752017-03-14 14:43:42 -04001129 float fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001130 fFactWidth = fFactWidth == 0 ? 1 : fFactWidth;
1131
Dan Sinclair05df0752017-03-14 14:43:42 -04001132 float fFace = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001133
1134 switch (m_sbType) {
1135 case SBT_HSCROLL:
1136 fFace = rcPosArea.left +
1137 fTrue * (rcPosArea.right - rcPosArea.left) / fFactWidth;
1138 break;
1139 case SBT_VSCROLL:
1140 fFace = rcPosArea.top -
1141 fTrue * (rcPosArea.top - rcPosArea.bottom) / fFactWidth;
1142 break;
1143 }
1144
1145 return fFace;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001146}
1147
Dan Sinclair05df0752017-03-14 14:43:42 -04001148float CPWL_ScrollBar::FaceToTrue(float fFace) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001149 CFX_FloatRect rcPosArea;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001150 rcPosArea = GetScrollArea();
1151
Dan Sinclair05df0752017-03-14 14:43:42 -04001152 float fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001153 fFactWidth = fFactWidth == 0 ? 1 : fFactWidth;
1154
Dan Sinclair05df0752017-03-14 14:43:42 -04001155 float fTrue = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001156
1157 switch (m_sbType) {
1158 case SBT_HSCROLL:
1159 fTrue = (fFace - rcPosArea.left) * fFactWidth /
1160 (rcPosArea.right - rcPosArea.left);
1161 break;
1162 case SBT_VSCROLL:
1163 fTrue = (rcPosArea.top - fFace) * fFactWidth /
1164 (rcPosArea.top - rcPosArea.bottom);
1165 break;
1166 }
1167
1168 return fTrue;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001169}
1170
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001171void CPWL_ScrollBar::CreateChildWnd(const PWL_CREATEPARAM& cp) {
1172 CreateButtons(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001173}
1174
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001175void CPWL_ScrollBar::TimerProc() {
1176 PWL_SCROLL_PRIVATEDATA sTemp = m_sData;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001177 if (m_bMinOrMax)
1178 m_sData.SubSmall();
1179 else
1180 m_sData.AddSmall();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001181
tsepezf86ca382016-09-13 12:23:30 -07001182 if (sTemp != m_sData) {
tsepez4cf55152016-11-02 14:37:54 -07001183 MovePosButton(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001184 NotifyScrollWindow();
1185 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001186}