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 #ifndef XFA_FWL_CFWL_SCROLLBAR_H_ 8 #define XFA_FWL_CFWL_SCROLLBAR_H_ 9 10 #include <memory> 11 12 #include "core/fxcrt/cfx_timer.h" 13 #include "core/fxcrt/fx_system.h" 14 #include "third_party/base/check.h" 15 #include "xfa/fwl/cfwl_eventscroll.h" 16 #include "xfa/fwl/cfwl_widget.h" 17 18 #define FWL_STYLEEXT_SCB_Horz (0L << 0) 19 #define FWL_STYLEEXT_SCB_Vert (1L << 0) 20 21 class CFWL_ScrollBar final : public CFWL_Widget, 22 public CFX_Timer::CallbackIface { 23 public: 24 CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED; 25 ~CFWL_ScrollBar() override; 26 27 // CFWL_Widget: 28 FWL_Type GetClassID() const override; 29 void Update() override; 30 void DrawWidget(CFGAS_GEGraphics* pGraphics, 31 const CFX_Matrix& matrix) override; 32 void OnProcessMessage(CFWL_Message* pMessage) override; 33 void OnDrawWidget(CFGAS_GEGraphics* pGraphics, 34 const CFX_Matrix& matrix) override; 35 36 // CFX_Timer::CallbackIface: 37 void OnTimerFired() override; 38 GetRange(float * fMin,float * fMax)39 void GetRange(float* fMin, float* fMax) const { 40 DCHECK(fMin); 41 DCHECK(fMax); 42 *fMin = m_fRangeMin; 43 *fMax = m_fRangeMax; 44 } SetRange(float fMin,float fMax)45 void SetRange(float fMin, float fMax) { 46 m_fRangeMin = fMin; 47 m_fRangeMax = fMax; 48 } GetPageSize()49 float GetPageSize() const { return m_fPageSize; } SetPageSize(float fPageSize)50 void SetPageSize(float fPageSize) { m_fPageSize = fPageSize; } GetStepSize()51 float GetStepSize() const { return m_fStepSize; } SetStepSize(float fStepSize)52 void SetStepSize(float fStepSize) { m_fStepSize = fStepSize; } GetPos()53 float GetPos() const { return m_fPos; } SetPos(float fPos)54 void SetPos(float fPos) { m_fPos = fPos; } 55 void SetTrackPos(float fTrackPos); 56 57 private: 58 CFWL_ScrollBar(CFWL_App* app, 59 const Properties& properties, 60 CFWL_Widget* pOuter); 61 IsVertical()62 bool IsVertical() const { 63 return !!(m_Properties.m_dwStyleExes & FWL_STYLEEXT_SCB_Vert); 64 } 65 void DrawTrack(CFGAS_GEGraphics* pGraphics, 66 bool bLower, 67 const CFX_Matrix* pMatrix); 68 void DrawArrowBtn(CFGAS_GEGraphics* pGraphics, 69 bool bMinBtn, 70 const CFX_Matrix* pMatrix); 71 void DrawThumb(CFGAS_GEGraphics* pGraphics, const CFX_Matrix* pMatrix); 72 void Layout(); 73 void CalcButtonLen(); 74 CFX_RectF CalcMinButtonRect(); 75 CFX_RectF CalcMaxButtonRect(); 76 CFX_RectF CalcThumbButtonRect(const CFX_RectF& rtThumbRect); 77 CFX_RectF CalcMinTrackRect(const CFX_RectF& rtMinRect); 78 CFX_RectF CalcMaxTrackRect(const CFX_RectF& rtMaxRect); 79 float GetTrackPointPos(const CFX_PointF& point); 80 81 bool SendEvent(); 82 bool OnScroll(CFWL_EventScroll::Code dwCode, float fPos); 83 void OnLButtonDown(const CFX_PointF& point); 84 void OnLButtonUp(const CFX_PointF& point); 85 void OnMouseMove(const CFX_PointF& point); 86 void OnMouseLeave(); 87 void OnMouseWheel(const CFX_Vector& delta); 88 bool DoScroll(CFWL_EventScroll::Code dwCode, float fPos); 89 void DoMouseDown(int32_t iItem, 90 const CFX_RectF& rtItem, 91 int32_t& iState, 92 const CFX_PointF& point); 93 void DoMouseUp(int32_t iItem, 94 const CFX_RectF& rtItem, 95 int32_t& iState, 96 const CFX_PointF& point); 97 void DoMouseMove(int32_t iItem, 98 const CFX_RectF& rtItem, 99 int32_t& iState, 100 const CFX_PointF& point); 101 void DoMouseLeave(int32_t iItem, const CFX_RectF& rtItem, int32_t& iState); 102 void DoMouseHover(int32_t iItem, const CFX_RectF& rtItem, int32_t& iState); 103 104 float m_fRangeMin = 0.0f; 105 float m_fRangeMax = -1.0f; 106 float m_fPageSize = 0.0f; 107 float m_fStepSize = 0.0f; 108 float m_fPos = 0.0f; 109 float m_fTrackPos = 0.0f; 110 int32_t m_iMinButtonState = CFWL_PartState_Normal; 111 int32_t m_iMaxButtonState = CFWL_PartState_Normal; 112 int32_t m_iThumbButtonState = CFWL_PartState_Normal; 113 int32_t m_iMinTrackState = CFWL_PartState_Normal; 114 int32_t m_iMaxTrackState = CFWL_PartState_Normal; 115 float m_fLastTrackPos = 0.0f; 116 CFX_PointF m_cpTrackPoint; 117 int32_t m_iMouseWheel = 0; 118 float m_fButtonLen = 0.0f; 119 bool m_bMouseDown = false; 120 bool m_bMinSize = false; 121 CFX_RectF m_ClientRect; 122 CFX_RectF m_ThumbRect; 123 CFX_RectF m_MinBtnRect; 124 CFX_RectF m_MaxBtnRect; 125 CFX_RectF m_MinTrackRect; 126 CFX_RectF m_MaxTrackRect; 127 std::unique_ptr<CFX_Timer> m_pTimer; 128 }; 129 130 #endif // XFA_FWL_CFWL_SCROLLBAR_H_ 131