home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CPEditText 1.2 / CPEditScrollPane.cp next >
Encoding:
Text File  |  1994-11-30  |  5.1 KB  |  178 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CPEditScrollPane.c
  3.  
  4.                           The PEditScrollPane Class
  5.     
  6.     PEditScrollPane is a helper class for PEditText which provides better
  7.     scrolling for PEditText panes with more than 32k lines of text.
  8.     
  9.     SUPERCLASS = CScrollPane
  10.     
  11.     Copyright © 1992 Christopher R. Wysocki.  All rights reserved.
  12.     Based on code copyright © 1989-1991 Symantec Corporation.
  13.     
  14.  ******************************************************************************/
  15.  
  16. #include "CPEditScrollPane.h"
  17.  
  18. #include <CScrollBar.h>
  19. #include <CPanorama.h>
  20.  
  21.  
  22. /**** C O N S T R U C T I O N / D E S T R U C T I O N   M E T H O D S ****/
  23.  
  24.  
  25. /******************************************************************************
  26.  IScrollPane
  27.  
  28.         Initialize a PEditScrollPane object.
  29.  ******************************************************************************/
  30.  
  31. void    CPEditScrollPane::IPEditScrollPane(
  32.     CView            *anEnclosure,
  33.     CBureaucrat        *aSupervisor,
  34.     short            aWidth,
  35.     short            aHeight,
  36.     short            aHEncl,
  37.     short            aVEncl,
  38.     SizingOption    aHSizing,
  39.     SizingOption    aVSizing,
  40.     Boolean            hasHoriz,
  41.     Boolean            hasVert,
  42.     Boolean            hasSizeBox)
  43. {    
  44.     CScrollPane::IScrollPane(anEnclosure, aSupervisor, aWidth, aHeight, aHEncl,
  45.                     aVEncl, aHSizing, aVSizing, hasHoriz, hasVert, hasSizeBox);
  46.     
  47.     hScale = vScale = 1;
  48. }
  49.     
  50.  
  51. /******************************************************************************
  52.  IViewTemp {OVERRIDE}
  53.  
  54.         Initialize a PEditScrollPane using a template.
  55.  ******************************************************************************/
  56.  
  57. void    CPEditScrollPane::IViewTemp(
  58.     CView            *anEnclosure,        /* Enclosing view                    */
  59.     CBureaucrat        *aSupervisor,        /* Boss in chain of command            */
  60.     Ptr                viewData)            /* Template with View data            */
  61. {
  62.     inherited::IViewTemp(anEnclosure, aSupervisor, viewData);
  63.     
  64.     hScale = vScale = 1;
  65. }
  66.  
  67.  
  68. /**** S C R O L L   B A R   M A I N T E N A N C E   M E T H O D S ****/
  69.  
  70.  
  71. /******************************************************************************
  72.  AdjustScrollMax {OVERRIDE}
  73.  
  74.         Adjust the maximum value of the scroll bars to conform to the
  75.         extent and frame size of the Panorama.
  76.  ******************************************************************************/
  77.  
  78. void    CPEditScrollPane::AdjustScrollMax()
  79. {
  80.     long        hPos, vPos;
  81.     short        hFSpan, vFSpan;
  82.     
  83.     if (itsPanorama == NULL)            /* Take a quick exit if no            */
  84.         return;                            /*   Panorama is installed            */
  85.     
  86.     itsPanorama->GetExtent(&hPos, &vPos);
  87.     hExtent = hPos;
  88.     vExtent = vPos;
  89.     
  90.     itsPanorama->GetFrameSpan(&hFSpan, &vFSpan);
  91.     hSpan = hFSpan;
  92.     vSpan = vFSpan;
  93.     
  94.     hScale = hExtent / MAXINT + 1;        /* Controls are limited to shorts    */
  95.     vScale = vExtent / MAXINT + 1;        /* Need to scale in case extent is    */
  96.                                         /*   larger than a short            */
  97.     
  98.     itsPanorama->GetFramePosition(&hPos, &vPos);
  99.  
  100.     if (itsHorizSBar != NULL)
  101.         itsHorizSBar->SetMaxValue(Max((hExtent - hSpan), hPos) / hScale);
  102.  
  103.     if (itsVertSBar != NULL)
  104.         itsVertSBar->SetMaxValue(Max((vExtent - vSpan), vPos) / vScale);
  105. }
  106.  
  107.  
  108. /******************************************************************************
  109.  Calibrate {OVERRIDE}
  110.  
  111.         Adjust scroll bar setting when the position of the frame of the
  112.         ScrollPane's panorama changes.
  113.  ******************************************************************************/
  114.  
  115. void    CPEditScrollPane::Calibrate()
  116. {
  117.     long        hPos, vPos;
  118.     
  119.     if (itsPanorama == NULL)            /* Take a quick exit if no            */
  120.         return;                            /*   Panorama is installed            */
  121.  
  122.     itsPanorama->GetFramePosition(&hPos, &vPos);
  123.     
  124.     if (itsHorizSBar != NULL)
  125.         itsHorizSBar->SetValue((short) (hPos / hScale));
  126.     
  127.     if (itsVertSBar != NULL)
  128.         itsVertSBar->SetValue((short) (vPos / vScale));
  129. }
  130.  
  131.  
  132. /******************************************************************************
  133.  DoThumbDrag {OVERRIDE}
  134.  
  135.         Adjust associated Panorama when the thumb of a scroll bar is dragged
  136.  ******************************************************************************/
  137.  
  138. void    CPEditScrollPane::DoThumbDrag(
  139.     short        hDelta,
  140.     short        vDelta)
  141. {
  142.     long        hPixels = 0;
  143.     long        vPixels = 0;
  144.     LongPt        currPos, newPos;
  145.     
  146.     /* Because of the scaling of control values when using long coordinates    */
  147.     /* dragging the thumb to the beginning or end of the scroll bar will    */
  148.     /* sometimes not fully scroll to the beginning or end. Catch this by    */
  149.     /* checking if the current value is the max or min.                        */
  150.     
  151.     itsPanorama->GetFramePosition(&currPos.h, &currPos.v);
  152.     
  153.     if (hDelta != 0 && itsHorizSBar != NULL) {
  154.         if (itsHorizSBar->GetValue() == itsHorizSBar->GetMinValue()) {
  155.             itsPanorama->GetHomePosition(&newPos);
  156.             hPixels = newPos.h - currPos.h;
  157.         }
  158.         else if (itsHorizSBar->GetValue() == itsHorizSBar->GetMaxValue())
  159.             hPixels = Max(0, hExtent - hSpan - currPos.h);
  160.         else
  161.             hPixels = Min(((long)hDelta) * hUnit * hScale, hExtent - hSpan - currPos.h);
  162.     }
  163.     
  164.      if (vDelta != 0 && itsVertSBar != NULL) {
  165.         if (itsVertSBar->GetValue() == itsVertSBar->GetMinValue()) {
  166.             itsPanorama->GetHomePosition(&newPos);
  167.             vPixels = newPos.v - currPos.v;
  168.         }
  169.         else if (itsVertSBar->GetValue() == itsVertSBar->GetMaxValue())
  170.             vPixels = Max(0, vExtent - vSpan - currPos.v);
  171.         else
  172.             vPixels = Min(((long)vDelta) * vUnit * vScale, vExtent - vSpan - currPos.v);
  173.     }
  174.     
  175.      if (hPixels != 0 || vPixels != 0)
  176.         DoScroll(hPixels, vPixels);
  177. }
  178.