home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Today - The Disc! 8 / cdrt08.iso / mac / Shareware / HyperCard / demoCdef 120 ƒ / cdef3D source ƒ / cdef Common / miscCDEF.c < prev    next >
Encoding:
Text File  |  1994-12-12  |  2.8 KB  |  103 lines  |  [TEXT/KAHL]

  1. //----------------------------------------------------------------------------------
  2. // File        : miscCDEF.c
  3. // Date        : November 2,1991
  4. // Author    : Jim Stout
  5. // Purpose    : support routines CDEFs.
  6. //----------------------------------------------------------------------------------
  7.  
  8. #include <GestaltEqu.h>
  9. #include <Traps.h>
  10. #include "miscCDEF.h"
  11.  
  12. //----------------------------------------------------------------------------------
  13. //    Get the pixel depth of the current GDevice
  14. //----------------------------------------------------------------------------------
  15. short getPixDepth(Rect *r)
  16. {
  17.     Rect            gRect, iRect;
  18.     GDHandle         gDev;
  19.     short            thisDepth, pixDepth = 32;
  20.     
  21.     if(!trapAvailable(_GetDeviceList))            // Must have Device Mgr
  22.         return(1);
  23.         
  24.     gRect = *r;
  25.     
  26.     LocalToGlobal((Point *)&gRect.top);
  27.     LocalToGlobal((Point *)&gRect.bottom);
  28.     
  29.     gDev = GetDeviceList();
  30.     while(gDev) {
  31.         if(SectRect(&gRect, &(*gDev)->gdRect, &iRect) &&
  32.             TestDeviceAttribute(gDev,screenDevice) &&
  33.             TestDeviceAttribute(gDev,screenActive)) {
  34.             
  35.             thisDepth = (*(*gDev)->gdPMap)->pixelSize;
  36.             if(thisDepth < pixDepth)
  37.                 pixDepth = thisDepth;
  38.         }
  39.         gDev = GetNextDevice(gDev);
  40.     }
  41.     return(pixDepth);
  42. }
  43.  
  44. //----------------------------------------------------------------------------------
  45. //    Use Gestalt to find out the MacOS version. 
  46. //----------------------------------------------------------------------------------
  47. short getOSVers()
  48. {
  49.     OSErr        err;
  50.     short        ret=0x0600;
  51.     long        gResult;
  52.     
  53.     if(trapAvailable(_Gestalt)) {                        // is Gestalt available ?    
  54.         err = Gestalt(gestaltSystemVersion,&gResult);
  55.         if(err == noErr)
  56.             ret = LoWord(gResult);
  57.     }
  58.     return(ret);
  59. }
  60. //----------------------------------------------------------------------------------
  61. //    Generic routine to see if a given trap is available
  62. //----------------------------------------------------------------------------------
  63.  
  64. Boolean    trapAvailable(theTrap)
  65. short    theTrap;
  66. {
  67.     TrapType    tType;
  68.     
  69.     tType = getTrapType(theTrap);
  70.     
  71.     if(tType == ToolTrap) {
  72.         theTrap &= 0x07ff;
  73.         if(theTrap >= numToolBoxTraps())
  74.             theTrap = _Unimplemented;
  75.     }
  76.     return(( NGetTrapAddress(theTrap, tType) !=
  77.         NGetTrapAddress(_Unimplemented, ToolTrap) ));
  78. }
  79.  
  80. //----------------------------------------------------------------------------------
  81. //    Needed for "trapAvailable" routine
  82. //----------------------------------------------------------------------------------
  83.  
  84. TrapType getTrapType(theTrap)
  85. short    theTrap;
  86. {
  87.     if((theTrap &= 0x0800))
  88.         return(ToolTrap);
  89.     return(OSTrap);
  90. }
  91.  
  92. //----------------------------------------------------------------------------------
  93. //    Needed for "trapAvailable" routine
  94. //----------------------------------------------------------------------------------
  95.  
  96. short numToolBoxTraps()
  97. {
  98.     if(NGetTrapAddress(_InitGraf, ToolTrap) ==
  99.         NGetTrapAddress(0xaa6e, ToolTrap))
  100.         return(0x0200);
  101.     return(0x0400);
  102. }
  103.