home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / PNL Libraries / Libraries / SmartScroll / SmartScrollAPI.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-26  |  4.4 KB  |  136 lines  |  [TEXT/CWIE]

  1. /*
  2.      File:        SmartScrollAPI.c
  3.  
  4.      Contains:    Smart Scroll Application Programming Interface code
  5.  
  6.      Version:    1.2
  7.  
  8.      Copyright:    © 1996 by Marc Moini, portions by Marc Menschenfreund,
  9.                 Alessandro Levi Montalcini and Mark Shirley (Thanks!)
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, please email Marc@Kagi.com
  13.  
  14. */
  15. #ifndef __SMARTSCROLLAPI__
  16. #include "SmartScrollAPI.h"
  17. #endif
  18.  
  19. #if PRAGMA_ALIGN_SUPPORTED
  20. #pragma options align=mac68k
  21. #endif
  22.  
  23. #if PRAGMA_IMPORT_SUPPORTED
  24. #pragma import on
  25. #endif
  26.  
  27. #include "Errors.h"
  28. #include "OSUtils.h"
  29. #include "Traps.h"
  30. #include "Gestalt.h"
  31.  
  32. #define    kgestaltSmartScroll    'MMBS'
  33.  
  34. enum
  35.     {
  36.     kSetSmartScrollInfo = 0L,
  37.     kSetSmartScrollProp,
  38.     kGetSmartScrollProp,
  39.     kDisposeAllSmartScrolls
  40.     };
  41.  
  42. typedef pascal void (*SmartScrollProcPtr) (long selector,long *result,ControlRef theScrollBar,long param1,long param2);
  43.  
  44. typedef struct {
  45.     char                privateStuff[16];
  46.     SmartScrollProcPtr    dispatchProc;
  47.     long                smartScrollSignature;
  48. } SmartScrollGestaltRec, *SmartScrollGestaltPtr;
  49.  
  50.  
  51. #if GENERATINGCFM
  52. #define CallSmartScrollProc(userRoutine, selector, result, theControl, param1, param2)        \
  53.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSmartScrollProcInfo, (selector), (result), (theControl), (param1), (param2))
  54. #else
  55. #define CallSmartScrollProc(userRoutine, selector, result, theControl, param1, param2)        \
  56.         (*(userRoutine))((selector), (result), (theControl), (param1), (param2))
  57. #endif
  58.  
  59. enum    {
  60.     uppSmartScrollProcInfo = kPascalStackBased
  61.         | STACK_ROUTINE_PARAMETER (1, SIZE_CODE(sizeof(long)))
  62.         | STACK_ROUTINE_PARAMETER (2, SIZE_CODE(sizeof(long *)))
  63.         | STACK_ROUTINE_PARAMETER (3, SIZE_CODE(sizeof(ControlRef)))
  64.         | STACK_ROUTINE_PARAMETER (4, SIZE_CODE(sizeof(long)))
  65.         | STACK_ROUTINE_PARAMETER (5, SIZE_CODE(sizeof(long)))
  66. };
  67. /****************************************************************************************/
  68.  
  69. static OSErr __SmartScrollDispatch(long selector,long *result,ControlRef theControl,long param1,long param2)
  70.     {
  71.     OSErr                     ret = paramErr;
  72.     SmartScrollGestaltPtr    ssRec;
  73.     
  74.     if (NGetTrapAddress (_Gestalt, OSTrap) != NGetTrapAddress (_Unimplemented, OSTrap))
  75.         {
  76.         if (Gestalt ( kgestaltSmartScroll, (long *)&ssRec)==noErr
  77.             && ssRec && ssRec->smartScrollSignature==kgestaltSmartScroll)
  78.             {
  79.                 CallSmartScrollProc(ssRec->dispatchProc,selector,result,theControl,param1,param2);
  80.                 ret = noErr;
  81.             }
  82.         }
  83.     return ret;
  84.     }
  85.     
  86. /****************************************************************************************/
  87. /* Call this routine to set the Visible/Total proportion for a scrollbar. */
  88. /*  amountVisible is a 32bit value representing the size of the portion of the document that is visible now. */
  89. /*  amountTotal is a 32bit value representing the size of the whole document. */
  90. /*  these two parameters must share the same unit (pixels, lines, characters, frames, etc). */
  91.  
  92. pascal void SetSmartScrollInfo (ControlRef theScrollBar, long amountVisible , long amountTotal)
  93.     {
  94.     long     dummy;
  95.     
  96.     (void)__SmartScrollDispatch(kSetSmartScrollInfo,&dummy,theScrollBar,amountVisible,amountTotal);
  97.     }
  98.  
  99. /****************************************************************************************/
  100. /* Call this routine to set the Visible/Total proportion for a scrollbar. */
  101. /*  proportion is a Fract value (32bit) representing the Visible/Total ratio */
  102. /*  This call has the exact same effect as SetSmartScrollInfo, you may use either one. */
  103.  
  104. pascal void SetSmartScrollProp (ControlHandle theScrollBar, Fract proportion)
  105. /*
  106. Comment
  107. */
  108.     {
  109.     long     dummy;
  110.     
  111.     (void)__SmartScrollDispatch(kSetSmartScrollProp,&dummy,theScrollBar,(long)proportion,0);
  112.     }
  113.  
  114. /****************************************************************************************/
  115. /* Call this routine to get the last proportion you stored for this scrollbar. */
  116. /* the value returned will be 0 if there is an error (Smart Scroll not installed, or no value stored)  */
  117.  
  118. pascal Fract GetSmartScrollProp (ControlHandle theScrollBar)
  119.     {
  120.     Fract     result = 0L;
  121.     
  122.     __SmartScrollDispatch(kGetSmartScrollProp,(long *)&result,theScrollBar,0,0);
  123.     return result;
  124.     }
  125.  
  126. /****************************************************************************************/
  127. /* Call this routine before your code Quits, to help SmartScroll */
  128. /* free the memory it reserved for the scrollbars in your Application. */
  129.  
  130. pascal void DisposeAllSmartScrolls (void)
  131.     {
  132.     long     dummy;
  133.     
  134.     (void)__SmartScrollDispatch(kDisposeAllSmartScrolls,&dummy,NULL,0,0);
  135.     }
  136.