home *** CD-ROM | disk | FTP | other *** search
- /*________________________________________________________________________________
-
- BadGestalt.c
-
- Copyright © 1993-1995 Onyx Technology - All rights reserved
-
- The routines in this file gather information about the environment
- we're running in. Whenever possible they use Gestalt as the first
- choice and SysEnvirons as a last resort.
-
- IMPORTANT NOTE: Since development environments like MPW and THINK provide
- glue code for Gestalt, and since it's been around for so long now, we don't
- even bother checking for it anymore and just use it instead of reverting
- back to _SysEnvirons calls. Since QC itself won't run on systems that are
- so old they don't have _Gestalt, it's pretty safe to say we wouldn't be
- running this app anyway. If that turns out to be the case, then #define
- _CHK_FOR_GESTALT_ to use code that will check for _Gestalt and use
- SysEnvirons if necessary.
-
- ________________________________________________________________________________*/
-
- #ifndef _H_BadGestalt
- #include "BadGestalt.h"
- #endif
- #ifndef _H_BadGlobs
- #include "BadGlobs.h"
- #endif
-
- //#define _CHK_FOR_GESTALT_ // define this for code that checks for _Gestalt
- // by default we let glue code figure it out for us
-
- /*________________________________________________________________________________
-
- GetSystemVers()
-
- info: Get the system version, try Gestalt first, then SysEnvirons
-
- return: long sysVersion; -1 if failed
-
- ________________________________________________________________________________*/
- long GetSystemVers(void)
- {
- short myErr;
- long sysVersion;
- #ifdef _CHK_FOR_GESTALT_
- SysEnvRec theWorld;
- #endif
-
- if ( HasGestalt() )
- {
- myErr = Gestalt(gestaltSystemVersion, &sysVersion);
- if (myErr)
- sysVersion = -1;
- }
- #ifdef _CHK_FOR_GESTALT_
- else
- {
- if (!SysEnvirons(2, &theWorld))
- sysVersion = theWorld.systemVersion;
- else
- sysVersion = -1;
- }
- #endif //_CHK_FOR_GESTALT_
-
- return(sysVersion);
- }
-
- /*________________________________________________________________________________
-
- HasGestalt()
-
- info: Determine if Gestalt is available or not.
-
- return: true if available, false if not.
-
- ________________________________________________________________________________*/
- short HasGestalt(void)
- {
- #ifdef _CHK_FOR_GESTALT_
- long int GestaltAddr = -1;
- short hasGestalt = false;
-
- GestaltAddr = TrapAvailable(_GestaltDispatch);
-
- if (GestaltAddr>0) // we have it, yeah!
- hasGestalt = true; // set this flag
-
- return(hasGestalt);
- #else
- return(true);
- #endif //_CHK_FOR_GESTALT_
- }
-
-
- /*________________________________________________________________________________
-
- GetQDVers()
-
- info: Get the QuickDraw version, try Gestalt first, then SysEnvirons
-
- return: long sysVersion; -1 if failed
-
- ________________________________________________________________________________*/
- short GetQDVers(void)
- {
- short myErr;
- long QDvers;
- #ifdef _CHK_FOR_GESTALT_
- SysEnvRec theWorld;
- #endif
-
- if (HasGestalt())
- {
- myErr = Gestalt(gestaltQuickdrawVersion, &QDvers);
- if (myErr)
- QDvers = gestaltOriginalQD; // default to original
- }
- #ifdef _CHK_FOR_GESTALT_
- else
- {
- if (!SysEnvirons(2, &theWorld))
- QDvers = theWorld.hasColorQD;
- else
- QDvers = gestaltOriginalQD; // default back to original
- }
- #endif //_CHK_FOR_GESTALT_
-
- return(QDvers);
- }
-
- /*________________________________________________________________________________
-
- ColorQDIsPresent
-
- info: Check whether Color QuickDraw is present.
-
- return: true if Color QD is available, false if not. Call GetQDVers if you
- want the actual version of Color QuickDraw in use.
- _____________________________________________________________________ */
-
- Boolean ColorQDIsPresent(void)
- {
- Boolean hasColorQD = false;
-
- if (GetQDVers() > gestaltOriginalQD) // if greater than 1, yes
- hasColorQD = true;
-
- return (hasColorQD);
- }
-
- /*________________________________________________________________________________
-
- TrapAvailable()
-
- info: Determine if a particular trap is available.
-
- entry: theTrap - the trap number to test for.
-
- return: true if the trap is available, false if not.
- ________________________________________________________________________________*/
- short TrapAvailable(short theTrap)
- {
- short theType;
- short trimTest;
-
- theType = GetTrapType(theTrap);
-
- if(theType == ToolBoxTrap)
- {
- trimTest = BitAnd(theTrap,0x07FF);
- if(trimTest > NumToolboxTraps() )
- return(false);
- }
-
- return( (NGetTrapAddress(theTrap,theType) != NGetTrapAddress(_Unimplemented,ToolTrap)) );
- }
-
- /*________________________________________________________________________________
-
- NumToolboxTraps()
-
- info: Determine the number of toolbox traps available.
-
- return: short number of traps available.
-
- ________________________________________________________________________________*/
- short NumToolboxTraps(void)
- {
- if(NGetTrapAddress(InitGrafTrap,ToolTrap)==NGetTrapAddress(0xaa6e,ToolTrap))
- return(0x200);
- else
- return(0x400);
- }
-
- /*________________________________________________________________________________
- GetTrapType()
-
- info: Given a trap address, determine if trap is OS or ToolBox trap.
-
- entry: theTrap - the trap number
-
- return: short 1 = OSTrap; 2 = ToolBoxTrap
- ________________________________________________________________________________*/
- short GetTrapType(short theTrap)
- {
- short trapType = 0;
-
- if( BitAnd(theTrap,TrapMask) > 0)
- trapType = ToolBoxTrap;
- else
- trapType = OSTrap;
-
- return(trapType);
- }
-