• 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/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 
18 class CFWL_Widget;
19 
20 #define FWL_STYLEEXT_SCB_Horz (0L << 0)
21 #define FWL_STYLEEXT_SCB_Vert (1L << 0)
22 
23 class 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(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override;
34   void OnProcessMessage(CFWL_Message* pMessage) override;
35   void OnDrawWidget(CFX_Graphics* pGraphics,
36                     const CFX_Matrix* pMatrix) override;
37 
GetRange(FX_FLOAT * fMin,FX_FLOAT * fMax)38   void GetRange(FX_FLOAT* fMin, FX_FLOAT* fMax) const {
39     ASSERT(fMin);
40     ASSERT(fMax);
41     *fMin = m_fRangeMin;
42     *fMax = m_fRangeMax;
43   }
SetRange(FX_FLOAT fMin,FX_FLOAT fMax)44   void SetRange(FX_FLOAT fMin, FX_FLOAT fMax) {
45     m_fRangeMin = fMin;
46     m_fRangeMax = fMax;
47   }
GetPageSize()48   FX_FLOAT GetPageSize() const { return m_fPageSize; }
SetPageSize(FX_FLOAT fPageSize)49   void SetPageSize(FX_FLOAT fPageSize) { m_fPageSize = fPageSize; }
GetStepSize()50   FX_FLOAT GetStepSize() const { return m_fStepSize; }
SetStepSize(FX_FLOAT fStepSize)51   void SetStepSize(FX_FLOAT fStepSize) { m_fStepSize = fStepSize; }
GetPos()52   FX_FLOAT GetPos() const { return m_fPos; }
SetPos(FX_FLOAT fPos)53   void SetPos(FX_FLOAT fPos) { m_fPos = fPos; }
54   void SetTrackPos(FX_FLOAT fTrackPos);
55 
56  private:
57   class Timer : public CFWL_Timer {
58    public:
59     explicit Timer(CFWL_ScrollBar* pToolTip);
~Timer()60     ~Timer() override {}
61 
62     void Run(CFWL_TimerInfo* pTimerInfo) override;
63   };
64   friend class CFWL_ScrollBar::Timer;
65 
IsVertical()66   bool IsVertical() const {
67     return !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_SCB_Vert);
68   }
69   void DrawTrack(CFX_Graphics* pGraphics,
70                  IFWL_ThemeProvider* pTheme,
71                  bool bLower,
72                  const CFX_Matrix* pMatrix);
73   void DrawArrowBtn(CFX_Graphics* pGraphics,
74                     IFWL_ThemeProvider* pTheme,
75                     bool bMinBtn,
76                     const CFX_Matrix* pMatrix);
77   void DrawThumb(CFX_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   FX_FLOAT GetTrackPointPos(const CFX_PointF& point);
88 
89   bool SendEvent();
90   bool OnScroll(CFWL_EventScroll::Code dwCode, FX_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, FX_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   FX_FLOAT m_fRangeMin;
114   FX_FLOAT m_fRangeMax;
115   FX_FLOAT m_fPageSize;
116   FX_FLOAT m_fStepSize;
117   FX_FLOAT m_fPos;
118   FX_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   FX_FLOAT m_fLastTrackPos;
125   CFX_PointF m_cpTrackPoint;
126   int32_t m_iMouseWheel;
127   bool m_bMouseDown;
128   FX_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