home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / OWLINC.PAK / SCROLLER.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  4KB  |  116 lines

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