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