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