home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-03 | 6.1 KB | 280 lines | [TEXT/KAHL] |
- //CVScrollBar.cpp
- //Definition of the class CVScrollBar
- //Date - March 17, 1994
- //© 1994 by Vladimir Potap'yev, Manley & Associates, Inc.
-
-
-
- #ifndef CVScrollBar_H
- #include "CVScrollBar.hpp"
- #endif
-
-
- //we need this to call contrlDefProc
- typedef pascal long (**CntrlDefProcHandle) (short varCode, ControlHandle hCntrl, short message,
- long param);
-
- //we need this struct to do mouse tracking when user is dragging thumb
- typedef struct
- {
- Rect limitRect;
- Rect slopRect;
- short axis;
- }
- ThumbStruct;
-
-
- //currently active scroll bar
- CVScrollBar *gScrollBar;
-
-
-
- //our action procedure for stationary parts
- pascal void SBarActionProcedure (ControlHandle hCntrl, short whichPart)
-
- {
- gScrollBar->DoGoodClick (whichPart);
- //we need this to ensure smooth update of scroll bar
- gScrollBar->Refresh ();
- }
-
-
-
-
-
-
- /******************************************* IVScrollBar **************************************/
-
- void CVScrollBar :: IVScrollBar (
-
- CView *anEnclosure,
- CBureaucrat *aSupervisor,
- Orientation anOrientation,
- short aLength,
- short aHEncl,
- short aVEncl
- )
-
- {
- CScrollBar :: IScrollBar (anEnclosure, aSupervisor, anOrientation, aLength, aHEncl, aVEncl);
- itsScrollCommand = 0L;
- itsPageValue = 0;
- }
-
- // CVScrollBar :: IVScrollBar
-
-
-
-
-
-
-
- /******************************************* DoClick ****************************************/
-
-
- //a quick variation on PinRect
- void PinPtInRect (Rect& rect, Point& pt)
- {
- pt.h = rect.left > pt.h? rect.left : pt.h;
- pt.h = rect.right < pt.h? rect.right : pt.h;
- pt.v = rect.top > pt.v? rect.top : pt.v;
- pt.v = rect.bottom < pt.v? rect.bottom : pt.v;
- }
-
-
-
- void CVScrollBar :: DoClick (Point hitPt, short modifiers, long when)
-
- {
- short whichPart;
- LongPt tmp;
-
- CntrlDefProcHandle hCDEF;
- ThumbStruct thumbData;
- Point oldMousePos;
- Point newMousePos;
- long offset;
- LongRect barFrame;
- Rect updateRect;
- char savedState;
-
-
- gScrollBar = this;
-
- QDToLongPt( hitPt, &tmp);
- FrameToWind( &tmp, &hitPt);
-
-
- whichPart = TestControl( macControl, hitPt);
-
- PenNormal();
-
- if (whichPart >= inThumb)
- {
- oldMousePos = hitPt;
-
- //let's get to the control definition procedure
- hCDEF = (CntrlDefProcHandle) (**macControl).contrlDefProc;
-
- if (*hCDEF == NULL) //see if master pointer is null
- {
- LoadResource ((Handle)hCDEF); //resource is not in memory, load it in
- FailResError (); //make sure we are allright
- }
-
- savedState = HGetState ((Handle)hCDEF); //save the tag byte of the master pointer
- HLock ((Handle)hCDEF); //lock it
- HNoPurge ((Handle)hCDEF); //make it unpurgeable
-
- //we need to fill our ThumbStruct so that we could track the mouse
- //the topLeft corner of limitRect contains the point where mouse press was first detected
- thumbData.limitRect.left = hitPt.h;
- thumbData.limitRect.top = hitPt.v;
- (**hCDEF) (GetCVariant (macControl), macControl, thumbCntl, (long)&thumbData);
-
- while (StillDown())
- {
- Prepare (); //adjust coordinate system
- GetMouse (&newMousePos); //get new mouse position
-
- if (PtInRect (newMousePos, &thumbData.slopRect))
- {
- PinPtInRect (thumbData.limitRect, newMousePos); //and keep it in line
-
- //we force Control Manager to update contrlValue field of ControlRecord
- //by sending it as a message posCntl
- //as a parameter, we pass a long that contains in high word the vertical offset
- //and in the low word horizontal offset
- offset = (newMousePos.v - oldMousePos.v) << 16;
- offset |= (newMousePos.h - oldMousePos.h);
- (**hCDEF) (GetCVariant (macControl), macControl, posCntl, offset);
-
- //now, update the scrolled area
- itsSupervisor->DoCommand (GetScrollCmd());
- }
- oldMousePos = newMousePos;
- }
-
- //now restore the old state of the CDEF
- HSetState ((Handle)hCDEF, savedState);
- }
- else if (whichPart > 0)
- {
- TrackControl(macControl, hitPt, (ProcPtr)&SBarActionProcedure);
-
- //we don't want the scroll bar to flicker
- GetFrame (&barFrame);
- FrameToWindR (&barFrame, &updateRect);
- ValidRect (&updateRect);
- }
- }
-
- // CVScrollBar :: DoClick
-
-
-
-
-
- /**************************************** DoGoodClick **************************************/
-
- void CVScrollBar :: DoGoodClick (short whichPart)
- {
- short theOldValue = GetValue();
- short theNewValue = theOldValue;
- short maxValue = GetMaxValue();
- short minValue = GetMinValue();
-
- switch (whichPart)
- {
- case inUpButton: if (theOldValue > minValue)
- {
- theNewValue--;
- SetValue(theNewValue);
- itsSupervisor->DoCommand (GetScrollCmd());
- }
- break;
-
- case inDownButton: if (theOldValue < maxValue)
- {
- theNewValue++;
- SetValue(theNewValue);
- itsSupervisor->DoCommand (GetScrollCmd());
- }
- break;
-
- case inPageUp: if (theOldValue > minValue)
- {
- theNewValue -= Min (GetPageValue (), (theOldValue - minValue));
- SetValue (theNewValue);
- itsSupervisor->DoCommand (GetScrollCmd());
- }
- break;
-
- case inPageDown: if (theOldValue < maxValue)
- {
- theNewValue += Min (GetPageValue(), (maxValue - theOldValue));
- SetValue(theNewValue);
- itsSupervisor->DoCommand (GetScrollCmd());
- }
- break;
-
- default: break;
- }
- }
-
- // CVScrollBar :: DoGoodClick
-
-
-
-
-
-
- /**************************************** SetScrollCmd *************************************/
-
- void CVScrollBar :: SetScrollCmd (long aCommand)
- {
- itsScrollCommand = aCommand;
- }
-
- // CVScrollBar :: SetScrollCmd
-
-
-
-
-
-
- /*************************************** GetScrollCmd **************************************/
-
- long CVScrollBar :: GetScrollCmd (void)
- {
- return itsScrollCommand;
- }
-
- // CVScrollBar :: GetScrollCmd
-
-
-
-
-
- /***************************************** SetPageValue ***************************************/
-
- void CVScrollBar :: SetPageValue (short aValue)
-
- {
- itsPageValue = aValue;
- }
-
- // CVScrollBar :: SetPageValue
-
-
-
-
- /***************************************** GetPageValue ***************************************/
-
- short CVScrollBar :: GetPageValue (void)
-
- {
- return itsPageValue;
- }
-
- // CVScrollBar :: GetPageValue