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_PDFWINDOW_PWL_SCROLLBAR_H_
      8 #define FPDFSDK_PDFWINDOW_PWL_SCROLLBAR_H_
      9 
     10 #include "fpdfsdk/pdfwindow/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 
     24   bool operator==(const PWL_SCROLL_INFO& that) const {
     25     return fContentMin == that.fContentMin && fContentMax == that.fContentMax &&
     26            fPlateWidth == that.fPlateWidth && fBigStep == that.fBigStep &&
     27            fSmallStep == that.fSmallStep;
     28   }
     29   bool operator!=(const PWL_SCROLL_INFO& that) const {
     30     return !(*this == that);
     31   }
     32 
     33   FX_FLOAT fContentMin;
     34   FX_FLOAT fContentMax;
     35   FX_FLOAT fPlateWidth;
     36   FX_FLOAT fBigStep;
     37   FX_FLOAT fSmallStep;
     38 };
     39 
     40 enum PWL_SCROLLBAR_TYPE { SBT_HSCROLL, SBT_VSCROLL };
     41 
     42 enum PWL_SBBUTTON_TYPE { PSBT_MIN, PSBT_MAX, PSBT_POS };
     43 
     44 class CPWL_SBButton : public CPWL_Wnd {
     45  public:
     46   CPWL_SBButton(PWL_SCROLLBAR_TYPE eScrollBarType,
     47                 PWL_SBBUTTON_TYPE eButtonType);
     48   ~CPWL_SBButton() override;
     49 
     50   // CPWL_Wnd
     51   CFX_ByteString GetClassName() const override;
     52   void OnCreate(PWL_CREATEPARAM& cp) override;
     53   void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override;
     54   void DrawThisAppearance(CFX_RenderDevice* pDevice,
     55                           CFX_Matrix* pUser2Device) 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(FX_FLOAT min, FX_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(FX_FLOAT min, FX_FLOAT max);
     79   bool In(FX_FLOAT x) const;
     80   FX_FLOAT GetWidth() const;
     81 
     82   FX_FLOAT fMin;
     83   FX_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(FX_FLOAT min, FX_FLOAT max);
    101   void SetClientWidth(FX_FLOAT width);
    102   void SetSmallStep(FX_FLOAT step);
    103   void SetBigStep(FX_FLOAT step);
    104   bool SetPos(FX_FLOAT pos);
    105 
    106   void AddSmall();
    107   void SubSmall();
    108   void AddBig();
    109   void SubBig();
    110 
    111   PWL_FLOATRANGE ScrollRange;
    112   FX_FLOAT fClientWidth;
    113   FX_FLOAT fScrollPos;
    114   FX_FLOAT fBigStep;
    115   FX_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   CFX_ByteString GetClassName() const override;
    125   void OnCreate(PWL_CREATEPARAM& cp) override;
    126   void RePosChildWnd() override;
    127   void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override;
    128   void DrawThisAppearance(CFX_RenderDevice* pDevice,
    129                           CFX_Matrix* pUser2Device) 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 OnNotify(CPWL_Wnd* pWnd,
    133                 uint32_t msg,
    134                 intptr_t wParam = 0,
    135                 intptr_t lParam = 0) override;
    136   void CreateChildWnd(const PWL_CREATEPARAM& cp) override;
    137   void TimerProc() override;
    138 
    139   FX_FLOAT GetScrollBarWidth() const;
    140   PWL_SCROLLBAR_TYPE GetScrollBarType() const { return m_sbType; }
    141 
    142   void SetNotifyForever(bool bForever) { m_bNotifyForever = bForever; }
    143 
    144  protected:
    145   void SetScrollRange(FX_FLOAT fMin, FX_FLOAT fMax, FX_FLOAT fClientWidth);
    146   void SetScrollPos(FX_FLOAT fPos);
    147   void MovePosButton(bool bRefresh);
    148   void SetScrollStep(FX_FLOAT fBigStep, FX_FLOAT fSmallStep);
    149   void NotifyScrollWindow();
    150   CFX_FloatRect GetScrollArea() const;
    151 
    152  private:
    153   void CreateButtons(const PWL_CREATEPARAM& cp);
    154 
    155   void OnMinButtonLBDown(const CFX_PointF& point);
    156   void OnMinButtonLBUp(const CFX_PointF& point);
    157   void OnMinButtonMouseMove(const CFX_PointF& point);
    158 
    159   void OnMaxButtonLBDown(const CFX_PointF& point);
    160   void OnMaxButtonLBUp(const CFX_PointF& point);
    161   void OnMaxButtonMouseMove(const CFX_PointF& point);
    162 
    163   void OnPosButtonLBDown(const CFX_PointF& point);
    164   void OnPosButtonLBUp(const CFX_PointF& point);
    165   void OnPosButtonMouseMove(const CFX_PointF& point);
    166 
    167   FX_FLOAT TrueToFace(FX_FLOAT);
    168   FX_FLOAT FaceToTrue(FX_FLOAT);
    169 
    170   PWL_SCROLLBAR_TYPE m_sbType;
    171   PWL_SCROLL_INFO m_OriginInfo;
    172   CPWL_SBButton* m_pMinButton;
    173   CPWL_SBButton* m_pMaxButton;
    174   CPWL_SBButton* m_pPosButton;
    175   PWL_SCROLL_PRIVATEDATA m_sData;
    176   bool m_bMouseDown;
    177   bool m_bMinOrMax;
    178   bool m_bNotifyForever;
    179   FX_FLOAT m_nOldPos;
    180   FX_FLOAT m_fOldPosButton;
    181 };
    182 
    183 #endif  // FPDFSDK_PDFWINDOW_PWL_SCROLLBAR_H_
    184