| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "xfa/fwl/basewidget/fwl_scrollbarimp.h" | |
| 8 | |
| 9 #include "xfa/fwl/basewidget/ifwl_scrollbar.h" | |
| 10 #include "xfa/fwl/core/cfwl_message.h" | |
| 11 #include "xfa/fwl/core/cfwl_themebackground.h" | |
| 12 #include "xfa/fwl/core/cfwl_themepart.h" | |
| 13 #include "xfa/fwl/core/fwl_noteimp.h" | |
| 14 #include "xfa/fwl/core/fwl_widgetimp.h" | |
| 15 #include "xfa/fwl/core/ifwl_themeprovider.h" | |
| 16 | |
| 17 #define FWL_SCROLLBAR_Elapse 500 | |
| 18 #define FWL_SCROLLBAR_MinThumb 5 | |
| 19 | |
| 20 // static | |
| 21 IFWL_ScrollBar* IFWL_ScrollBar::Create( | |
| 22 const CFWL_WidgetImpProperties& properties, | |
| 23 IFWL_Widget* pOuter) { | |
| 24 IFWL_ScrollBar* pScrollBar = new IFWL_ScrollBar; | |
| 25 CFWL_ScrollBarImp* pScrollBarImpl = new CFWL_ScrollBarImp(properties, pOuter); | |
| 26 pScrollBar->SetImpl(pScrollBarImpl); | |
| 27 pScrollBarImpl->SetInterface(pScrollBar); | |
| 28 return pScrollBar; | |
| 29 } | |
| 30 IFWL_ScrollBar::IFWL_ScrollBar() {} | |
| 31 FX_BOOL IFWL_ScrollBar::IsVertical() { | |
| 32 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->IsVertical(); | |
| 33 } | |
| 34 FWL_Error IFWL_ScrollBar::GetRange(FX_FLOAT& fMin, FX_FLOAT& fMax) { | |
| 35 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->GetRange(fMin, fMax); | |
| 36 } | |
| 37 FWL_Error IFWL_ScrollBar::SetRange(FX_FLOAT fMin, FX_FLOAT fMax) { | |
| 38 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->SetRange(fMin, fMax); | |
| 39 } | |
| 40 FX_FLOAT IFWL_ScrollBar::GetPageSize() { | |
| 41 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->GetPageSize(); | |
| 42 } | |
| 43 FWL_Error IFWL_ScrollBar::SetPageSize(FX_FLOAT fPageSize) { | |
| 44 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->SetPageSize(fPageSize); | |
| 45 } | |
| 46 FX_FLOAT IFWL_ScrollBar::GetStepSize() { | |
| 47 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->GetStepSize(); | |
| 48 } | |
| 49 FWL_Error IFWL_ScrollBar::SetStepSize(FX_FLOAT fStepSize) { | |
| 50 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->SetStepSize(fStepSize); | |
| 51 } | |
| 52 FX_FLOAT IFWL_ScrollBar::GetPos() { | |
| 53 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->GetPos(); | |
| 54 } | |
| 55 FWL_Error IFWL_ScrollBar::SetPos(FX_FLOAT fPos) { | |
| 56 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->SetPos(fPos); | |
| 57 } | |
| 58 FX_FLOAT IFWL_ScrollBar::GetTrackPos() { | |
| 59 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->GetTrackPos(); | |
| 60 } | |
| 61 FWL_Error IFWL_ScrollBar::SetTrackPos(FX_FLOAT fTrackPos) { | |
| 62 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->SetTrackPos(fTrackPos); | |
| 63 } | |
| 64 FX_BOOL IFWL_ScrollBar::DoScroll(uint32_t dwCode, FX_FLOAT fPos) { | |
| 65 return static_cast<CFWL_ScrollBarImp*>(GetImpl())->DoScroll(dwCode, fPos); | |
| 66 } | |
| 67 CFWL_ScrollBarImp::CFWL_ScrollBarImp(const CFWL_WidgetImpProperties& properties, | |
| 68 IFWL_Widget* pOuter) | |
| 69 : CFWL_WidgetImp(properties, pOuter), | |
| 70 m_pTimerInfo(nullptr), | |
| 71 m_fRangeMin(0), | |
| 72 m_fRangeMax(-1), | |
| 73 m_fPageSize(0), | |
| 74 m_fStepSize(0), | |
| 75 m_fPos(0), | |
| 76 m_fTrackPos(0), | |
| 77 m_iMinButtonState(CFWL_PartState_Normal), | |
| 78 m_iMaxButtonState(CFWL_PartState_Normal), | |
| 79 m_iThumbButtonState(CFWL_PartState_Normal), | |
| 80 m_iMinTrackState(CFWL_PartState_Normal), | |
| 81 m_iMaxTrackState(CFWL_PartState_Normal), | |
| 82 m_fLastTrackPos(0), | |
| 83 m_cpTrackPointX(0), | |
| 84 m_cpTrackPointY(0), | |
| 85 m_iMouseWheel(0), | |
| 86 m_bTrackMouseLeave(FALSE), | |
| 87 m_bMouseHover(FALSE), | |
| 88 m_bMouseDown(FALSE), | |
| 89 m_bRepaintThumb(FALSE), | |
| 90 m_fButtonLen(0), | |
| 91 m_bMinSize(FALSE), | |
| 92 m_bCustomLayout(FALSE), | |
| 93 m_fMinThumb(FWL_SCROLLBAR_MinThumb) { | |
| 94 m_rtClient.Reset(); | |
| 95 m_rtThumb.Reset(); | |
| 96 m_rtMinBtn.Reset(); | |
| 97 m_rtMaxBtn.Reset(); | |
| 98 m_rtMinTrack.Reset(); | |
| 99 m_rtMaxTrack.Reset(); | |
| 100 } | |
| 101 | |
| 102 CFWL_ScrollBarImp::~CFWL_ScrollBarImp() {} | |
| 103 | |
| 104 FWL_Error CFWL_ScrollBarImp::GetClassName(CFX_WideString& wsClass) const { | |
| 105 wsClass = FWL_CLASS_ScrollBar; | |
| 106 return FWL_Error::Succeeded; | |
| 107 } | |
| 108 | |
| 109 FWL_Type CFWL_ScrollBarImp::GetClassID() const { | |
| 110 return FWL_Type::ScrollBar; | |
| 111 } | |
| 112 | |
| 113 FWL_Error CFWL_ScrollBarImp::Initialize() { | |
| 114 if (CFWL_WidgetImp::Initialize() != FWL_Error::Succeeded) | |
| 115 return FWL_Error::Indefinite; | |
| 116 | |
| 117 m_pDelegate = new CFWL_ScrollBarImpDelegate(this); | |
| 118 return FWL_Error::Succeeded; | |
| 119 } | |
| 120 | |
| 121 FWL_Error CFWL_ScrollBarImp::Finalize() { | |
| 122 delete m_pDelegate; | |
| 123 m_pDelegate = nullptr; | |
| 124 return CFWL_WidgetImp::Finalize(); | |
| 125 } | |
| 126 FWL_Error CFWL_ScrollBarImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | |
| 127 if (bAutoSize) { | |
| 128 rect.Set(0, 0, 0, 0); | |
| 129 FX_FLOAT* pfMinWidth = static_cast<FX_FLOAT*>( | |
| 130 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | |
| 131 if (!pfMinWidth) | |
| 132 return FWL_Error::Indefinite; | |
| 133 if (IsVertical()) { | |
| 134 rect.Set(0, 0, (*pfMinWidth), (*pfMinWidth) * 3); | |
| 135 } else { | |
| 136 rect.Set(0, 0, (*pfMinWidth) * 3, (*pfMinWidth)); | |
| 137 } | |
| 138 CFWL_WidgetImp::GetWidgetRect(rect, TRUE); | |
| 139 } else { | |
| 140 rect = m_pProperties->m_rtWidget; | |
| 141 } | |
| 142 return FWL_Error::Succeeded; | |
| 143 } | |
| 144 FWL_Error CFWL_ScrollBarImp::Update() { | |
| 145 if (IsLocked()) { | |
| 146 return FWL_Error::Indefinite; | |
| 147 } | |
| 148 if (!m_pProperties->m_pThemeProvider) { | |
| 149 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
| 150 } | |
| 151 Layout(); | |
| 152 return FWL_Error::Succeeded; | |
| 153 } | |
| 154 FWL_Error CFWL_ScrollBarImp::DrawWidget(CFX_Graphics* pGraphics, | |
| 155 const CFX_Matrix* pMatrix) { | |
| 156 if (!pGraphics) | |
| 157 return FWL_Error::Indefinite; | |
| 158 if (!m_pProperties->m_pThemeProvider) | |
| 159 return FWL_Error::Indefinite; | |
| 160 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
| 161 if (HasBorder()) { | |
| 162 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | |
| 163 } | |
| 164 if (HasEdge()) { | |
| 165 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | |
| 166 } | |
| 167 DrawTrack(pGraphics, pTheme, TRUE, pMatrix); | |
| 168 DrawTrack(pGraphics, pTheme, FALSE, pMatrix); | |
| 169 DrawArrowBtn(pGraphics, pTheme, TRUE, pMatrix); | |
| 170 DrawArrowBtn(pGraphics, pTheme, FALSE, pMatrix); | |
| 171 DrawThumb(pGraphics, pTheme, pMatrix); | |
| 172 return FWL_Error::Succeeded; | |
| 173 } | |
| 174 inline FX_BOOL CFWL_ScrollBarImp::IsVertical() { | |
| 175 return m_pProperties->m_dwStyleExes & FWL_STYLEEXT_SCB_Vert; | |
| 176 } | |
| 177 FWL_Error CFWL_ScrollBarImp::GetRange(FX_FLOAT& fMin, FX_FLOAT& fMax) { | |
| 178 fMin = m_fRangeMin; | |
| 179 fMax = m_fRangeMax; | |
| 180 return FWL_Error::Succeeded; | |
| 181 } | |
| 182 FWL_Error CFWL_ScrollBarImp::SetRange(FX_FLOAT fMin, FX_FLOAT fMax) { | |
| 183 m_fRangeMin = fMin; | |
| 184 m_fRangeMax = fMax; | |
| 185 return FWL_Error::Succeeded; | |
| 186 } | |
| 187 FX_FLOAT CFWL_ScrollBarImp::GetPageSize() { | |
| 188 return m_fPageSize; | |
| 189 } | |
| 190 FWL_Error CFWL_ScrollBarImp::SetPageSize(FX_FLOAT fPageSize) { | |
| 191 m_fPageSize = fPageSize; | |
| 192 return FWL_Error::Succeeded; | |
| 193 } | |
| 194 FX_FLOAT CFWL_ScrollBarImp::GetStepSize() { | |
| 195 return m_fStepSize; | |
| 196 } | |
| 197 FWL_Error CFWL_ScrollBarImp::SetStepSize(FX_FLOAT fStepSize) { | |
| 198 m_fStepSize = fStepSize; | |
| 199 return FWL_Error::Succeeded; | |
| 200 } | |
| 201 FX_FLOAT CFWL_ScrollBarImp::GetPos() { | |
| 202 return m_fPos; | |
| 203 } | |
| 204 FWL_Error CFWL_ScrollBarImp::SetPos(FX_FLOAT fPos) { | |
| 205 m_fPos = fPos; | |
| 206 return FWL_Error::Succeeded; | |
| 207 } | |
| 208 FX_FLOAT CFWL_ScrollBarImp::GetTrackPos() { | |
| 209 return m_fTrackPos; | |
| 210 } | |
| 211 FWL_Error CFWL_ScrollBarImp::SetTrackPos(FX_FLOAT fTrackPos) { | |
| 212 m_fTrackPos = fTrackPos; | |
| 213 CalcThumbButtonRect(m_rtThumb); | |
| 214 CalcMinTrackRect(m_rtMinTrack); | |
| 215 CalcMaxTrackRect(m_rtMaxTrack); | |
| 216 return FWL_Error::Succeeded; | |
| 217 } | |
| 218 FX_BOOL CFWL_ScrollBarImp::DoScroll(uint32_t dwCode, FX_FLOAT fPos) { | |
| 219 switch (dwCode) { | |
| 220 case FWL_SCBCODE_Min: | |
| 221 case FWL_SCBCODE_Max: | |
| 222 case FWL_SCBCODE_PageBackward: | |
| 223 case FWL_SCBCODE_PageForward: | |
| 224 case FWL_SCBCODE_StepBackward: | |
| 225 break; | |
| 226 case FWL_SCBCODE_StepForward: | |
| 227 break; | |
| 228 case FWL_SCBCODE_Pos: | |
| 229 case FWL_SCBCODE_TrackPos: | |
| 230 case FWL_SCBCODE_EndScroll: | |
| 231 break; | |
| 232 default: { return FALSE; } | |
| 233 } | |
| 234 return OnScroll(dwCode, fPos); | |
| 235 } | |
| 236 | |
| 237 void CFWL_ScrollBarImp::Run(IFWL_TimerInfo* pTimerInfo) { | |
| 238 if (m_pTimerInfo) | |
| 239 m_pTimerInfo->StopTimer(); | |
| 240 | |
| 241 if (!SendEvent()) | |
| 242 m_pTimerInfo = StartTimer(0, true); | |
| 243 } | |
| 244 | |
| 245 FWL_Error CFWL_ScrollBarImp::SetOuter(IFWL_Widget* pOuter) { | |
| 246 m_pOuter = pOuter; | |
| 247 return FWL_Error::Succeeded; | |
| 248 } | |
| 249 void CFWL_ScrollBarImp::DrawTrack(CFX_Graphics* pGraphics, | |
| 250 IFWL_ThemeProvider* pTheme, | |
| 251 FX_BOOL bLower, | |
| 252 const CFX_Matrix* pMatrix) { | |
| 253 CFWL_ThemeBackground param; | |
| 254 param.m_pWidget = m_pInterface; | |
| 255 param.m_iPart = bLower ? CFWL_Part::LowerTrack : CFWL_Part::UpperTrack; | |
| 256 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | |
| 257 ? CFWL_PartState_Disabled | |
| 258 : (bLower ? m_iMinTrackState : m_iMaxTrackState); | |
| 259 param.m_pGraphics = pGraphics; | |
| 260 param.m_matrix.Concat(*pMatrix); | |
| 261 param.m_rtPart = bLower ? m_rtMinTrack : m_rtMaxTrack; | |
| 262 pTheme->DrawBackground(¶m); | |
| 263 } | |
| 264 void CFWL_ScrollBarImp::DrawArrowBtn(CFX_Graphics* pGraphics, | |
| 265 IFWL_ThemeProvider* pTheme, | |
| 266 FX_BOOL bMinBtn, | |
| 267 const CFX_Matrix* pMatrix) { | |
| 268 CFWL_ThemeBackground param; | |
| 269 param.m_pWidget = m_pInterface; | |
| 270 param.m_iPart = bMinBtn ? CFWL_Part::ForeArrow : CFWL_Part::BackArrow; | |
| 271 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | |
| 272 ? CFWL_PartState_Disabled | |
| 273 : (bMinBtn ? m_iMinButtonState : m_iMaxButtonState); | |
| 274 param.m_pGraphics = pGraphics; | |
| 275 param.m_matrix.Concat(*pMatrix); | |
| 276 param.m_rtPart = bMinBtn ? m_rtMinBtn : m_rtMaxBtn; | |
| 277 if (param.m_rtPart.height > 0 && param.m_rtPart.width > 0) { | |
| 278 pTheme->DrawBackground(¶m); | |
| 279 } | |
| 280 } | |
| 281 void CFWL_ScrollBarImp::DrawThumb(CFX_Graphics* pGraphics, | |
| 282 IFWL_ThemeProvider* pTheme, | |
| 283 const CFX_Matrix* pMatrix) { | |
| 284 CFWL_ThemeBackground param; | |
| 285 param.m_pWidget = m_pInterface; | |
| 286 param.m_iPart = CFWL_Part::Thumb; | |
| 287 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | |
| 288 ? CFWL_PartState_Disabled | |
| 289 : m_iThumbButtonState; | |
| 290 param.m_pGraphics = pGraphics; | |
| 291 param.m_matrix.Concat(*pMatrix); | |
| 292 param.m_rtPart = m_rtThumb; | |
| 293 pTheme->DrawBackground(¶m); | |
| 294 } | |
| 295 void CFWL_ScrollBarImp::Layout() { | |
| 296 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
| 297 CFWL_ThemePart part; | |
| 298 part.m_pWidget = m_pInterface; | |
| 299 m_fMinThumb = *static_cast<FX_FLOAT*>( | |
| 300 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Size)); | |
| 301 m_bCustomLayout = pTheme->IsCustomizedLayout(m_pInterface); | |
| 302 GetClientRect(m_rtClient); | |
| 303 CalcButtonLen(); | |
| 304 CalcMinButtonRect(m_rtMinBtn); | |
| 305 CalcMaxButtonRect(m_rtMaxBtn); | |
| 306 CalcThumbButtonRect(m_rtThumb); | |
| 307 CalcMinTrackRect(m_rtMinTrack); | |
| 308 CalcMaxTrackRect(m_rtMaxTrack); | |
| 309 } | |
| 310 void CFWL_ScrollBarImp::CalcButtonLen() { | |
| 311 m_fButtonLen = IsVertical() ? m_rtClient.width : m_rtClient.height; | |
| 312 FX_FLOAT fLength = IsVertical() ? m_rtClient.height : m_rtClient.width; | |
| 313 if (fLength < m_fButtonLen * 2) { | |
| 314 m_fButtonLen = fLength / 2; | |
| 315 m_bMinSize = TRUE; | |
| 316 } else { | |
| 317 m_bMinSize = FALSE; | |
| 318 } | |
| 319 } | |
| 320 void CFWL_ScrollBarImp::CalcMinButtonRect(CFX_RectF& rect) { | |
| 321 if (m_bCustomLayout) | |
| 322 return; | |
| 323 | |
| 324 rect.left = m_rtClient.left; | |
| 325 rect.top = m_rtClient.top; | |
| 326 rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen; | |
| 327 rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height; | |
| 328 } | |
| 329 | |
| 330 void CFWL_ScrollBarImp::CalcMaxButtonRect(CFX_RectF& rect) { | |
| 331 if (m_bCustomLayout) | |
| 332 return; | |
| 333 | |
| 334 rect.left = | |
| 335 IsVertical() ? m_rtClient.left : m_rtClient.right() - m_fButtonLen; | |
| 336 rect.top = IsVertical() ? m_rtClient.bottom() - m_fButtonLen : m_rtClient.top; | |
| 337 rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen; | |
| 338 rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height; | |
| 339 } | |
| 340 | |
| 341 void CFWL_ScrollBarImp::CalcThumbButtonRect(CFX_RectF& rect) { | |
| 342 if (!IsEnabled()) { | |
| 343 m_rtThumb.Reset(); | |
| 344 return; | |
| 345 } | |
| 346 if (m_bMinSize) { | |
| 347 m_rtThumb.Empty(); | |
| 348 return; | |
| 349 } | |
| 350 FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; | |
| 351 memset(&rect, 0, sizeof(CFX_Rect)); | |
| 352 if (fRange < 0) { | |
| 353 if (IsVertical()) { | |
| 354 rect.Set(m_rtClient.left, m_rtMaxBtn.bottom(), m_rtClient.width, 0); | |
| 355 } else { | |
| 356 rect.Set(m_rtMaxBtn.right(), m_rtClient.top, 0, m_rtClient.height); | |
| 357 } | |
| 358 return; | |
| 359 } | |
| 360 CFX_RectF rtClient = m_rtClient; | |
| 361 FX_FLOAT fLength = IsVertical() ? rtClient.height : rtClient.width; | |
| 362 FX_FLOAT fSize = m_fButtonLen; | |
| 363 if (m_bCustomLayout) { | |
| 364 if (IsVertical()) { | |
| 365 fLength = fLength - m_rtMinBtn.height - m_rtMaxBtn.height; | |
| 366 if (fLength < m_rtMinBtn.height || fLength < m_rtMaxBtn.height) { | |
| 367 fLength = 0.0f; | |
| 368 } | |
| 369 } else { | |
| 370 fLength = fLength - m_rtMinBtn.width - m_rtMaxBtn.width; | |
| 371 if (fLength < m_rtMinBtn.width || fLength < m_rtMaxBtn.width) { | |
| 372 fLength = 0.0f; | |
| 373 } | |
| 374 } | |
| 375 } else { | |
| 376 fLength -= fSize * 2.0f; | |
| 377 if (fLength < fSize) { | |
| 378 fLength = 0.0f; | |
| 379 } | |
| 380 } | |
| 381 FX_FLOAT fThumbSize = fLength * fLength / (fRange + fLength); | |
| 382 if (fThumbSize < m_fMinThumb) { | |
| 383 fThumbSize = m_fMinThumb; | |
| 384 } | |
| 385 FX_FLOAT fDiff = fLength - fThumbSize; | |
| 386 if (fDiff < 0.0f) { | |
| 387 fDiff = 0.0f; | |
| 388 } | |
| 389 FX_FLOAT fTrackPos = m_fTrackPos; | |
| 390 if (fTrackPos > m_fRangeMax) { | |
| 391 fTrackPos = m_fRangeMax; | |
| 392 } | |
| 393 if (fTrackPos < m_fRangeMin) { | |
| 394 fTrackPos = m_fRangeMin; | |
| 395 } | |
| 396 if (!fRange) | |
| 397 return; | |
| 398 if (m_bCustomLayout) { | |
| 399 FX_FLOAT iPos = fDiff * (fTrackPos - m_fRangeMin) / fRange; | |
| 400 rect.left = rtClient.left; | |
| 401 if (!IsVertical()) { | |
| 402 if ((m_rtMinBtn.right() == m_rtMaxBtn.left && m_rtMinBtn.width > 0 && | |
| 403 m_rtMaxBtn.width > 0) || | |
| 404 (0 == m_rtMinBtn.width && 0 == m_rtMaxBtn.width)) { | |
| 405 rect.left += iPos; | |
| 406 } else { | |
| 407 rect.left += m_rtMinBtn.right() + iPos; | |
| 408 } | |
| 409 } | |
| 410 rect.top = rtClient.top; | |
| 411 if (IsVertical()) { | |
| 412 if ((m_rtMinBtn.bottom() == m_rtMaxBtn.top && m_rtMinBtn.height > 0 && | |
| 413 m_rtMaxBtn.height > 0) || | |
| 414 (0 == m_rtMinBtn.height && 0 == m_rtMaxBtn.height)) { | |
| 415 rect.top += iPos; | |
| 416 } else { | |
| 417 rect.top += m_rtMinBtn.bottom() + iPos; | |
| 418 } | |
| 419 } | |
| 420 rect.width = IsVertical() ? rtClient.width : fThumbSize; | |
| 421 rect.height = IsVertical() ? fThumbSize : rtClient.height; | |
| 422 } else { | |
| 423 FX_FLOAT iPos = fSize + fDiff * (fTrackPos - m_fRangeMin) / fRange; | |
| 424 rect.left = rtClient.left; | |
| 425 if (!IsVertical()) { | |
| 426 rect.left += iPos; | |
| 427 } | |
| 428 rect.top = rtClient.top; | |
| 429 if (IsVertical()) { | |
| 430 rect.top += iPos; | |
| 431 } | |
| 432 rect.width = IsVertical() ? rtClient.width : fThumbSize; | |
| 433 rect.height = IsVertical() ? fThumbSize : rtClient.height; | |
| 434 } | |
| 435 } | |
| 436 void CFWL_ScrollBarImp::CalcMinTrackRect(CFX_RectF& rect) { | |
| 437 if (m_bMinSize) { | |
| 438 rect.Empty(); | |
| 439 return; | |
| 440 } | |
| 441 FX_FLOAT fBottom = m_rtThumb.bottom(); | |
| 442 FX_FLOAT fRight = m_rtThumb.right(); | |
| 443 FX_FLOAT ix = (m_rtThumb.left + fRight) / 2; | |
| 444 FX_FLOAT iy = (m_rtThumb.top + fBottom) / 2; | |
| 445 rect.left = m_rtClient.left; | |
| 446 rect.top = m_rtClient.top; | |
| 447 FX_BOOL bVertical = IsVertical(); | |
| 448 rect.width = bVertical ? m_rtClient.width : ix; | |
| 449 rect.height = bVertical ? iy : m_rtClient.height; | |
| 450 if (m_bCustomLayout) { | |
| 451 if (bVertical) { | |
| 452 if (0 == m_rtMinBtn.height && 0 == m_rtMaxBtn.height) { | |
| 453 rect.top = m_rtClient.top; | |
| 454 } else if (m_rtMinBtn.top < m_rtThumb.top) { | |
| 455 rect.top = m_rtMinBtn.bottom(); | |
| 456 rect.height -= (m_rtMinBtn.bottom() - m_rtClient.top); | |
| 457 } | |
| 458 } else { | |
| 459 if (0 == m_rtMinBtn.width && 0 == m_rtMaxBtn.width) { | |
| 460 rect.left = m_rtClient.left; | |
| 461 } else if (m_rtMinBtn.left < m_rtThumb.left) { | |
| 462 rect.left = m_rtMinBtn.right(); | |
| 463 rect.width -= (m_rtMinBtn.right() - m_rtClient.left); | |
| 464 } | |
| 465 } | |
| 466 } | |
| 467 } | |
| 468 void CFWL_ScrollBarImp::CalcMaxTrackRect(CFX_RectF& rect) { | |
| 469 if (m_bMinSize) { | |
| 470 rect.Empty(); | |
| 471 return; | |
| 472 } | |
| 473 FX_FLOAT ix = (m_rtThumb.left + m_rtThumb.right()) / 2; | |
| 474 FX_FLOAT iy = (m_rtThumb.top + m_rtThumb.bottom()) / 2; | |
| 475 FX_BOOL bVertical = IsVertical(); | |
| 476 rect.left = bVertical ? m_rtClient.left : ix; | |
| 477 rect.top = bVertical ? iy : m_rtClient.top; | |
| 478 rect.width = bVertical ? m_rtClient.width : m_rtClient.right() - ix; | |
| 479 rect.height = bVertical ? m_rtClient.bottom() - iy : m_rtClient.height; | |
| 480 if (m_bCustomLayout) { | |
| 481 if (bVertical) { | |
| 482 if (m_rtMinBtn.top > m_rtThumb.top && m_rtMinBtn.height > 0 && | |
| 483 m_rtMaxBtn.height > 0) { | |
| 484 rect.height -= (m_rtClient.bottom() - m_rtMinBtn.top); | |
| 485 } else if (m_rtMinBtn.height > 0 && m_rtMaxBtn.height > 0) { | |
| 486 rect.height -= (m_rtClient.bottom() - m_rtMaxBtn.top); | |
| 487 } | |
| 488 } else { | |
| 489 if (m_rtMinBtn.left > m_rtThumb.left && m_rtMinBtn.width > 0 && | |
| 490 m_rtMaxBtn.width > 0) { | |
| 491 rect.width -= (m_rtClient.right() - m_rtMinBtn.left); | |
| 492 } else if (m_rtMinBtn.width > 0 && m_rtMaxBtn.width > 0) { | |
| 493 rect.width -= (m_rtClient.right() - m_rtMaxBtn.left); | |
| 494 } | |
| 495 } | |
| 496 } | |
| 497 } | |
| 498 FX_FLOAT CFWL_ScrollBarImp::GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy) { | |
| 499 FX_FLOAT fDiffX = fx - m_cpTrackPointX; | |
| 500 FX_FLOAT fDiffY = fy - m_cpTrackPointY; | |
| 501 FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; | |
| 502 FX_FLOAT fPos; | |
| 503 if (m_bCustomLayout) { | |
| 504 if (IsVertical()) { | |
| 505 if (0 == m_rtMinBtn.height && 0 == m_rtMaxBtn.height) { | |
| 506 fPos = fRange * fDiffY / (m_rtClient.height - m_rtThumb.height); | |
| 507 } else if (m_rtMinBtn.bottom() == m_rtMaxBtn.top) { | |
| 508 fPos = fRange * fDiffY / | |
| 509 (m_rtMinBtn.top - m_rtClient.top - m_rtThumb.height); | |
| 510 } else { | |
| 511 fPos = fRange * fDiffY / | |
| 512 (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height); | |
| 513 } | |
| 514 } else { | |
| 515 if (0 == m_rtMinBtn.width && 0 == m_rtMaxBtn.width) { | |
| 516 fPos = fRange * fDiffX / (m_rtClient.width - m_rtThumb.width); | |
| 517 } else if (m_rtMinBtn.right() == m_rtMaxBtn.left) { | |
| 518 fPos = fRange * fDiffX / | |
| 519 (m_rtMinBtn.left - m_rtClient.left - m_rtThumb.width); | |
| 520 } else { | |
| 521 fPos = fRange * fDiffX / | |
| 522 (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width); | |
| 523 } | |
| 524 } | |
| 525 } else { | |
| 526 if (IsVertical()) { | |
| 527 fPos = fRange * fDiffY / | |
| 528 (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height); | |
| 529 } else { | |
| 530 fPos = fRange * fDiffX / | |
| 531 (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width); | |
| 532 } | |
| 533 } | |
| 534 fPos += m_fLastTrackPos; | |
| 535 if (fPos < m_fRangeMin) { | |
| 536 fPos = m_fRangeMin; | |
| 537 } | |
| 538 if (fPos > m_fRangeMax) { | |
| 539 fPos = m_fRangeMax; | |
| 540 } | |
| 541 return fPos; | |
| 542 } | |
| 543 void CFWL_ScrollBarImp::GetTrackRect(CFX_RectF& rect, FX_BOOL bLower) { | |
| 544 FX_BOOL bDisabled = m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled; | |
| 545 if (bDisabled || m_bCustomLayout) { | |
| 546 rect = bLower ? m_rtMinTrack : m_rtMaxTrack; | |
| 547 } else { | |
| 548 FX_FLOAT fW = m_rtThumb.width / 2; | |
| 549 FX_FLOAT fH = m_rtThumb.height / 2; | |
| 550 FX_BOOL bVert = IsVertical(); | |
| 551 if (bLower) { | |
| 552 if (bVert) { | |
| 553 FX_FLOAT fMinTrackHeight = m_rtMinTrack.height - fH - m_rtMinBtn.height; | |
| 554 fMinTrackHeight = (fMinTrackHeight >= 0.0f) ? fMinTrackHeight : 0.0f; | |
| 555 rect.Set(m_rtMinTrack.left, m_rtMinTrack.top + m_rtMinBtn.height, | |
| 556 m_rtMinTrack.width, fMinTrackHeight); | |
| 557 } else { | |
| 558 FX_FLOAT fMinTrackWidth = | |
| 559 m_rtMinTrack.width - fW - m_rtMinBtn.width + 2; | |
| 560 fMinTrackWidth = (fMinTrackWidth >= 0.0f) ? fMinTrackWidth : 0.0f; | |
| 561 rect.Set(m_rtMinTrack.left + m_rtMinBtn.width - 1, m_rtMinTrack.top, | |
| 562 fMinTrackWidth, m_rtMinTrack.height); | |
| 563 } | |
| 564 } else { | |
| 565 if (bVert) { | |
| 566 FX_FLOAT fMaxTrackHeight = m_rtMaxTrack.height - fH - m_rtMaxBtn.height; | |
| 567 fMaxTrackHeight = (fMaxTrackHeight >= 0.0f) ? fMaxTrackHeight : 0.0f; | |
| 568 rect.Set(m_rtMaxTrack.left, m_rtMaxTrack.top + fH, m_rtMaxTrack.width, | |
| 569 fMaxTrackHeight); | |
| 570 } else { | |
| 571 FX_FLOAT fMaxTrackWidth = | |
| 572 m_rtMaxTrack.width - fW - m_rtMaxBtn.width + 2; | |
| 573 fMaxTrackWidth = (fMaxTrackWidth >= 0.0f) ? fMaxTrackWidth : 0.0f; | |
| 574 rect.Set(m_rtMaxTrack.left + fW, m_rtMaxTrack.top, fMaxTrackWidth, | |
| 575 m_rtMaxTrack.height); | |
| 576 } | |
| 577 } | |
| 578 } | |
| 579 } | |
| 580 FX_BOOL CFWL_ScrollBarImp::SendEvent() { | |
| 581 if (m_iMinButtonState == CFWL_PartState_Pressed) { | |
| 582 DoScroll(FWL_SCBCODE_StepBackward, m_fTrackPos); | |
| 583 return FALSE; | |
| 584 } | |
| 585 if (m_iMaxButtonState == CFWL_PartState_Pressed) { | |
| 586 DoScroll(FWL_SCBCODE_StepForward, m_fTrackPos); | |
| 587 return FALSE; | |
| 588 } | |
| 589 if (m_iMinTrackState == CFWL_PartState_Pressed) { | |
| 590 DoScroll(FWL_SCBCODE_PageBackward, m_fTrackPos); | |
| 591 return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); | |
| 592 } | |
| 593 if (m_iMaxTrackState == CFWL_PartState_Pressed) { | |
| 594 DoScroll(FWL_SCBCODE_PageForward, m_fTrackPos); | |
| 595 return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); | |
| 596 } | |
| 597 if (m_iMouseWheel) { | |
| 598 uint16_t dwCode = | |
| 599 m_iMouseWheel < 0 ? FWL_SCBCODE_StepForward : FWL_SCBCODE_StepBackward; | |
| 600 DoScroll(dwCode, m_fTrackPos); | |
| 601 } | |
| 602 return TRUE; | |
| 603 } | |
| 604 FX_BOOL CFWL_ScrollBarImp::OnScroll(uint32_t dwCode, FX_FLOAT fPos) { | |
| 605 FX_BOOL bRet = TRUE; | |
| 606 CFWL_EvtScroll ev; | |
| 607 ev.m_iScrollCode = dwCode; | |
| 608 ev.m_pSrcTarget = m_pInterface; | |
| 609 ev.m_fPos = fPos; | |
| 610 ev.m_pRet = &bRet; | |
| 611 DispatchEvent(&ev); | |
| 612 return bRet; | |
| 613 } | |
| 614 | |
| 615 CFWL_ScrollBarImpDelegate::CFWL_ScrollBarImpDelegate(CFWL_ScrollBarImp* pOwner) | |
| 616 : m_pOwner(pOwner) {} | |
| 617 | |
| 618 void CFWL_ScrollBarImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
| 619 if (!pMessage) | |
| 620 return; | |
| 621 | |
| 622 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); | |
| 623 if (dwMsgCode == CFWL_MessageType::Mouse) { | |
| 624 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 625 switch (pMsg->m_dwCmd) { | |
| 626 case FWL_MouseCommand::LeftButtonDown: { | |
| 627 OnLButtonDown(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); | |
| 628 break; | |
| 629 } | |
| 630 case FWL_MouseCommand::LeftButtonUp: { | |
| 631 OnLButtonUp(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); | |
| 632 break; | |
| 633 } | |
| 634 case FWL_MouseCommand::Move: { | |
| 635 OnMouseMove(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); | |
| 636 break; | |
| 637 } | |
| 638 case FWL_MouseCommand::Leave: { | |
| 639 OnMouseLeave(); | |
| 640 break; | |
| 641 } | |
| 642 default: { | |
| 643 break; | |
| 644 } | |
| 645 } | |
| 646 } else if (dwMsgCode == CFWL_MessageType::MouseWheel) { | |
| 647 CFWL_MsgMouseWheel* pMsg = static_cast<CFWL_MsgMouseWheel*>(pMessage); | |
| 648 OnMouseWheel(pMsg->m_fx, pMsg->m_fy, pMsg->m_dwFlags, pMsg->m_fDeltaX, | |
| 649 pMsg->m_fDeltaY); | |
| 650 } | |
| 651 } | |
| 652 | |
| 653 void CFWL_ScrollBarImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | |
| 654 const CFX_Matrix* pMatrix) { | |
| 655 m_pOwner->DrawWidget(pGraphics, pMatrix); | |
| 656 } | |
| 657 | |
| 658 void CFWL_ScrollBarImpDelegate::OnLButtonDown(uint32_t dwFlags, | |
| 659 FX_FLOAT fx, | |
| 660 FX_FLOAT fy) { | |
| 661 if (!m_pOwner->IsEnabled()) { | |
| 662 return; | |
| 663 } | |
| 664 m_pOwner->m_bMouseDown = TRUE; | |
| 665 m_pOwner->SetGrab(TRUE); | |
| 666 m_pOwner->m_cpTrackPointX = fx; | |
| 667 m_pOwner->m_cpTrackPointY = fy; | |
| 668 m_pOwner->m_fLastTrackPos = m_pOwner->m_fTrackPos; | |
| 669 if (m_pOwner->m_rtMinBtn.Contains(fx, fy)) { | |
| 670 DoMouseDown(0, m_pOwner->m_rtMinBtn, m_pOwner->m_iMinButtonState, fx, fy); | |
| 671 } else { | |
| 672 if (m_pOwner->m_rtThumb.Contains(fx, fy)) { | |
| 673 DoMouseDown(1, m_pOwner->m_rtThumb, m_pOwner->m_iThumbButtonState, fx, | |
| 674 fy); | |
| 675 } else { | |
| 676 if (m_pOwner->m_rtMaxBtn.Contains(fx, fy)) { | |
| 677 DoMouseDown(2, m_pOwner->m_rtMaxBtn, m_pOwner->m_iMaxButtonState, fx, | |
| 678 fy); | |
| 679 } else { | |
| 680 if (m_pOwner->m_rtMinTrack.Contains(fx, fy)) { | |
| 681 DoMouseDown(3, m_pOwner->m_rtMinTrack, m_pOwner->m_iMinTrackState, fx, | |
| 682 fy); | |
| 683 } else { | |
| 684 DoMouseDown(4, m_pOwner->m_rtMaxTrack, m_pOwner->m_iMaxTrackState, fx, | |
| 685 fy); | |
| 686 } | |
| 687 } | |
| 688 } | |
| 689 } | |
| 690 if (!m_pOwner->SendEvent()) | |
| 691 m_pOwner->m_pTimerInfo = m_pOwner->StartTimer(FWL_SCROLLBAR_Elapse, true); | |
| 692 } | |
| 693 | |
| 694 void CFWL_ScrollBarImpDelegate::OnLButtonUp(uint32_t dwFlags, | |
| 695 FX_FLOAT fx, | |
| 696 FX_FLOAT fy) { | |
| 697 m_pOwner->m_pTimerInfo->StopTimer(); | |
| 698 m_pOwner->m_bMouseDown = FALSE; | |
| 699 DoMouseUp(0, m_pOwner->m_rtMinBtn, m_pOwner->m_iMinButtonState, fx, fy); | |
| 700 DoMouseUp(1, m_pOwner->m_rtThumb, m_pOwner->m_iThumbButtonState, fx, fy); | |
| 701 DoMouseUp(2, m_pOwner->m_rtMaxBtn, m_pOwner->m_iMaxButtonState, fx, fy); | |
| 702 DoMouseUp(3, m_pOwner->m_rtMinTrack, m_pOwner->m_iMinTrackState, fx, fy); | |
| 703 DoMouseUp(4, m_pOwner->m_rtMaxTrack, m_pOwner->m_iMaxTrackState, fx, fy); | |
| 704 m_pOwner->SetGrab(FALSE); | |
| 705 } | |
| 706 void CFWL_ScrollBarImpDelegate::OnMouseMove(uint32_t dwFlags, | |
| 707 FX_FLOAT fx, | |
| 708 FX_FLOAT fy) { | |
| 709 DoMouseMove(0, m_pOwner->m_rtMinBtn, m_pOwner->m_iMinButtonState, fx, fy); | |
| 710 DoMouseMove(1, m_pOwner->m_rtThumb, m_pOwner->m_iThumbButtonState, fx, fy); | |
| 711 DoMouseMove(2, m_pOwner->m_rtMaxBtn, m_pOwner->m_iMaxButtonState, fx, fy); | |
| 712 DoMouseMove(3, m_pOwner->m_rtMinTrack, m_pOwner->m_iMinTrackState, fx, fy); | |
| 713 DoMouseMove(4, m_pOwner->m_rtMaxTrack, m_pOwner->m_iMaxTrackState, fx, fy); | |
| 714 } | |
| 715 void CFWL_ScrollBarImpDelegate::OnMouseLeave() { | |
| 716 DoMouseLeave(0, m_pOwner->m_rtMinBtn, m_pOwner->m_iMinButtonState); | |
| 717 DoMouseLeave(1, m_pOwner->m_rtThumb, m_pOwner->m_iThumbButtonState); | |
| 718 DoMouseLeave(2, m_pOwner->m_rtMaxBtn, m_pOwner->m_iMaxButtonState); | |
| 719 DoMouseLeave(3, m_pOwner->m_rtMinTrack, m_pOwner->m_iMinTrackState); | |
| 720 DoMouseLeave(4, m_pOwner->m_rtMaxTrack, m_pOwner->m_iMaxTrackState); | |
| 721 } | |
| 722 void CFWL_ScrollBarImpDelegate::OnMouseWheel(FX_FLOAT fx, | |
| 723 FX_FLOAT fy, | |
| 724 uint32_t dwFlags, | |
| 725 FX_FLOAT fDeltaX, | |
| 726 FX_FLOAT fDeltaY) { | |
| 727 m_pOwner->m_iMouseWheel = (int32_t)fDeltaX; | |
| 728 m_pOwner->SendEvent(); | |
| 729 m_pOwner->m_iMouseWheel = 0; | |
| 730 } | |
| 731 void CFWL_ScrollBarImpDelegate::DoMouseDown(int32_t iItem, | |
| 732 const CFX_RectF& rtItem, | |
| 733 int32_t& iState, | |
| 734 FX_FLOAT fx, | |
| 735 FX_FLOAT fy) { | |
| 736 if (!rtItem.Contains(fx, fy)) { | |
| 737 return; | |
| 738 } | |
| 739 if (iState == CFWL_PartState_Pressed) { | |
| 740 return; | |
| 741 } | |
| 742 iState = CFWL_PartState_Pressed; | |
| 743 m_pOwner->Repaint(&rtItem); | |
| 744 } | |
| 745 void CFWL_ScrollBarImpDelegate::DoMouseUp(int32_t iItem, | |
| 746 const CFX_RectF& rtItem, | |
| 747 int32_t& iState, | |
| 748 FX_FLOAT fx, | |
| 749 FX_FLOAT fy) { | |
| 750 int32_t iNewState = | |
| 751 rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered : CFWL_PartState_Normal; | |
| 752 if (iState == iNewState) { | |
| 753 return; | |
| 754 } | |
| 755 iState = iNewState; | |
| 756 m_pOwner->Repaint(&rtItem); | |
| 757 m_pOwner->OnScroll(FWL_SCBCODE_EndScroll, m_pOwner->m_fTrackPos); | |
| 758 } | |
| 759 void CFWL_ScrollBarImpDelegate::DoMouseMove(int32_t iItem, | |
| 760 const CFX_RectF& rtItem, | |
| 761 int32_t& iState, | |
| 762 FX_FLOAT fx, | |
| 763 FX_FLOAT fy) { | |
| 764 if (!m_pOwner->m_bMouseDown) { | |
| 765 int32_t iNewState = rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered | |
| 766 : CFWL_PartState_Normal; | |
| 767 if (iState == iNewState) { | |
| 768 return; | |
| 769 } | |
| 770 iState = iNewState; | |
| 771 m_pOwner->Repaint(&rtItem); | |
| 772 } else if ((2 == iItem) && | |
| 773 (m_pOwner->m_iThumbButtonState == CFWL_PartState_Pressed)) { | |
| 774 FX_FLOAT fPos = m_pOwner->GetTrackPointPos(fx, fy); | |
| 775 m_pOwner->m_fTrackPos = fPos; | |
| 776 m_pOwner->OnScroll(FWL_SCBCODE_TrackPos, fPos); | |
| 777 } | |
| 778 } | |
| 779 void CFWL_ScrollBarImpDelegate::DoMouseLeave(int32_t iItem, | |
| 780 const CFX_RectF& rtItem, | |
| 781 int32_t& iState) { | |
| 782 if (iState == CFWL_PartState_Normal) { | |
| 783 return; | |
| 784 } | |
| 785 iState = CFWL_PartState_Normal; | |
| 786 m_pOwner->Repaint(&rtItem); | |
| 787 } | |
| 788 void CFWL_ScrollBarImpDelegate::DoMouseHover(int32_t iItem, | |
| 789 const CFX_RectF& rtItem, | |
| 790 int32_t& iState) { | |
| 791 if (iState == CFWL_PartState_Hovered) { | |
| 792 return; | |
| 793 } | |
| 794 iState = CFWL_PartState_Hovered; | |
| 795 m_pOwner->Repaint(&rtItem); | |
| 796 } | |
| OLD | NEW |