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