dc1f18fce915dc424fa0d4aeeb263a3e168f1a53
[pdfium.git] / fpdfsdk / include / pdfwindow / PWL_ScrollBar.h
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 _PWL_SCROLLBAR_H_
8 #define _PWL_SCROLLBAR_H_
9
10 #include "PWL_Wnd.h"
11
12 class CPWL_SBButton;
13 class CPWL_ScrollBar;
14
15 struct PWL_SCROLL_INFO
16 {
17 public:
18         PWL_SCROLL_INFO() : fContentMin(0.0f), fContentMax(0.0f), fPlateWidth(0.0f), fBigStep(0.0f), fSmallStep(0.0f)
19         {
20         }
21         FX_FLOAT                                        fContentMin;
22         FX_FLOAT                                        fContentMax;    
23         FX_FLOAT                                        fPlateWidth;    
24         FX_FLOAT                                        fBigStep;
25         FX_FLOAT                                        fSmallStep;
26 };
27
28 enum PWL_SCROLLBAR_TYPE
29 {
30         SBT_HSCROLL,
31         SBT_VSCROLL
32 };
33
34 enum PWL_SBBUTTON_TYPE
35 {
36         PSBT_MIN,
37         PSBT_MAX,
38         PSBT_POS
39 };
40
41 class CPWL_SBButton : public CPWL_Wnd  
42 {
43 public:
44         CPWL_SBButton(PWL_SCROLLBAR_TYPE eScrollBarType,PWL_SBBUTTON_TYPE eButtonType);
45         virtual ~CPWL_SBButton();
46
47 public:
48         virtual CFX_ByteString          GetClassName() const;
49         virtual void                            OnCreate(PWL_CREATEPARAM & cp);
50         virtual void                            GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream);
51         virtual void                            DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device);
52         virtual FX_BOOL                         OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag);
53         virtual FX_BOOL                         OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag);
54         virtual FX_BOOL                         OnMouseMove(const CPDF_Point & point, FX_DWORD nFlag);
55
56 protected:
57         PWL_SCROLLBAR_TYPE                      m_eScrollBarType;
58         PWL_SBBUTTON_TYPE                       m_eSBButtonType;
59
60         FX_BOOL                                         m_bMouseDown;
61 };
62
63 struct PWL_FLOATRANGE
64 {
65 public:
66         PWL_FLOATRANGE();
67         PWL_FLOATRANGE(FX_FLOAT min,FX_FLOAT max);
68         void Default();
69         void Set(FX_FLOAT min,FX_FLOAT max);
70         FX_BOOL In(FX_FLOAT x) const;
71         FX_FLOAT GetWidth() const;
72
73         FX_FLOAT fMin,fMax;
74 };
75
76 struct PWL_SCROLL_PRIVATEDATA
77 {
78 public:
79         PWL_SCROLL_PRIVATEDATA();
80
81         void Default();
82         void SetScrollRange(FX_FLOAT min,FX_FLOAT max);
83         void SetClientWidth(FX_FLOAT width);
84         void SetSmallStep(FX_FLOAT step);
85         void SetBigStep(FX_FLOAT step);
86         FX_BOOL SetPos(FX_FLOAT pos);
87
88         void AddSmall();
89         void SubSmall();
90         void AddBig();
91         void SubBig();
92
93         PWL_FLOATRANGE                          ScrollRange;
94         FX_FLOAT                                        fClientWidth;
95         FX_FLOAT                                        fScrollPos;
96         FX_FLOAT                                        fBigStep;
97         FX_FLOAT                                        fSmallStep;
98 };
99
100 class CPWL_ScrollBar : public CPWL_Wnd  
101 {
102 public:
103         CPWL_ScrollBar(PWL_SCROLLBAR_TYPE sbType = SBT_HSCROLL);
104         virtual ~CPWL_ScrollBar();
105
106 public:
107         virtual CFX_ByteString          GetClassName() const;
108         virtual void                            OnCreate(PWL_CREATEPARAM & cp);
109         virtual void                            RePosChildWnd();
110         virtual void                            GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream);
111         virtual void                            DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device);
112
113         virtual FX_BOOL                         OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag);
114         virtual FX_BOOL                         OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag);
115         virtual void                            OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam = 0, FX_INTPTR lParam = 0);
116
117         virtual void                            CreateChildWnd(const PWL_CREATEPARAM & cp);
118         
119         FX_FLOAT                                        GetScrollBarWidth() const;      
120         PWL_SCROLLBAR_TYPE                      GetScrollBarType() const {return m_sbType;};
121
122         void                                            SetNotifyForever(FX_BOOL bForever) {m_bNotifyForever = bForever;}
123
124 protected:                      
125         void                                            SetScrollRange(FX_FLOAT fMin,FX_FLOAT fMax,FX_FLOAT fClientWidth);
126         void                                            SetScrollPos(FX_FLOAT fPos);
127         void                                            MovePosButton(FX_BOOL bRefresh);
128         void                                            SetScrollStep(FX_FLOAT fBigStep,FX_FLOAT fSmallStep);
129         void                                            NotifyScrollWindow();
130         CPDF_Rect                                       GetScrollArea() const;
131
132 private:
133         void                                            CreateButtons(const PWL_CREATEPARAM & cp);
134
135         void                                            OnMinButtonLBDown(const CPDF_Point & point);
136         void                                            OnMinButtonLBUp(const CPDF_Point & point);
137         void                                            OnMinButtonMouseMove(const CPDF_Point & point);
138
139         void                                            OnMaxButtonLBDown(const CPDF_Point & point);
140         void                                            OnMaxButtonLBUp(const CPDF_Point & point);
141         void                                            OnMaxButtonMouseMove(const CPDF_Point & point);
142
143         void                                            OnPosButtonLBDown(const CPDF_Point & point);
144         void                                            OnPosButtonLBUp(const CPDF_Point & point);
145         void                                            OnPosButtonMouseMove(const CPDF_Point & point);
146
147         FX_FLOAT                                        TrueToFace(FX_FLOAT);
148         FX_FLOAT                                        FaceToTrue(FX_FLOAT);
149
150         virtual void                            TimerProc();
151
152 private:
153         PWL_SCROLLBAR_TYPE                      m_sbType;
154         PWL_SCROLL_INFO                         m_OriginInfo;
155         CPWL_SBButton*                          m_pMinButton;
156         CPWL_SBButton*                          m_pMaxButton;
157         CPWL_SBButton*                          m_pPosButton;
158         PWL_SCROLL_PRIVATEDATA          m_sData;
159         FX_BOOL                                         m_bMouseDown;   
160         FX_BOOL                                         m_bMinOrMax;
161         FX_BOOL                                         m_bNotifyForever;
162         FX_FLOAT                                        m_nOldPos;
163         FX_FLOAT                                        m_fOldPosButton;
164 };
165
166 #endif // !defined(AFX_PWL_SCROLLBAR_H__DCFEC082_2651_48A4_B8F3_63F1B3CC5E10__INCLUDED_)
167
168