1 // Copyright 2014 The PDFium Authors 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 <stdint.h> 11 12 #include <memory> 13 14 #include "core/fxcrt/cfx_timer.h" 15 #include "third_party/base/check.h" 16 #include "xfa/fwl/cfwl_eventscroll.h" 17 #include "xfa/fwl/cfwl_themepart.h" 18 #include "xfa/fwl/cfwl_widget.h" 19 20 #define FWL_STYLEEXT_SCB_Horz (0L << 0) 21 #define FWL_STYLEEXT_SCB_Vert (1L << 0) 22 23 class CFWL_ScrollBar final : public CFWL_Widget, 24 public CFX_Timer::CallbackIface { 25 public: 26 CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED; 27 ~CFWL_ScrollBar() override; 28 29 // CFWL_Widget: 30 FWL_Type GetClassID() const override; 31 void Update() override; 32 void DrawWidget(CFGAS_GEGraphics* pGraphics, 33 const CFX_Matrix& matrix) override; 34 void OnProcessMessage(CFWL_Message* pMessage) override; 35 void OnDrawWidget(CFGAS_GEGraphics* pGraphics, 36 const CFX_Matrix& matrix) override; 37 38 // CFX_Timer::CallbackIface: 39 void OnTimerFired() override; 40 GetRange(float * fMin,float * fMax)41 void GetRange(float* fMin, float* fMax) const { 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 { return !!(GetStyleExts() & FWL_STYLEEXT_SCB_Vert); } 63 void DrawUpperTrack(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 64 void DrawLowerTrack(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 65 void DrawMaxArrowBtn(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 66 void DrawMinArrowBtn(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 67 void DrawThumb(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 68 void Layout(); 69 void CalcButtonLen(); 70 CFX_RectF CalcMinButtonRect(); 71 CFX_RectF CalcMaxButtonRect(); 72 CFX_RectF CalcThumbButtonRect(const CFX_RectF& rtThumbRect); 73 CFX_RectF CalcMinTrackRect(const CFX_RectF& rtMinRect); 74 CFX_RectF CalcMaxTrackRect(const CFX_RectF& rtMaxRect); 75 float GetTrackPointPos(const CFX_PointF& point); 76 77 bool SendEvent(); 78 bool OnScroll(CFWL_EventScroll::Code dwCode, float fPos); 79 void OnLButtonDown(const CFX_PointF& point); 80 void OnLButtonUp(const CFX_PointF& point); 81 void OnMouseMove(const CFX_PointF& point); 82 void OnMouseLeave(); 83 void OnMouseWheel(const CFX_Vector& delta); 84 bool DoScroll(CFWL_EventScroll::Code dwCode, float fPos); 85 void DoMouseDown(int32_t iItem, 86 const CFX_RectF& rtItem, 87 CFWL_PartState* pState, 88 const CFX_PointF& point); 89 void DoMouseUp(int32_t iItem, 90 const CFX_RectF& rtItem, 91 CFWL_PartState* pState, 92 const CFX_PointF& point); 93 void DoMouseMove(int32_t iItem, 94 const CFX_RectF& rtItem, 95 CFWL_PartState* pState, 96 const CFX_PointF& point); 97 void DoMouseLeave(int32_t iItem, 98 const CFX_RectF& rtItem, 99 CFWL_PartState* pState); 100 void DoMouseHover(int32_t iItem, 101 const CFX_RectF& rtItem, 102 CFWL_PartState* pState); 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 CFWL_PartState m_iMinButtonState = CFWL_PartState::kNormal; 111 CFWL_PartState m_iMaxButtonState = CFWL_PartState::kNormal; 112 CFWL_PartState m_iThumbButtonState = CFWL_PartState::kNormal; 113 CFWL_PartState m_iMinTrackState = CFWL_PartState::kNormal; 114 CFWL_PartState m_iMaxTrackState = CFWL_PartState::kNormal; 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