home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / Intelligent classes 1.0 / CIntelligentScrollPane.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  2.7 KB  |  107 lines  |  [TEXT/KAHL]

  1. /****
  2.  *    CIntelligentScrollPane.c
  3.  *
  4.  *    This class makes the ScrollPane a little more intelligent.
  5.  *
  6.  *    Copyright © 1993 Quipus, by Mårten Sörliden.  All rights reserved.
  7.  *
  8.  ****/
  9.  
  10. #include <CScrollBar.h>
  11. #include <CIntelligentScrollPane.h>
  12. #include <CIntelligentPanorama.h>
  13. #include <CIntelligentWindow.h>
  14.  
  15.  
  16. /** Construction and destruction methods **/
  17.  
  18. void CIntelligentScrollPane::IIntelligentScrollPane(CView *anEnclosure, CBureaucrat *aSupervisor,
  19.                             short aWidth, short aHeight,
  20.                             short aHEncl, short aVEncl,
  21.                             SizingOption aHSizing, SizingOption aVSizing,
  22.                             Boolean hasHoriz, Boolean hasVert, Boolean hasSizeBox)
  23. {
  24.     IScrollPane(anEnclosure, aSupervisor, aWidth, aHeight,
  25.                     aHEncl, aVEncl, aHSizing, aVSizing,
  26.                     hasHoriz, hasVert, hasSizeBox);
  27.  
  28. }
  29.  
  30. void CIntelligentScrollPane::Dispose(void)
  31. {
  32.     if (itsPanorama)
  33.         if (member(itsPanorama, CIntelligentPanorama))
  34.             itsPanorama->SetScrollPane(NULL);
  35.     inherited::Dispose();
  36. }
  37.  
  38.  
  39. /** Accessing methods **/
  40.  
  41. void CIntelligentScrollPane::GetPreferedFrame(LongRect *theFrame)
  42. {
  43.     LongRect theAperture;
  44.     LongRect theBounds;
  45.     
  46.     GetFrame(theFrame);
  47.     if (itsPanorama) {
  48.         itsPanorama->GetAperture(&theAperture);
  49.         itsPanorama->GetBounds(&theBounds);
  50.         theFrame->right = theFrame->right + (theBounds.right - theBounds.left) - (theAperture.right - theAperture.left);
  51.         theFrame->bottom = theFrame->bottom + (theBounds.bottom - theBounds.top) - (theAperture.bottom - theAperture.top);
  52.     }
  53. }
  54.  
  55.  
  56. /** Scroll bar maintenance methods **/
  57.  
  58. // Override
  59. void    CIntelligentScrollPane::AdjustScrollMax()
  60. {
  61.     register short    newMax;                /* New maximum scroll bar setting    */
  62.     long                    hPos;
  63.     long                    vPos;
  64.     short                hFSpan;
  65.     short                vFSpan;
  66.     short                theValue;
  67.     
  68.     if (itsPanorama == NULL)            /* Take a quick exit if no            */
  69.         return;                            /*   Panorama is installed            */
  70.     
  71.     itsPanorama->GetExtent(&hPos, &vPos);
  72.     hExtent = hPos;
  73.     vExtent = vPos;
  74.     
  75.     itsPanorama->GetFrameSpan(&hFSpan, &vFSpan);
  76.     hSpan = hFSpan;
  77.     vSpan = vFSpan;
  78.     
  79.     hUnit = hExtent / MAXINT + 1;        /* Controls are limited to shorts    */
  80.     vUnit = vExtent / MAXINT + 1;        /* Need to scale in case extent is    */
  81.                                         /*   larger than a short            */
  82.     hStep = Max( hUnit, hStep);
  83.     vStep = Max( vUnit, vStep);
  84.  
  85.     itsPanorama->GetFramePosition(&hPos, &vPos);
  86.  
  87.     if (itsHorizSBar != NULL) {
  88.         theValue = Max((hExtent - hSpan), hPos) / hUnit;
  89.         if (theValue >= 0)
  90.             itsHorizSBar->SetMaxValue(theValue);
  91.         else
  92.             itsHorizSBar->SetMaxValue(0);
  93.     }
  94.  
  95.     if (itsVertSBar != NULL) {
  96.         theValue = Max((vExtent - vSpan), vPos) / vUnit;
  97.         if (theValue >= 0)
  98.             itsVertSBar->SetMaxValue(theValue);
  99.         else
  100.             itsVertSBar->SetMaxValue(0);
  101.     }
  102.  
  103.     if (itsPanorama) {
  104.         if (member(itsEnclosure, CIntelligentWindow))
  105.             ((CIntelligentWindow *)itsEnclosure)->UpdateStdState();
  106.     }
  107. }