home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / Harvest C / Source Code / CTableScroller.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-24  |  3.6 KB  |  122 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CTableScroller.c
  3.  
  4.         A subclass of CScrollPane that assists in providing synchronized
  5.         scrolling of a table and its row and column labels. The other classes
  6.         involved are CDemoTable and CTableLabels.
  7.         
  8.     SUPERCLASS = CScrollPane
  9.     
  10.     Copyright © 1991 Symantec Corporation. All rights reserved.
  11.     
  12.  
  13.  ******************************************************************************/
  14.  
  15. #include "CTableScroller.h"
  16. #include "CTableLabels.h"
  17. #include "CWindow.h"
  18. #include "Global.h"
  19.  
  20.  
  21. extern RgnHandle    gUtilRgn;
  22.  
  23. /******************************************************************************
  24.  ITableScroller
  25.  
  26.      Initialization method for CTableScroller.
  27. ******************************************************************************/
  28.  
  29. void CTableScroller::ITableScroller( CView *anEnclosure, CBureaucrat *aSupervisor,
  30.                 short aWidth, short    aHeight, short aHEncl, short aVEncl,
  31.                 SizingOption aHSizing, SizingOption aVSizing,
  32.                 Boolean    hasHoriz, Boolean hasVert, Boolean hasSizeBox)
  33. {
  34.     itsRowLabels = itsColLabels = NULL;
  35.  
  36.     CScrollPane::IScrollPane( anEnclosure, aSupervisor, aWidth, aHeight,
  37.                     aHEncl, aVEncl, aHSizing, aVSizing,
  38.                     hasHoriz, hasVert, hasSizeBox);
  39.                     
  40. }
  41.  
  42. /******************************************************************************
  43.  SetLabels
  44.  
  45.      Specify the row and column label panes.
  46. ******************************************************************************/
  47.  
  48. void CTableScroller::SetLabels( CTableLabels *rowLabels, CTableLabels *colLabels)
  49. {
  50.     itsRowLabels = rowLabels;
  51.     itsColLabels = colLabels;
  52. }
  53.  
  54. /******************************************************************************
  55.  ScrollBits
  56.  
  57.      This method is called to scroll the necessary pixels in the 
  58.      table and labels. Performing the scroll here allows us to do a single 
  59.      ScrollRect for each pane rather than one for the table and then another
  60.      for the row/column labels. The visual appearance is much better.
  61. ******************************************************************************/
  62.  
  63. void CTableScroller::ScrollBits( long hDelta, long vDelta)
  64. {
  65.     Rect qdRect;
  66.     LongRect panAperture;
  67.             
  68.         // determine the portion of the table to scroll in the
  69.         // Frame coordinates of this pane.
  70.         
  71.     itsPanorama->Prepare();
  72.     itsPanorama->GetAperture( &panAperture);
  73.     itsPanorama->FrameToEnclR( &panAperture);
  74.     
  75.         // get the rect to scroll in QuickDraw coordinates
  76.         
  77.     Prepare();
  78.     FrameToQDR( &panAperture, &qdRect);
  79.     
  80.         // If any horizontal scrolling is needed, then we must include
  81.         // the column labels in the scroll rectangle.
  82.         
  83.     if (hDelta)
  84.         qdRect.top = 0;
  85.  
  86.         // If any vertical scrolling is needed, then we must include
  87.         // the row labels in the scroll rectangle.
  88.  
  89.     if (vDelta)
  90.         qdRect.left = 0;
  91.  
  92.         // Check if any pixels actually need to be scrolled, if not
  93.         // just do a refresh. Also check if we're doing a simultaneous
  94.         // horizontal and vertical scroll. In that case we can't scroll
  95.         // bits, we must do a refresh and redraw.
  96.         
  97.     if ((Abs(hDelta) < itsPanorama->width) && (Abs(vDelta) < itsPanorama->height) &&
  98.         (!hDelta || !vDelta))
  99.     {        
  100.         ScrollRect( &qdRect, -hDelta, -vDelta, gUtilRgn);
  101.         InvalRgn(gUtilRgn);
  102.     }
  103.     else
  104.     {
  105.         RefreshRect( &qdRect);
  106.     }
  107. }
  108.     
  109. /******************************************************************************
  110.  DoScroll {OVERRIDE}
  111.  
  112.      Override CScrollPane::DoScroll to provide synchronized scrolling.
  113.      
  114. ******************************************************************************/
  115.  
  116. void CTableScroller::DoScroll( long hDelta, long vDelta)
  117. {
  118.     ScrollBits( hDelta, vDelta);
  119.     itsPanorama->Scroll( hDelta, vDelta, kNoRedraw);
  120.     GetWindow()->Update();
  121. }
  122.