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