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 FPDFSDK_PWL_CPWL_SCROLL_BAR_H_ 8 #define FPDFSDK_PWL_CPWL_SCROLL_BAR_H_ 9 10 #include "core/fxcrt/unowned_ptr.h" 11 #include "fpdfsdk/pwl/cpwl_wnd.h" 12 13 class CPWL_SBButton; 14 class CPWL_ScrollBar; 15 16 struct PWL_SCROLL_INFO { 17 public: PWL_SCROLL_INFOPWL_SCROLL_INFO18 PWL_SCROLL_INFO() 19 : fContentMin(0.0f), 20 fContentMax(0.0f), 21 fPlateWidth(0.0f), 22 fBigStep(0.0f), 23 fSmallStep(0.0f) {} 24 25 bool operator==(const PWL_SCROLL_INFO& that) const { 26 return fContentMin == that.fContentMin && fContentMax == that.fContentMax && 27 fPlateWidth == that.fPlateWidth && fBigStep == that.fBigStep && 28 fSmallStep == that.fSmallStep; 29 } 30 bool operator!=(const PWL_SCROLL_INFO& that) const { 31 return !(*this == that); 32 } 33 34 float fContentMin; 35 float fContentMax; 36 float fPlateWidth; 37 float fBigStep; 38 float fSmallStep; 39 }; 40 41 enum PWL_SCROLLBAR_TYPE { SBT_HSCROLL, SBT_VSCROLL }; 42 43 enum PWL_SBBUTTON_TYPE { PSBT_MIN, PSBT_MAX, PSBT_POS }; 44 45 class CPWL_SBButton : public CPWL_Wnd { 46 public: 47 CPWL_SBButton(PWL_SCROLLBAR_TYPE eScrollBarType, 48 PWL_SBBUTTON_TYPE eButtonType); 49 ~CPWL_SBButton() override; 50 51 // CPWL_Wnd 52 ByteString GetClassName() const override; 53 void OnCreate(CreateParams* pParamsToAdjust) override; 54 void DrawThisAppearance(CFX_RenderDevice* pDevice, 55 const CFX_Matrix& mtUser2Device) override; 56 bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; 57 bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; 58 bool OnMouseMove(const CFX_PointF& point, uint32_t nFlag) override; 59 60 protected: 61 PWL_SCROLLBAR_TYPE m_eScrollBarType; 62 PWL_SBBUTTON_TYPE m_eSBButtonType; 63 64 bool m_bMouseDown; 65 }; 66 67 struct PWL_FLOATRANGE { 68 public: 69 PWL_FLOATRANGE(); 70 PWL_FLOATRANGE(float min, float max); 71 72 bool operator==(const PWL_FLOATRANGE& that) const { 73 return fMin == that.fMin && fMax == that.fMax; 74 } 75 bool operator!=(const PWL_FLOATRANGE& that) const { return !(*this == that); } 76 77 void Default(); 78 void Set(float min, float max); 79 bool In(float x) const; 80 float GetWidth() const; 81 82 float fMin; 83 float fMax; 84 }; 85 86 struct PWL_SCROLL_PRIVATEDATA { 87 public: 88 PWL_SCROLL_PRIVATEDATA(); 89 90 bool operator==(const PWL_SCROLL_PRIVATEDATA& that) const { 91 return ScrollRange == that.ScrollRange && 92 fClientWidth == that.fClientWidth && fScrollPos == that.fScrollPos && 93 fBigStep == that.fBigStep && fSmallStep == that.fSmallStep; 94 } 95 bool operator!=(const PWL_SCROLL_PRIVATEDATA& that) const { 96 return !(*this == that); 97 } 98 99 void Default(); 100 void SetScrollRange(float min, float max); 101 void SetClientWidth(float width); 102 void SetSmallStep(float step); 103 void SetBigStep(float step); 104 bool SetPos(float pos); 105 106 void AddSmall(); 107 void SubSmall(); 108 void AddBig(); 109 void SubBig(); 110 111 PWL_FLOATRANGE ScrollRange; 112 float fClientWidth; 113 float fScrollPos; 114 float fBigStep; 115 float fSmallStep; 116 }; 117 118 class CPWL_ScrollBar : public CPWL_Wnd { 119 public: 120 explicit CPWL_ScrollBar(PWL_SCROLLBAR_TYPE sbType = SBT_HSCROLL); 121 ~CPWL_ScrollBar() override; 122 123 // CPWL_Wnd: 124 ByteString GetClassName() const override; 125 void OnCreate(CreateParams* pParamsToAdjust) override; 126 void OnDestroy() override; 127 bool RePosChildWnd() override; 128 void DrawThisAppearance(CFX_RenderDevice* pDevice, 129 const CFX_Matrix& mtUser2Device) override; 130 bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; 131 bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; 132 void SetScrollInfo(const PWL_SCROLL_INFO& info) override; 133 void SetScrollPosition(float pos) override; 134 void NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) override; 135 void NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) override; 136 void NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) override; 137 void CreateChildWnd(const CreateParams& cp) override; 138 void TimerProc() override; 139 140 float GetScrollBarWidth() const; GetScrollBarType()141 PWL_SCROLLBAR_TYPE GetScrollBarType() const { return m_sbType; } 142 SetNotifyForever(bool bForever)143 void SetNotifyForever(bool bForever) { m_bNotifyForever = bForever; } 144 145 protected: 146 void SetScrollRange(float fMin, float fMax, float fClientWidth); 147 void SetScrollPos(float fPos); 148 149 // Returns |true| iff this instance is still allocated. 150 bool MovePosButton(bool bRefresh); 151 void SetScrollStep(float fBigStep, float fSmallStep); 152 void NotifyScrollWindow(); 153 CFX_FloatRect GetScrollArea() const; 154 155 private: 156 void CreateButtons(const CreateParams& cp); 157 158 void OnMinButtonLBDown(const CFX_PointF& point); 159 void OnMinButtonLBUp(const CFX_PointF& point); 160 void OnMinButtonMouseMove(const CFX_PointF& point); 161 162 void OnMaxButtonLBDown(const CFX_PointF& point); 163 void OnMaxButtonLBUp(const CFX_PointF& point); 164 void OnMaxButtonMouseMove(const CFX_PointF& point); 165 166 void OnPosButtonLBDown(const CFX_PointF& point); 167 void OnPosButtonLBUp(const CFX_PointF& point); 168 void OnPosButtonMouseMove(const CFX_PointF& point); 169 170 float TrueToFace(float); 171 float FaceToTrue(float); 172 173 PWL_SCROLLBAR_TYPE m_sbType; 174 PWL_SCROLL_INFO m_OriginInfo; 175 UnownedPtr<CPWL_SBButton> m_pMinButton; 176 UnownedPtr<CPWL_SBButton> m_pMaxButton; 177 UnownedPtr<CPWL_SBButton> m_pPosButton; 178 PWL_SCROLL_PRIVATEDATA m_sData; 179 bool m_bMouseDown; 180 bool m_bMinOrMax; 181 bool m_bNotifyForever; 182 float m_nOldPos; 183 float m_fOldPosButton; 184 }; 185 186 #endif // FPDFSDK_PWL_CPWL_SCROLL_BAR_H_ 187