OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fwl/core/ifwl_scrollbar.h" | 7 #include "xfa/fwl/core/ifwl_scrollbar.h" |
8 | 8 |
9 #include "third_party/base/ptr_util.h" | 9 #include "third_party/base/ptr_util.h" |
10 #include "xfa/fwl/core/cfwl_message.h" | 10 #include "xfa/fwl/core/cfwl_message.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 m_rtMaxTrack.Reset(); | 52 m_rtMaxTrack.Reset(); |
53 } | 53 } |
54 | 54 |
55 IFWL_ScrollBar::~IFWL_ScrollBar() {} | 55 IFWL_ScrollBar::~IFWL_ScrollBar() {} |
56 | 56 |
57 FWL_Type IFWL_ScrollBar::GetClassID() const { | 57 FWL_Type IFWL_ScrollBar::GetClassID() const { |
58 return FWL_Type::ScrollBar; | 58 return FWL_Type::ScrollBar; |
59 } | 59 } |
60 | 60 |
61 void IFWL_ScrollBar::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { | 61 void IFWL_ScrollBar::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { |
62 if (bAutoSize) { | 62 if (!bAutoSize) { |
63 rect.Set(0, 0, 0, 0); | |
64 FX_FLOAT* pfMinWidth = static_cast<FX_FLOAT*>( | |
65 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | |
66 if (!pfMinWidth) | |
67 return; | |
68 if (IsVertical()) { | |
69 rect.Set(0, 0, (*pfMinWidth), (*pfMinWidth) * 3); | |
70 } else { | |
71 rect.Set(0, 0, (*pfMinWidth) * 3, (*pfMinWidth)); | |
72 } | |
73 IFWL_Widget::GetWidgetRect(rect, true); | |
74 } else { | |
75 rect = m_pProperties->m_rtWidget; | 63 rect = m_pProperties->m_rtWidget; |
| 64 return; |
76 } | 65 } |
| 66 |
| 67 rect.Set(0, 0, 0, 0); |
| 68 FX_FLOAT* pfMinWidth = static_cast<FX_FLOAT*>( |
| 69 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
| 70 if (!pfMinWidth) |
| 71 return; |
| 72 if (IsVertical()) |
| 73 rect.Set(0, 0, (*pfMinWidth), (*pfMinWidth) * 3); |
| 74 else |
| 75 rect.Set(0, 0, (*pfMinWidth) * 3, (*pfMinWidth)); |
| 76 IFWL_Widget::GetWidgetRect(rect, true); |
77 } | 77 } |
78 | 78 |
79 void IFWL_ScrollBar::Update() { | 79 void IFWL_ScrollBar::Update() { |
80 if (IsLocked()) { | 80 if (IsLocked()) |
81 return; | 81 return; |
82 } | 82 if (!m_pProperties->m_pThemeProvider) |
83 if (!m_pProperties->m_pThemeProvider) { | |
84 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 83 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
85 } | 84 |
86 Layout(); | 85 Layout(); |
87 } | 86 } |
88 | 87 |
89 void IFWL_ScrollBar::DrawWidget(CFX_Graphics* pGraphics, | 88 void IFWL_ScrollBar::DrawWidget(CFX_Graphics* pGraphics, |
90 const CFX_Matrix* pMatrix) { | 89 const CFX_Matrix* pMatrix) { |
91 if (!pGraphics) | 90 if (!pGraphics) |
92 return; | 91 return; |
93 if (!m_pProperties->m_pThemeProvider) | 92 if (!m_pProperties->m_pThemeProvider) |
94 return; | 93 return; |
| 94 |
95 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 95 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
96 if (HasBorder()) { | 96 if (HasBorder()) |
97 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | 97 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); |
98 } | 98 if (HasEdge()) |
99 if (HasEdge()) { | |
100 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | 99 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); |
101 } | |
102 DrawTrack(pGraphics, pTheme, true, pMatrix); | 100 DrawTrack(pGraphics, pTheme, true, pMatrix); |
103 DrawTrack(pGraphics, pTheme, false, pMatrix); | 101 DrawTrack(pGraphics, pTheme, false, pMatrix); |
104 DrawArrowBtn(pGraphics, pTheme, true, pMatrix); | 102 DrawArrowBtn(pGraphics, pTheme, true, pMatrix); |
105 DrawArrowBtn(pGraphics, pTheme, false, pMatrix); | 103 DrawArrowBtn(pGraphics, pTheme, false, pMatrix); |
106 DrawThumb(pGraphics, pTheme, pMatrix); | 104 DrawThumb(pGraphics, pTheme, pMatrix); |
107 } | 105 } |
108 | 106 |
109 void IFWL_ScrollBar::SetTrackPos(FX_FLOAT fTrackPos) { | 107 void IFWL_ScrollBar::SetTrackPos(FX_FLOAT fTrackPos) { |
110 m_fTrackPos = fTrackPos; | 108 m_fTrackPos = fTrackPos; |
111 CalcThumbButtonRect(m_rtThumb); | 109 CalcThumbButtonRect(m_rtThumb); |
(...skipping 29 matching lines...) Expand all Loading... |
141 const CFX_Matrix* pMatrix) { | 139 const CFX_Matrix* pMatrix) { |
142 CFWL_ThemeBackground param; | 140 CFWL_ThemeBackground param; |
143 param.m_pWidget = this; | 141 param.m_pWidget = this; |
144 param.m_iPart = bMinBtn ? CFWL_Part::ForeArrow : CFWL_Part::BackArrow; | 142 param.m_iPart = bMinBtn ? CFWL_Part::ForeArrow : CFWL_Part::BackArrow; |
145 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | 143 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
146 ? CFWL_PartState_Disabled | 144 ? CFWL_PartState_Disabled |
147 : (bMinBtn ? m_iMinButtonState : m_iMaxButtonState); | 145 : (bMinBtn ? m_iMinButtonState : m_iMaxButtonState); |
148 param.m_pGraphics = pGraphics; | 146 param.m_pGraphics = pGraphics; |
149 param.m_matrix.Concat(*pMatrix); | 147 param.m_matrix.Concat(*pMatrix); |
150 param.m_rtPart = bMinBtn ? m_rtMinBtn : m_rtMaxBtn; | 148 param.m_rtPart = bMinBtn ? m_rtMinBtn : m_rtMaxBtn; |
151 if (param.m_rtPart.height > 0 && param.m_rtPart.width > 0) { | 149 if (param.m_rtPart.height > 0 && param.m_rtPart.width > 0) |
152 pTheme->DrawBackground(¶m); | 150 pTheme->DrawBackground(¶m); |
153 } | |
154 } | 151 } |
155 | 152 |
156 void IFWL_ScrollBar::DrawThumb(CFX_Graphics* pGraphics, | 153 void IFWL_ScrollBar::DrawThumb(CFX_Graphics* pGraphics, |
157 IFWL_ThemeProvider* pTheme, | 154 IFWL_ThemeProvider* pTheme, |
158 const CFX_Matrix* pMatrix) { | 155 const CFX_Matrix* pMatrix) { |
159 CFWL_ThemeBackground param; | 156 CFWL_ThemeBackground param; |
160 param.m_pWidget = this; | 157 param.m_pWidget = this; |
161 param.m_iPart = CFWL_Part::Thumb; | 158 param.m_iPart = CFWL_Part::Thumb; |
162 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | 159 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
163 ? CFWL_PartState_Disabled | 160 ? CFWL_PartState_Disabled |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 215 |
219 void IFWL_ScrollBar::CalcThumbButtonRect(CFX_RectF& rect) { | 216 void IFWL_ScrollBar::CalcThumbButtonRect(CFX_RectF& rect) { |
220 if (!IsEnabled()) { | 217 if (!IsEnabled()) { |
221 m_rtThumb.Reset(); | 218 m_rtThumb.Reset(); |
222 return; | 219 return; |
223 } | 220 } |
224 if (m_bMinSize) { | 221 if (m_bMinSize) { |
225 m_rtThumb.Empty(); | 222 m_rtThumb.Empty(); |
226 return; | 223 return; |
227 } | 224 } |
| 225 |
228 FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; | 226 FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; |
229 memset(&rect, 0, sizeof(CFX_Rect)); | 227 memset(&rect, 0, sizeof(CFX_Rect)); |
230 if (fRange < 0) { | 228 if (fRange < 0) { |
231 if (IsVertical()) { | 229 if (IsVertical()) |
232 rect.Set(m_rtClient.left, m_rtMaxBtn.bottom(), m_rtClient.width, 0); | 230 rect.Set(m_rtClient.left, m_rtMaxBtn.bottom(), m_rtClient.width, 0); |
233 } else { | 231 else |
234 rect.Set(m_rtMaxBtn.right(), m_rtClient.top, 0, m_rtClient.height); | 232 rect.Set(m_rtMaxBtn.right(), m_rtClient.top, 0, m_rtClient.height); |
235 } | |
236 return; | 233 return; |
237 } | 234 } |
| 235 |
238 CFX_RectF rtClient = m_rtClient; | 236 CFX_RectF rtClient = m_rtClient; |
239 FX_FLOAT fLength = IsVertical() ? rtClient.height : rtClient.width; | 237 FX_FLOAT fLength = IsVertical() ? rtClient.height : rtClient.width; |
240 FX_FLOAT fSize = m_fButtonLen; | 238 FX_FLOAT fSize = m_fButtonLen; |
241 if (m_bCustomLayout) { | 239 if (m_bCustomLayout) { |
242 if (IsVertical()) { | 240 if (IsVertical()) { |
243 fLength = fLength - m_rtMinBtn.height - m_rtMaxBtn.height; | 241 fLength = fLength - m_rtMinBtn.height - m_rtMaxBtn.height; |
244 if (fLength < m_rtMinBtn.height || fLength < m_rtMaxBtn.height) { | 242 if (fLength < m_rtMinBtn.height || fLength < m_rtMaxBtn.height) |
245 fLength = 0.0f; | 243 fLength = 0.0f; |
246 } | |
247 } else { | 244 } else { |
248 fLength = fLength - m_rtMinBtn.width - m_rtMaxBtn.width; | 245 fLength = fLength - m_rtMinBtn.width - m_rtMaxBtn.width; |
249 if (fLength < m_rtMinBtn.width || fLength < m_rtMaxBtn.width) { | 246 if (fLength < m_rtMinBtn.width || fLength < m_rtMaxBtn.width) |
250 fLength = 0.0f; | 247 fLength = 0.0f; |
251 } | |
252 } | 248 } |
253 } else { | 249 } else { |
254 fLength -= fSize * 2.0f; | 250 fLength -= fSize * 2.0f; |
255 if (fLength < fSize) { | 251 if (fLength < fSize) |
256 fLength = 0.0f; | 252 fLength = 0.0f; |
257 } | |
258 } | 253 } |
| 254 |
259 FX_FLOAT fThumbSize = fLength * fLength / (fRange + fLength); | 255 FX_FLOAT fThumbSize = fLength * fLength / (fRange + fLength); |
260 if (fThumbSize < m_fMinThumb) { | 256 fThumbSize = std::max(fThumbSize, m_fMinThumb); |
261 fThumbSize = m_fMinThumb; | 257 |
262 } | 258 FX_FLOAT fDiff = std::max(fLength - fThumbSize, 0.0f); |
263 FX_FLOAT fDiff = fLength - fThumbSize; | 259 FX_FLOAT fTrackPos = |
264 if (fDiff < 0.0f) { | 260 std::max(std::min(m_fTrackPos, m_fRangeMax), m_fRangeMin); |
265 fDiff = 0.0f; | |
266 } | |
267 FX_FLOAT fTrackPos = m_fTrackPos; | |
268 if (fTrackPos > m_fRangeMax) { | |
269 fTrackPos = m_fRangeMax; | |
270 } | |
271 if (fTrackPos < m_fRangeMin) { | |
272 fTrackPos = m_fRangeMin; | |
273 } | |
274 if (!fRange) | 261 if (!fRange) |
275 return; | 262 return; |
| 263 |
276 if (m_bCustomLayout) { | 264 if (m_bCustomLayout) { |
277 FX_FLOAT iPos = fDiff * (fTrackPos - m_fRangeMin) / fRange; | 265 FX_FLOAT iPos = fDiff * (fTrackPos - m_fRangeMin) / fRange; |
278 rect.left = rtClient.left; | 266 rect.left = rtClient.left; |
279 if (!IsVertical()) { | 267 if (!IsVertical()) { |
280 if ((m_rtMinBtn.right() == m_rtMaxBtn.left && m_rtMinBtn.width > 0 && | 268 if ((m_rtMinBtn.right() == m_rtMaxBtn.left && m_rtMinBtn.width > 0 && |
281 m_rtMaxBtn.width > 0) || | 269 m_rtMaxBtn.width > 0) || |
282 (0 == m_rtMinBtn.width && 0 == m_rtMaxBtn.width)) { | 270 (0 == m_rtMinBtn.width && 0 == m_rtMaxBtn.width)) { |
283 rect.left += iPos; | 271 rect.left += iPos; |
284 } else { | 272 } else { |
285 rect.left += m_rtMinBtn.right() + iPos; | 273 rect.left += m_rtMinBtn.right() + iPos; |
286 } | 274 } |
287 } | 275 } |
288 rect.top = rtClient.top; | 276 rect.top = rtClient.top; |
289 if (IsVertical()) { | 277 if (IsVertical()) { |
290 if ((m_rtMinBtn.bottom() == m_rtMaxBtn.top && m_rtMinBtn.height > 0 && | 278 if ((m_rtMinBtn.bottom() == m_rtMaxBtn.top && m_rtMinBtn.height > 0 && |
291 m_rtMaxBtn.height > 0) || | 279 m_rtMaxBtn.height > 0) || |
292 (0 == m_rtMinBtn.height && 0 == m_rtMaxBtn.height)) { | 280 (0 == m_rtMinBtn.height && 0 == m_rtMaxBtn.height)) { |
293 rect.top += iPos; | 281 rect.top += iPos; |
294 } else { | 282 } else { |
295 rect.top += m_rtMinBtn.bottom() + iPos; | 283 rect.top += m_rtMinBtn.bottom() + iPos; |
296 } | 284 } |
297 } | 285 } |
298 rect.width = IsVertical() ? rtClient.width : fThumbSize; | 286 rect.width = IsVertical() ? rtClient.width : fThumbSize; |
299 rect.height = IsVertical() ? fThumbSize : rtClient.height; | 287 rect.height = IsVertical() ? fThumbSize : rtClient.height; |
300 } else { | 288 } else { |
301 FX_FLOAT iPos = fSize + fDiff * (fTrackPos - m_fRangeMin) / fRange; | 289 FX_FLOAT iPos = fSize + fDiff * (fTrackPos - m_fRangeMin) / fRange; |
302 rect.left = rtClient.left; | 290 rect.left = rtClient.left; |
303 if (!IsVertical()) { | 291 if (!IsVertical()) |
304 rect.left += iPos; | 292 rect.left += iPos; |
305 } | 293 |
306 rect.top = rtClient.top; | 294 rect.top = rtClient.top; |
307 if (IsVertical()) { | 295 if (IsVertical()) |
308 rect.top += iPos; | 296 rect.top += iPos; |
309 } | 297 |
310 rect.width = IsVertical() ? rtClient.width : fThumbSize; | 298 rect.width = IsVertical() ? rtClient.width : fThumbSize; |
311 rect.height = IsVertical() ? fThumbSize : rtClient.height; | 299 rect.height = IsVertical() ? fThumbSize : rtClient.height; |
312 } | 300 } |
313 } | 301 } |
314 | 302 |
315 void IFWL_ScrollBar::CalcMinTrackRect(CFX_RectF& rect) { | 303 void IFWL_ScrollBar::CalcMinTrackRect(CFX_RectF& rect) { |
316 if (m_bMinSize) { | 304 if (m_bMinSize) { |
317 rect.Empty(); | 305 rect.Empty(); |
318 return; | 306 return; |
319 } | 307 } |
| 308 |
320 FX_FLOAT fBottom = m_rtThumb.bottom(); | 309 FX_FLOAT fBottom = m_rtThumb.bottom(); |
321 FX_FLOAT fRight = m_rtThumb.right(); | 310 FX_FLOAT fRight = m_rtThumb.right(); |
322 FX_FLOAT ix = (m_rtThumb.left + fRight) / 2; | 311 FX_FLOAT ix = (m_rtThumb.left + fRight) / 2; |
323 FX_FLOAT iy = (m_rtThumb.top + fBottom) / 2; | 312 FX_FLOAT iy = (m_rtThumb.top + fBottom) / 2; |
324 rect.left = m_rtClient.left; | 313 rect.left = m_rtClient.left; |
325 rect.top = m_rtClient.top; | 314 rect.top = m_rtClient.top; |
326 bool bVertical = IsVertical(); | 315 bool bVertical = IsVertical(); |
327 rect.width = bVertical ? m_rtClient.width : ix; | 316 rect.width = bVertical ? m_rtClient.width : ix; |
328 rect.height = bVertical ? iy : m_rtClient.height; | 317 rect.height = bVertical ? iy : m_rtClient.height; |
329 if (m_bCustomLayout) { | 318 if (!m_bCustomLayout) |
330 if (bVertical) { | 319 return; |
331 if (0 == m_rtMinBtn.height && 0 == m_rtMaxBtn.height) { | 320 |
332 rect.top = m_rtClient.top; | 321 if (bVertical) { |
333 } else if (m_rtMinBtn.top < m_rtThumb.top) { | 322 if (m_rtMinBtn.height == 0 && m_rtMaxBtn.height == 0) { |
334 rect.top = m_rtMinBtn.bottom(); | 323 rect.top = m_rtClient.top; |
335 rect.height -= (m_rtMinBtn.bottom() - m_rtClient.top); | 324 } else if (m_rtMinBtn.top < m_rtThumb.top) { |
336 } | 325 rect.top = m_rtMinBtn.bottom(); |
337 } else { | 326 rect.height -= (m_rtMinBtn.bottom() - m_rtClient.top); |
338 if (0 == m_rtMinBtn.width && 0 == m_rtMaxBtn.width) { | |
339 rect.left = m_rtClient.left; | |
340 } else if (m_rtMinBtn.left < m_rtThumb.left) { | |
341 rect.left = m_rtMinBtn.right(); | |
342 rect.width -= (m_rtMinBtn.right() - m_rtClient.left); | |
343 } | |
344 } | 327 } |
| 328 } else if (m_rtMinBtn.width == 0 && m_rtMaxBtn.width == 0) { |
| 329 rect.left = m_rtClient.left; |
| 330 } else if (m_rtMinBtn.left < m_rtThumb.left) { |
| 331 rect.left = m_rtMinBtn.right(); |
| 332 rect.width -= (m_rtMinBtn.right() - m_rtClient.left); |
345 } | 333 } |
346 } | 334 } |
347 | 335 |
348 void IFWL_ScrollBar::CalcMaxTrackRect(CFX_RectF& rect) { | 336 void IFWL_ScrollBar::CalcMaxTrackRect(CFX_RectF& rect) { |
349 if (m_bMinSize) { | 337 if (m_bMinSize) { |
350 rect.Empty(); | 338 rect.Empty(); |
351 return; | 339 return; |
352 } | 340 } |
| 341 |
353 FX_FLOAT ix = (m_rtThumb.left + m_rtThumb.right()) / 2; | 342 FX_FLOAT ix = (m_rtThumb.left + m_rtThumb.right()) / 2; |
354 FX_FLOAT iy = (m_rtThumb.top + m_rtThumb.bottom()) / 2; | 343 FX_FLOAT iy = (m_rtThumb.top + m_rtThumb.bottom()) / 2; |
355 bool bVertical = IsVertical(); | 344 bool bVertical = IsVertical(); |
356 rect.left = bVertical ? m_rtClient.left : ix; | 345 rect.left = bVertical ? m_rtClient.left : ix; |
357 rect.top = bVertical ? iy : m_rtClient.top; | 346 rect.top = bVertical ? iy : m_rtClient.top; |
358 rect.width = bVertical ? m_rtClient.width : m_rtClient.right() - ix; | 347 rect.width = bVertical ? m_rtClient.width : m_rtClient.right() - ix; |
359 rect.height = bVertical ? m_rtClient.bottom() - iy : m_rtClient.height; | 348 rect.height = bVertical ? m_rtClient.bottom() - iy : m_rtClient.height; |
360 if (m_bCustomLayout) { | 349 if (!m_bCustomLayout) |
361 if (bVertical) { | 350 return; |
362 if (m_rtMinBtn.top > m_rtThumb.top && m_rtMinBtn.height > 0 && | 351 |
363 m_rtMaxBtn.height > 0) { | 352 if (bVertical) { |
364 rect.height -= (m_rtClient.bottom() - m_rtMinBtn.top); | 353 if (m_rtMinBtn.top > m_rtThumb.top && m_rtMinBtn.height > 0 && |
365 } else if (m_rtMinBtn.height > 0 && m_rtMaxBtn.height > 0) { | 354 m_rtMaxBtn.height > 0) { |
366 rect.height -= (m_rtClient.bottom() - m_rtMaxBtn.top); | 355 rect.height -= (m_rtClient.bottom() - m_rtMinBtn.top); |
367 } | 356 } else if (m_rtMinBtn.height > 0 && m_rtMaxBtn.height > 0) { |
368 } else { | 357 rect.height -= (m_rtClient.bottom() - m_rtMaxBtn.top); |
369 if (m_rtMinBtn.left > m_rtThumb.left && m_rtMinBtn.width > 0 && | |
370 m_rtMaxBtn.width > 0) { | |
371 rect.width -= (m_rtClient.right() - m_rtMinBtn.left); | |
372 } else if (m_rtMinBtn.width > 0 && m_rtMaxBtn.width > 0) { | |
373 rect.width -= (m_rtClient.right() - m_rtMaxBtn.left); | |
374 } | |
375 } | 358 } |
| 359 } else if (m_rtMinBtn.left > m_rtThumb.left && m_rtMinBtn.width > 0 && |
| 360 m_rtMaxBtn.width > 0) { |
| 361 rect.width -= (m_rtClient.right() - m_rtMinBtn.left); |
| 362 } else if (m_rtMinBtn.width > 0 && m_rtMaxBtn.width > 0) { |
| 363 rect.width -= (m_rtClient.right() - m_rtMaxBtn.left); |
376 } | 364 } |
377 } | 365 } |
378 | 366 |
379 FX_FLOAT IFWL_ScrollBar::GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy) { | 367 FX_FLOAT IFWL_ScrollBar::GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy) { |
380 FX_FLOAT fDiffX = fx - m_cpTrackPointX; | 368 FX_FLOAT fDiffX = fx - m_cpTrackPointX; |
381 FX_FLOAT fDiffY = fy - m_cpTrackPointY; | 369 FX_FLOAT fDiffY = fy - m_cpTrackPointY; |
382 FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; | 370 FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; |
383 FX_FLOAT fPos; | 371 FX_FLOAT fPos; |
384 if (m_bCustomLayout) { | 372 if (m_bCustomLayout) { |
385 if (IsVertical()) { | 373 if (IsVertical()) { |
386 if (0 == m_rtMinBtn.height && 0 == m_rtMaxBtn.height) { | 374 if (m_rtMinBtn.height == 0 && m_rtMaxBtn.height == 0) { |
387 fPos = fRange * fDiffY / (m_rtClient.height - m_rtThumb.height); | 375 fPos = fRange * fDiffY / (m_rtClient.height - m_rtThumb.height); |
388 } else if (m_rtMinBtn.bottom() == m_rtMaxBtn.top) { | 376 } else if (m_rtMinBtn.bottom() == m_rtMaxBtn.top) { |
389 fPos = fRange * fDiffY / | 377 fPos = fRange * fDiffY / |
390 (m_rtMinBtn.top - m_rtClient.top - m_rtThumb.height); | 378 (m_rtMinBtn.top - m_rtClient.top - m_rtThumb.height); |
391 } else { | 379 } else { |
392 fPos = fRange * fDiffY / | 380 fPos = fRange * fDiffY / |
393 (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height); | 381 (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height); |
394 } | 382 } |
395 } else { | 383 } else { |
396 if (0 == m_rtMinBtn.width && 0 == m_rtMaxBtn.width) { | 384 if (m_rtMinBtn.width == 0 && m_rtMaxBtn.width == 0) { |
397 fPos = fRange * fDiffX / (m_rtClient.width - m_rtThumb.width); | 385 fPos = fRange * fDiffX / (m_rtClient.width - m_rtThumb.width); |
398 } else if (m_rtMinBtn.right() == m_rtMaxBtn.left) { | 386 } else if (m_rtMinBtn.right() == m_rtMaxBtn.left) { |
399 fPos = fRange * fDiffX / | 387 fPos = fRange * fDiffX / |
400 (m_rtMinBtn.left - m_rtClient.left - m_rtThumb.width); | 388 (m_rtMinBtn.left - m_rtClient.left - m_rtThumb.width); |
401 } else { | 389 } else { |
402 fPos = fRange * fDiffX / | 390 fPos = fRange * fDiffX / |
403 (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width); | 391 (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width); |
404 } | 392 } |
405 } | 393 } |
406 } else { | 394 } else { |
407 if (IsVertical()) { | 395 if (IsVertical()) { |
408 fPos = fRange * fDiffY / | 396 fPos = fRange * fDiffY / |
409 (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height); | 397 (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height); |
410 } else { | 398 } else { |
411 fPos = fRange * fDiffX / | 399 fPos = fRange * fDiffX / |
412 (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width); | 400 (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width); |
413 } | 401 } |
414 } | 402 } |
415 fPos += m_fLastTrackPos; | 403 fPos += m_fLastTrackPos; |
416 if (fPos < m_fRangeMin) { | 404 return std::min(std::max(fPos, m_fRangeMin), m_fRangeMax); |
417 fPos = m_fRangeMin; | |
418 } | |
419 if (fPos > m_fRangeMax) { | |
420 fPos = m_fRangeMax; | |
421 } | |
422 return fPos; | |
423 } | 405 } |
424 | 406 |
425 void IFWL_ScrollBar::GetTrackRect(CFX_RectF& rect, bool bLower) { | 407 void IFWL_ScrollBar::GetTrackRect(CFX_RectF& rect, bool bLower) { |
426 bool bDisabled = !!(m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled); | 408 bool bDisabled = !!(m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled); |
427 if (bDisabled || m_bCustomLayout) { | 409 if (bDisabled || m_bCustomLayout) { |
428 rect = bLower ? m_rtMinTrack : m_rtMaxTrack; | 410 rect = bLower ? m_rtMinTrack : m_rtMaxTrack; |
429 } else { | 411 return; |
430 FX_FLOAT fW = m_rtThumb.width / 2; | 412 } |
431 FX_FLOAT fH = m_rtThumb.height / 2; | 413 |
432 bool bVert = IsVertical(); | 414 FX_FLOAT fW = m_rtThumb.width / 2; |
433 if (bLower) { | 415 FX_FLOAT fH = m_rtThumb.height / 2; |
434 if (bVert) { | 416 bool bVert = IsVertical(); |
435 FX_FLOAT fMinTrackHeight = m_rtMinTrack.height - fH - m_rtMinBtn.height; | 417 if (bLower) { |
436 fMinTrackHeight = (fMinTrackHeight >= 0.0f) ? fMinTrackHeight : 0.0f; | 418 if (bVert) { |
437 rect.Set(m_rtMinTrack.left, m_rtMinTrack.top + m_rtMinBtn.height, | 419 FX_FLOAT fMinTrackHeight = m_rtMinTrack.height - fH - m_rtMinBtn.height; |
438 m_rtMinTrack.width, fMinTrackHeight); | 420 fMinTrackHeight = (fMinTrackHeight >= 0.0f) ? fMinTrackHeight : 0.0f; |
439 } else { | 421 rect.Set(m_rtMinTrack.left, m_rtMinTrack.top + m_rtMinBtn.height, |
440 FX_FLOAT fMinTrackWidth = | 422 m_rtMinTrack.width, fMinTrackHeight); |
441 m_rtMinTrack.width - fW - m_rtMinBtn.width + 2; | 423 return; |
442 fMinTrackWidth = (fMinTrackWidth >= 0.0f) ? fMinTrackWidth : 0.0f; | |
443 rect.Set(m_rtMinTrack.left + m_rtMinBtn.width - 1, m_rtMinTrack.top, | |
444 fMinTrackWidth, m_rtMinTrack.height); | |
445 } | |
446 } else { | |
447 if (bVert) { | |
448 FX_FLOAT fMaxTrackHeight = m_rtMaxTrack.height - fH - m_rtMaxBtn.height; | |
449 fMaxTrackHeight = (fMaxTrackHeight >= 0.0f) ? fMaxTrackHeight : 0.0f; | |
450 rect.Set(m_rtMaxTrack.left, m_rtMaxTrack.top + fH, m_rtMaxTrack.width, | |
451 fMaxTrackHeight); | |
452 } else { | |
453 FX_FLOAT fMaxTrackWidth = | |
454 m_rtMaxTrack.width - fW - m_rtMaxBtn.width + 2; | |
455 fMaxTrackWidth = (fMaxTrackWidth >= 0.0f) ? fMaxTrackWidth : 0.0f; | |
456 rect.Set(m_rtMaxTrack.left + fW, m_rtMaxTrack.top, fMaxTrackWidth, | |
457 m_rtMaxTrack.height); | |
458 } | |
459 } | 424 } |
| 425 |
| 426 FX_FLOAT fMinTrackWidth = m_rtMinTrack.width - fW - m_rtMinBtn.width + 2; |
| 427 fMinTrackWidth = (fMinTrackWidth >= 0.0f) ? fMinTrackWidth : 0.0f; |
| 428 rect.Set(m_rtMinTrack.left + m_rtMinBtn.width - 1, m_rtMinTrack.top, |
| 429 fMinTrackWidth, m_rtMinTrack.height); |
| 430 return; |
460 } | 431 } |
| 432 |
| 433 if (bVert) { |
| 434 FX_FLOAT fMaxTrackHeight = m_rtMaxTrack.height - fH - m_rtMaxBtn.height; |
| 435 fMaxTrackHeight = (fMaxTrackHeight >= 0.0f) ? fMaxTrackHeight : 0.0f; |
| 436 rect.Set(m_rtMaxTrack.left, m_rtMaxTrack.top + fH, m_rtMaxTrack.width, |
| 437 fMaxTrackHeight); |
| 438 return; |
| 439 } |
| 440 |
| 441 FX_FLOAT fMaxTrackWidth = m_rtMaxTrack.width - fW - m_rtMaxBtn.width + 2; |
| 442 fMaxTrackWidth = (fMaxTrackWidth >= 0.0f) ? fMaxTrackWidth : 0.0f; |
| 443 rect.Set(m_rtMaxTrack.left + fW, m_rtMaxTrack.top, fMaxTrackWidth, |
| 444 m_rtMaxTrack.height); |
461 } | 445 } |
462 | 446 |
463 bool IFWL_ScrollBar::SendEvent() { | 447 bool IFWL_ScrollBar::SendEvent() { |
464 if (m_iMinButtonState == CFWL_PartState_Pressed) { | 448 if (m_iMinButtonState == CFWL_PartState_Pressed) { |
465 DoScroll(FWL_SCBCODE::StepBackward, m_fTrackPos); | 449 DoScroll(FWL_SCBCODE::StepBackward, m_fTrackPos); |
466 return false; | 450 return false; |
467 } | 451 } |
468 if (m_iMaxButtonState == CFWL_PartState_Pressed) { | 452 if (m_iMaxButtonState == CFWL_PartState_Pressed) { |
469 DoScroll(FWL_SCBCODE::StepForward, m_fTrackPos); | 453 DoScroll(FWL_SCBCODE::StepForward, m_fTrackPos); |
470 return false; | 454 return false; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 | 578 |
595 void IFWL_ScrollBar::DoMouseDown(int32_t iItem, | 579 void IFWL_ScrollBar::DoMouseDown(int32_t iItem, |
596 const CFX_RectF& rtItem, | 580 const CFX_RectF& rtItem, |
597 int32_t& iState, | 581 int32_t& iState, |
598 FX_FLOAT fx, | 582 FX_FLOAT fx, |
599 FX_FLOAT fy) { | 583 FX_FLOAT fy) { |
600 if (!rtItem.Contains(fx, fy)) | 584 if (!rtItem.Contains(fx, fy)) |
601 return; | 585 return; |
602 if (iState == CFWL_PartState_Pressed) | 586 if (iState == CFWL_PartState_Pressed) |
603 return; | 587 return; |
| 588 |
604 iState = CFWL_PartState_Pressed; | 589 iState = CFWL_PartState_Pressed; |
605 Repaint(&rtItem); | 590 Repaint(&rtItem); |
606 } | 591 } |
607 | 592 |
608 void IFWL_ScrollBar::DoMouseUp(int32_t iItem, | 593 void IFWL_ScrollBar::DoMouseUp(int32_t iItem, |
609 const CFX_RectF& rtItem, | 594 const CFX_RectF& rtItem, |
610 int32_t& iState, | 595 int32_t& iState, |
611 FX_FLOAT fx, | 596 FX_FLOAT fx, |
612 FX_FLOAT fy) { | 597 FX_FLOAT fy) { |
613 int32_t iNewState = | 598 int32_t iNewState = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 | 649 |
665 void IFWL_ScrollBar::Timer::Run(IFWL_TimerInfo* pTimerInfo) { | 650 void IFWL_ScrollBar::Timer::Run(IFWL_TimerInfo* pTimerInfo) { |
666 IFWL_ScrollBar* pButton = static_cast<IFWL_ScrollBar*>(m_pWidget); | 651 IFWL_ScrollBar* pButton = static_cast<IFWL_ScrollBar*>(m_pWidget); |
667 | 652 |
668 if (pButton->m_pTimerInfo) | 653 if (pButton->m_pTimerInfo) |
669 pButton->m_pTimerInfo->StopTimer(); | 654 pButton->m_pTimerInfo->StopTimer(); |
670 | 655 |
671 if (!pButton->SendEvent()) | 656 if (!pButton->SendEvent()) |
672 pButton->m_pTimerInfo = StartTimer(0, true); | 657 pButton->m_pTimerInfo = StartTimer(0, true); |
673 } | 658 } |
OLD | NEW |