home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 19.ddi / OWLINC.PAK / SCROLLER.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  3.9 KB  |  115 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //   include\owl\scroller.h
  4. //   Definition of class TScroller.
  5. //----------------------------------------------------------------------------
  6. #if !defined(__OWL_SCROLLER_H)
  7. #define __OWL_SCROLLER_H
  8.  
  9. #if !defined(__OWL_OWLDEFS_H)
  10.   #include <owl\owldefs.h>
  11. #endif
  12. #if !defined(__CLASSLIB_OBJSTRM_H)
  13.   #include <classlib\objstrm.h>
  14. #endif
  15. #if !defined(__LIMITS_H)
  16.   #include <limits.h>
  17. #endif
  18.  
  19. class _OWLCLASS TWindow;
  20. #if !defined(__OWL_POINT_H)
  21. class _OWLCLASS TRect;
  22. #endif
  23. class _OWLCLASS TDC;
  24.  
  25. inline long LongMulDiv(long mul1, long mul2, long div1)
  26.                        {return (mul1*mul2) / div1;}
  27.  
  28. //
  29. //  class TScroller
  30. //  ----- ---------
  31. //
  32. // Class TScroller implements the actual scroller object. All functions
  33. // are inline or virtual to avoid pulling in code when no scrollers have
  34. // been constructed.
  35. //
  36. class _OWLCLASS TScroller : public TStreamableBase {
  37.   public:
  38.     TScroller(TWindow* window,
  39.               int      xUnit,  int  yUnit,
  40.               long     xRange, long yRange);
  41.     virtual ~TScroller();
  42.  
  43.             void  SetWindow(TWindow* win) {Window = win;}
  44.     virtual void  SetUnits(int xUnit, int yUnit);
  45.     virtual void  SetPageSize();
  46.     virtual void  SetSBarRange();
  47.     virtual void  SetRange(long xRange, long yRange);
  48.  
  49.     virtual void  BeginView(TDC& dc, TRect& rect);
  50.     virtual void  EndView();
  51.     virtual void  VScroll(UINT scrollEvent, int thumbPos);
  52.     virtual void  HScroll(UINT scrollEvent, int thumbPos);
  53.     virtual void  ScrollTo(long x, long y);
  54.  
  55.     //
  56.     // scrolls to a position calculated using the passed "Delta" values
  57.     //
  58.     void          ScrollBy(long dx, long dy) {ScrollTo(XPos+dx, YPos+dy);}
  59.  
  60.     virtual BOOL  IsAutoMode();
  61.     virtual void  AutoScroll();
  62.  
  63.     //
  64.     // returns a BOOL value indicating whether or not the passed
  65.     // area (in units) is currently visible
  66.     //
  67.     BOOL          IsVisibleRect(long x, long y, int xExt, int yExt)
  68.             {return (x + xExt > XPos) && (y + yExt > YPos) &&
  69.                   (x <= XPos + XPage + 1) && (y <= YPos + YPage + 1);}
  70.  
  71.     //
  72.     // converts a horizontal range value from the scrollbar to a
  73.     // horizontal scroll value
  74.     //
  75.     int           XScrollValue(long rangeUnit)
  76.             {return (int)LongMulDiv(rangeUnit, SHRT_MAX, XRange);}
  77.  
  78.     //
  79.     // converts a vertical range value from the scrollbar to a
  80.     // vertical scroll value
  81.     //
  82.     int           YScrollValue(long rangeUnit)
  83.             {return (int)LongMulDiv(rangeUnit, SHRT_MAX, YRange);}
  84.  
  85.     //
  86.     // converts a horizontal scroll value from the scrollbar to
  87.     // a horizontal range value
  88.     //
  89.     long          XRangeValue(int scrollUnit)
  90.             {return LongMulDiv(scrollUnit, XRange, SHRT_MAX);}
  91.  
  92.     //
  93.     // converts a vertical scroll value from the scrollbar to
  94.     // a vertical range value
  95.     //
  96.     long          YRangeValue(int scrollUnit)
  97.             {return LongMulDiv(scrollUnit, YRange, SHRT_MAX);}
  98.  
  99.   public:
  100.     TWindow*  Window;          // Window that this scroller belongs to
  101.     long      XPos, YPos;      // current pos in horz/vert scroll units
  102.     long      XRange, YRange;  // # of scrollable horz/vert scroll units
  103.     int       XUnit, YUnit;    // logical device units per horz/vert scroll unit
  104.     int       XLine, YLine;    // # of horz/vert scroll units per line
  105.     int       XPage, YPage;    // # of horz/vert scroll units per page
  106.     BOOL      AutoMode;        // auto scrolling mode
  107.     BOOL      TrackMode;       // track scroll mode
  108.     BOOL      AutoOrg;         // indicates Scroller offsets origin
  109.     BOOL      HasHScrollBar, HasVScrollBar;
  110.  
  111.   DECLARE_STREAMABLE(_OWLCLASS, TScroller, 1);
  112. };
  113.  
  114. #endif  // __OWL_SCROLLER_H
  115.