home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-30 | 5.1 KB | 178 lines | [TEXT/KAHL] |
- /******************************************************************************
- CPEditScrollPane.c
-
- The PEditScrollPane Class
-
- PEditScrollPane is a helper class for PEditText which provides better
- scrolling for PEditText panes with more than 32k lines of text.
-
- SUPERCLASS = CScrollPane
-
- Copyright © 1992 Christopher R. Wysocki. All rights reserved.
- Based on code copyright © 1989-1991 Symantec Corporation.
-
- ******************************************************************************/
-
- #include "CPEditScrollPane.h"
-
- #include <CScrollBar.h>
- #include <CPanorama.h>
-
-
- /**** 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 ****/
-
-
- /******************************************************************************
- IScrollPane
-
- Initialize a PEditScrollPane object.
- ******************************************************************************/
-
- void CPEditScrollPane::IPEditScrollPane(
- CView *anEnclosure,
- CBureaucrat *aSupervisor,
- short aWidth,
- short aHeight,
- short aHEncl,
- short aVEncl,
- SizingOption aHSizing,
- SizingOption aVSizing,
- Boolean hasHoriz,
- Boolean hasVert,
- Boolean hasSizeBox)
- {
- CScrollPane::IScrollPane(anEnclosure, aSupervisor, aWidth, aHeight, aHEncl,
- aVEncl, aHSizing, aVSizing, hasHoriz, hasVert, hasSizeBox);
-
- hScale = vScale = 1;
- }
-
-
- /******************************************************************************
- IViewTemp {OVERRIDE}
-
- Initialize a PEditScrollPane using a template.
- ******************************************************************************/
-
- void CPEditScrollPane::IViewTemp(
- CView *anEnclosure, /* Enclosing view */
- CBureaucrat *aSupervisor, /* Boss in chain of command */
- Ptr viewData) /* Template with View data */
- {
- inherited::IViewTemp(anEnclosure, aSupervisor, viewData);
-
- hScale = vScale = 1;
- }
-
-
- /**** 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 ****/
-
-
- /******************************************************************************
- AdjustScrollMax {OVERRIDE}
-
- Adjust the maximum value of the scroll bars to conform to the
- extent and frame size of the Panorama.
- ******************************************************************************/
-
- void CPEditScrollPane::AdjustScrollMax()
- {
- long hPos, vPos;
- short hFSpan, vFSpan;
-
- if (itsPanorama == NULL) /* Take a quick exit if no */
- return; /* Panorama is installed */
-
- itsPanorama->GetExtent(&hPos, &vPos);
- hExtent = hPos;
- vExtent = vPos;
-
- itsPanorama->GetFrameSpan(&hFSpan, &vFSpan);
- hSpan = hFSpan;
- vSpan = vFSpan;
-
- hScale = hExtent / MAXINT + 1; /* Controls are limited to shorts */
- vScale = vExtent / MAXINT + 1; /* Need to scale in case extent is */
- /* larger than a short */
-
- itsPanorama->GetFramePosition(&hPos, &vPos);
-
- if (itsHorizSBar != NULL)
- itsHorizSBar->SetMaxValue(Max((hExtent - hSpan), hPos) / hScale);
-
- if (itsVertSBar != NULL)
- itsVertSBar->SetMaxValue(Max((vExtent - vSpan), vPos) / vScale);
- }
-
-
- /******************************************************************************
- Calibrate {OVERRIDE}
-
- Adjust scroll bar setting when the position of the frame of the
- ScrollPane's panorama changes.
- ******************************************************************************/
-
- void CPEditScrollPane::Calibrate()
- {
- long hPos, vPos;
-
- if (itsPanorama == NULL) /* Take a quick exit if no */
- return; /* Panorama is installed */
-
- itsPanorama->GetFramePosition(&hPos, &vPos);
-
- if (itsHorizSBar != NULL)
- itsHorizSBar->SetValue((short) (hPos / hScale));
-
- if (itsVertSBar != NULL)
- itsVertSBar->SetValue((short) (vPos / vScale));
- }
-
-
- /******************************************************************************
- DoThumbDrag {OVERRIDE}
-
- Adjust associated Panorama when the thumb of a scroll bar is dragged
- ******************************************************************************/
-
- void CPEditScrollPane::DoThumbDrag(
- short hDelta,
- short vDelta)
- {
- long hPixels = 0;
- long vPixels = 0;
- LongPt currPos, newPos;
-
- /* Because of the scaling of control values when using long coordinates */
- /* dragging the thumb to the beginning or end of the scroll bar will */
- /* sometimes not fully scroll to the beginning or end. Catch this by */
- /* checking if the current value is the max or min. */
-
- itsPanorama->GetFramePosition(&currPos.h, &currPos.v);
-
- if (hDelta != 0 && itsHorizSBar != NULL) {
- if (itsHorizSBar->GetValue() == itsHorizSBar->GetMinValue()) {
- itsPanorama->GetHomePosition(&newPos);
- hPixels = newPos.h - currPos.h;
- }
- else if (itsHorizSBar->GetValue() == itsHorizSBar->GetMaxValue())
- hPixels = Max(0, hExtent - hSpan - currPos.h);
- else
- hPixels = Min(((long)hDelta) * hUnit * hScale, hExtent - hSpan - currPos.h);
- }
-
- if (vDelta != 0 && itsVertSBar != NULL) {
- if (itsVertSBar->GetValue() == itsVertSBar->GetMinValue()) {
- itsPanorama->GetHomePosition(&newPos);
- vPixels = newPos.v - currPos.v;
- }
- else if (itsVertSBar->GetValue() == itsVertSBar->GetMaxValue())
- vPixels = Max(0, vExtent - vSpan - currPos.v);
- else
- vPixels = Min(((long)vDelta) * vUnit * vScale, vExtent - vSpan - currPos.v);
- }
-
- if (hPixels != 0 || vPixels != 0)
- DoScroll(hPixels, vPixels);
- }
-