shellscroll.c

Go to the documentation of this file.
00001 
00002 /*  $Id: shellscroll.c 1203 2006-04-05 22:58:09Z karstenw $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 #include "frontier.h"
00029 #include "standard.h"
00030 
00031 #include "scrollbar.h"
00032 #include "quickdraw.h"
00033 #include "shell.h"
00034 #include "shellprivate.h"
00035 
00036 
00037 
00038 void shellupdatescrollbars (hdlwindowinfo hinfo) {
00039     
00040     /*
00041     can be called by an application to update the scrollbars when they need changing
00042     and the shell isn't expecting a change.
00043     
00044     an example -- a range delete operation in a spreadsheet, or a dragging move
00045     in an outline.
00046     
00047     dw to dmb: this routine now takes a hldwindowinfo parameter, not a windowptr.
00048     */
00049     
00050     register hdlwindowinfo h = hinfo;
00051     
00052     setscrollbarinfo ((**h).vertscrollbar, &(**h).vertscrollinfo);
00053     
00054     setscrollbarinfo ((**h).horizscrollbar, &(**h).horizscrollinfo);
00055     
00056     (**h).fldirtyscrollbars = false;
00057     } /*shellupdatescrollbars*/
00058     
00059     
00060 void shellcheckdirtyscrollbars (void) {
00061     
00062     if (!shellpushfrontglobals ()) /*need at least one window open*/
00063         return;
00064     
00065     /*dmb to DW: why was this excluded for dialogs?  no longer valid, but am I breaking something?
00066     if (!config.fldialog)
00067     */
00068         if ((**shellwindowinfo).fldirtyscrollbars) {
00069             
00070             shellupdatescrollbars (shellwindowinfo);
00071             }
00072     
00073     shellpopglobals ();
00074     } /*shellcheckdirtyscrollbars*/
00075     
00076     
00077 void shellsetscrollbars (WindowPtr w) {
00078     
00079     /*
00080     call the driver to set the min, max and current values for the scroll 
00081     bars.  
00082     
00083     8/31/90 DW: we not longer set globals, we now push them.
00084     */
00085     
00086     shellpushglobals (w);
00087     
00088     (*shellglobals.setscrollbarroutine) ();
00089     
00090     shellupdatescrollbars (shellwindowinfo);
00091         
00092     shellpopglobals ();
00093     } /*shellsetscrollbars*/
00094 
00095 
00096 static tydirection scrolldirection (boolean flvert, boolean flup) {
00097 
00098     register tydirection dir;
00099     
00100     if (flvert)
00101         if (flup)
00102             dir = up;
00103         else
00104             dir = down;
00105     else
00106         if (flup)
00107             dir = left;
00108         else
00109             dir = right;
00110     
00111     return (dir);
00112     } /*scrolldirection*/
00113 
00114 
00115 
00116 
00117 #ifdef WIN95VERSION
00118 
00119 void winscroll (boolean isvertscroll, int scrolltype, long pos)
00120     {
00121 
00122     /*
00123     7.0b20 PBS: Fix Windows display glitch -- if scroll is finished,
00124     redraw the scrollbar.
00125     */
00126 
00127     boolean flup, flpage;
00128     long distance;
00129     tyscrollinfo scrollinfo;
00130     tydirection dir;
00131 
00132     if (shellwindowinfo != NULL)
00133         {
00134         if (isvertscroll)
00135             {
00136             scrollinfo = (**shellwindowinfo).vertscrollinfo;
00137             }
00138         else
00139             {
00140             scrollinfo = (**shellwindowinfo).horizscrollinfo;
00141             }
00142 
00143         switch (scrolltype)
00144             {
00145             case SB_LINEUP:
00146             case SB_PAGEUP:
00147             case SB_TOP:
00148                 flup = false;
00149                 break;
00150 
00151             case SB_BOTTOM:
00152             case SB_LINEDOWN:
00153             case SB_PAGEDOWN:
00154                 flup = true;
00155                 break;
00156 
00157             case SB_THUMBPOSITION:
00158             case SB_THUMBTRACK:
00159                 if (pos < scrollinfo.cur)
00160                     flup = false;
00161                 else
00162                     flup = true;
00163                 break;
00164             default:
00165                 flup = false;
00166                 break;
00167             }
00168 
00169         dir = scrolldirection (isvertscroll, flup);
00170 
00171         flpage = false;
00172         distance = 0;
00173 
00174         switch (scrolltype)
00175             {
00176             case SB_PAGEUP:
00177             case SB_PAGEDOWN:
00178                 flpage = true;
00179                 distance = 1;
00180                 break;
00181 
00182             case SB_LINEUP:
00183             case SB_LINEDOWN:
00184                 distance = 1;
00185                 break;
00186 
00187             case SB_BOTTOM:
00188                 distance = scrollinfo.max - scrollinfo.cur;
00189                 break;
00190 
00191             case SB_TOP:
00192                 distance = scrollinfo.cur - scrollinfo.min;
00193                 break;
00194 
00195             case SB_THUMBPOSITION:
00196             case SB_THUMBTRACK:
00197                 distance = scrollinfo.cur - pos;
00198                 break;
00199 
00200             default:
00201                 break;
00202             }
00203 
00204         distance = abs(distance);
00205 
00206         if (distance > 0)
00207             (*shellglobals.scrollroutine) (dir, flpage, distance);
00208 
00209         if (scrolltype == SB_ENDSCROLL) { /*7.0b20 PBS: Fix Windows display glitch -- redraw.*/
00210 
00211             if (isvertscroll)
00212 
00213                 drawscrollbar ((**shellwindowinfo).vertscrollbar);
00214             
00215             else
00216 
00217                 drawscrollbar ((**shellwindowinfo).horizscrollbar);
00218             } /*if*/
00219 
00220         }
00221     }
00222 
00223 #endif
00224 
00225 
00226 #ifdef MACVERSION
00227 static pascal void shellhorizscroll (hdlscrollbar ctrl, short part) {
00228     
00229     register hdlwindowinfo h = shellwindowinfo;
00230     boolean flleft, flpage;
00231     register tydirection dir;
00232     
00233     if (!scrollbarhit (ctrl, part, &flleft, &flpage))
00234         return;
00235     
00236     /*  
00237     pushclip ((**h).contentrect);
00238     */
00239     
00240     dir = scrolldirection (false, flleft);
00241     
00242     (*shellglobals.scrollroutine) (dir, flpage, 1);
00243     
00244     /*
00245     popclip ();
00246     */
00247     
00248     setscrollbarinfo ((**h).horizscrollbar, &(**h).horizscrollinfo);
00249     } /*shellhorizscroll*/
00250 
00251 
00252 static pascal void shellvertscroll (hdlscrollbar ctrl, short part) {
00253     
00254     register hdlwindowinfo h = shellwindowinfo;
00255     boolean flup, flpage;
00256     register tydirection dir;
00257     
00258     if (!scrollbarhit (ctrl, part, &flup, &flpage))
00259         return;
00260     
00261     /*
00262     pushclip ((**h).contentrect);
00263     */
00264     
00265     dir = scrolldirection (true, flup);
00266         
00267     (*shellglobals.scrollroutine) (dir, flpage, 1);
00268     
00269     /*  
00270     popclip ();
00271     */
00272     
00273     setscrollbarinfo ((**h).vertscrollbar, &(**h).vertscrollinfo);
00274     } /*shellvertscroll*/
00275 
00276 
00277 //Code change by Timothy Paustian Friday, June 16, 2000 3:14:00 PM
00278 //Changed to Opaque call for Carbon
00279 
00280 #if TARGET_RT_MAC_MACHO
00281     #define shellvertscrollUPP  (&shellvertscroll)
00282     #define shellhorizscrollUPP (&shellhorizscroll)
00283     #define shelllivescrollupp  (&ScrollThumbActionProc)
00284 #elif TARGET_RT_MAC_CFM
00285     #if TARGET_API_MAC_CARBON
00286         ControlActionUPP    shellvertscrollDesc;
00287         ControlActionUPP    shellhorizscrollDesc;
00288         ControlActionUPP    shelllivescrollupp;
00289         #define shellvertscrollUPP (shellvertscrollDesc)
00290         #define shellhorizscrollUPP (shellhorizscrollDesc)
00291     #else
00292         static RoutineDescriptor shellvertscrollDesc = BUILD_ROUTINE_DESCRIPTOR (uppControlActionProcInfo, shellvertscroll);
00293         static RoutineDescriptor shellhorizscrollDesc = BUILD_ROUTINE_DESCRIPTOR (uppControlActionProcInfo, shellhorizscroll);
00294         #define shellvertscrollUPP (&shellvertscrollDesc)
00295         #define shellhorizscrollUPP (&shellhorizscrollDesc)
00296     #endif
00297 #endif
00298 
00299 #if TARGET_API_MAC_CARBON == 1
00300 
00301 /*The live scrolling code descends from Apple sample code, hence the different style of code.*/
00302 
00303 enum
00304 {
00305     // Misc scroll bar constants
00306 
00307     kScrollBarWidth = 16,
00308     kScrollBarWidthAdjust = kScrollBarWidth - 1,
00309     
00310     kScrollArrowWidth = 16,
00311     kScrollThumbWidth = 16,
00312     kTotalWidthAdjust = (kScrollArrowWidth * 2) + kScrollThumbWidth,
00313     
00314     kPageOverlap = 10,
00315     kThumbTrackWidthSlop = 50,
00316     kThumbTrackLengthSlop = 113
00317 
00318 };
00319 
00320 
00321 static ControlRef   gControl;
00322 static SInt32       gValueSlop;
00323 //static SInt32     gSaveValue;
00324 static SInt32       gStartValue;
00325 
00326 static SInt32   CalcValueFromPoint ( ControlRef theControl, Point thePoint );
00327 static boolean flverticalscroll;
00328 static RgnHandle    gSaveClip = nil;
00329 static long lastpoint;
00330 
00331 pascal void ScrollThumbActionProc (void);
00332 
00333 
00334 static void DisableDrawing ( void ) {
00335 
00336     Rect    nullRect = { 0, 0, 0, 0 };
00337 
00338     GetClip ( gSaveClip );
00339     ClipRect ( &nullRect );
00340     
00341     return;
00342     } /*DisableDrawing*/
00343 
00344 
00345 static void EnableDrawing ( void ) {
00346 
00347     SetClip ( gSaveClip );
00348     
00349     return;
00350     } /*EnableDrawing*/
00351 
00352 
00353 SInt32 CalcValueFromPoint (ControlHandle hControl, Point thePoint) {
00354     
00355     /*Figure where we are in scroll bar terms.*/
00356 
00357     SInt32 theValue = 0, theRange, theDistance, thePin;
00358     Rect rectControl, indicatorbounds;
00359     WindowPtr lpWindow;
00360     long thumbheight = 16;
00361     long thumbwidth = 16;
00362     RgnHandle indicatorregion = NewRgn ();
00363     long gTotalVSizeAdjust, gTotalWidthAdjust;
00364     short baselineoffset;
00365     
00366     GetControlRegion (hControl, kControlIndicatorPart, indicatorregion);
00367     GetRegionBounds (indicatorregion, &indicatorbounds);
00368     
00369     thumbheight = indicatorbounds.bottom - indicatorbounds.top;
00370     
00371     thumbwidth = indicatorbounds.right - indicatorbounds.left;
00372     
00373     DisposeRgn (indicatorregion);
00374     
00375     gTotalVSizeAdjust = ((kScrollArrowWidth * 2) + thumbheight);
00376     
00377     gTotalWidthAdjust = ((kScrollArrowWidth * 2) + thumbwidth);
00378 
00379     lpWindow = shellwindow; // (*hControl)->contrlOwner;
00380     
00381     zerorect (&rectControl);
00382     
00383     GetBestControlRect (hControl, &rectControl, &baselineoffset);
00384     
00385     //rectControl = (*hControl)->contrlRect;
00386     
00387     theRange = GetControlMaximum ( hControl ) - GetControlMinimum ( hControl );
00388     
00389     if (flverticalscroll) {
00390     
00391         // Scroll distance adjusted for scroll arrows and the thumb
00392         theDistance = rectControl.bottom - rectControl.top - gTotalVSizeAdjust;
00393         // Pin thePoint to the middle of the thumb
00394         thePin = rectControl.top + (thumbheight / 2);
00395         thePin = lastpoint;
00396         theValue = ((thePoint.v - thePin) * theRange) / theDistance;
00397         } /*if*/
00398     
00399     else { /*horizontal scrolling*/
00400         
00401         theDistance = rectControl.right - rectControl.left - gTotalWidthAdjust;
00402 
00403         thePin = rectControl.left + (thumbwidth / 2);
00404         
00405         thePin = lastpoint;
00406         
00407         theValue = ((thePoint.h - thePin) * theRange) / theDistance;
00408         } /*else*/
00409 
00410     theValue += gValueSlop;
00411     
00412     if ( theValue < GetControlMinimum ( hControl ) )
00413         theValue = GetControlMinimum ( hControl );
00414     else if ( theValue > GetControlMaximum ( hControl ) )
00415         theValue = GetControlMaximum ( hControl );
00416 
00417     return theValue;
00418     } /*CalcValueFromPoint*/
00419     
00420     
00421 pascal void ScrollThumbActionProc (void) {
00422 
00423     SInt32 theValue;
00424     hdlscrollbar hscrollbar;
00425     Point thePoint;
00426     Rect theRect;
00427     long ctscroll;
00428     tydirection dir;
00429     long currvalue;
00430     hdlwindowinfo h = shellwindowinfo;
00431     short baselineoffset;
00432 
00433     if (h == nil) /*defensive driving*/
00434         return;
00435 
00436     hscrollbar = (**h).vertscrollbar;
00437     
00438     if (!flverticalscroll)
00439         hscrollbar = (**h).horizscrollbar;
00440     
00441     zerorect (&theRect);
00442     
00443     GetBestControlRect (hscrollbar, &theRect, &baselineoffset);
00444     //theRect = (**hscrollbar).contrlRect;
00445     
00446     if (flverticalscroll)
00447         
00448         insetrect (&theRect, -kThumbTrackLengthSlop, -kThumbTrackWidthSlop);
00449         
00450     else
00451         
00452         insetrect (&theRect, -kThumbTrackWidthSlop, -kThumbTrackLengthSlop);
00453     
00454     GetMouse (&thePoint);
00455         
00456     if (pointinrect (thePoint, theRect))
00457         
00458         theValue = CalcValueFromPoint (hscrollbar, thePoint);
00459         
00460     else
00461         
00462         theValue = gStartValue;
00463         
00464     currvalue = (**h).vertscrollinfo.cur;
00465     
00466     if (theValue != GetControlValue (hscrollbar)) { // if we scrolled
00467         
00468         EnableDrawing ();
00469 
00470         ctscroll = theValue - GetControlValue (hscrollbar);
00471         
00472         dir = scrolldirection (flverticalscroll, ctscroll > 0); 
00473         
00474         (*shellglobals.scrollroutine) (dir, false, abs (ctscroll));
00475         
00476         (**h).vertscrollinfo.cur = theValue;
00477 
00478         DisableDrawing ();
00479         } /*if*/
00480     
00481     return;
00482     } /*ScrollThumbActionProc*/
00483 
00484 
00485 static OSErr BeginThumbTracking ( ControlRef theControl ) {
00486 
00487     OSErr theErr = noErr;
00488     Point thePoint;
00489 
00490     gControl = theControl;
00491     gStartValue = GetControlValue ( theControl );
00492     
00493     gValueSlop = 0;
00494     GetMouse ( &thePoint );
00495     
00496     if (flverticalscroll)
00497         lastpoint = thePoint.v;
00498     else
00499         lastpoint = thePoint.h;
00500     
00501     gValueSlop = GetControlValue ( theControl ) - CalcValueFromPoint ( theControl, thePoint );
00502         
00503     gSaveClip = NewRgn ( );
00504 
00505     DisableDrawing ( );
00506     
00507     return theErr;
00508     } /*BeginThumbTracking*/
00509     
00510 
00511 static void EndThumbTracking ( void ) {
00512     
00513 //  hdlwindowinfo h = shellwindowinfo;
00514 
00515     EnableDrawing ();
00516 
00517     DisposeRgn ( gSaveClip );
00518 
00519 //  if (flverticalscroll)
00520 //      setscrollbarcurrent ((**h).vertscrollbar, (**h).vertscrollinfo.cur);
00521 //  else
00522 //      setscrollbarcurrent ((**h).horizscrollbar, (**h).horizscrollinfo.cur);
00523 
00524     return;
00525     } /*EndThumbTracking*/
00526 
00527 #endif
00528 
00529 extern void shellinitscroll ();
00530 
00531 void shellinitscroll(void)
00532 {
00533     //Code change by Timothy Paustian Saturday, July 22, 2000 12:04:35 AM
00534     //Needed in shellscroll
00535     #if TARGET_API_MAC_CARBON
00536         #if TARGET_RT_MAC_CFM
00537             shellvertscrollDesc = NewControlActionUPP(shellvertscroll);
00538             shellhorizscrollDesc = NewControlActionUPP(shellhorizscroll);
00539             shelllivescrollupp = NewControlActionUPP (ScrollThumbActionProc);
00540         #endif
00541     #endif
00542 }
00543 
00544 extern void shellshutdownscroll ();
00545 
00546 void shellshutdownscroll(void)
00547 {
00548     #if TARGET_API_MAC_CARBON
00549         #if TARGET_RT_MAC_CFM
00550             DisposeControlActionUPP(shellvertscrollDesc);
00551             DisposeControlActionUPP(shellhorizscrollDesc);
00552             DisposeControlActionUPP (shelllivescrollupp);
00553         #endif
00554     #endif
00555 }
00556 
00557 
00558 void shellscroll (boolean flvert, hdlscrollbar sb, short part, Point pt) {
00559     
00560 //  register WindowPtr w = shellwindow;
00561     register long oldscrollbarcurrent;
00562     #if TARGET_API_MAC_CARBON != 1
00563         register long ctscroll;
00564         tydirection dir;
00565     #endif
00566     
00567     //pushclip ((*w).portRect); /*allow drawing in whole window%/
00568         
00569     if (part == kControlIndicatorPart) {
00570         
00571         oldscrollbarcurrent = getscrollbarcurrent (sb);
00572         
00573         #if TARGET_API_MAC_CARBON == 1
00574             
00575             gControl = sb;
00576             
00577             flverticalscroll = flvert;
00578             
00579             gStartValue = oldscrollbarcurrent;
00580             
00581             BeginThumbTracking (sb);
00582             
00583             TrackControl (sb, pt, (ControlActionUPP) shelllivescrollupp);
00584             
00585             EndThumbTracking ();            
00586         
00587         #else
00588         
00589             TrackControl (sb, pt, nil);
00590             
00591             ctscroll = getscrollbarcurrent (sb) - oldscrollbarcurrent;
00592         
00593             dir = scrolldirection (flvert, ctscroll > 0);
00594             
00595             (*shellglobals.scrollroutine) (dir, false, abs (ctscroll));
00596 
00597         #endif          
00598         }
00599     
00600     else {
00601     
00602         if (flvert)
00603         
00604             TrackControl (sb, pt, shellvertscrollUPP);
00605             
00606         else
00607         
00608             TrackControl (sb, pt, shellhorizscrollUPP);
00609         }
00610     
00611     /*
00612     popclip ();
00613     */
00614     } /*shellscroll*/
00615     
00616 #endif
00617 
00618 
00619 

Generated on Wed May 31 18:20:01 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6