InitMac.c

/*
    File:       InitMac.c
 
    Contains:   A simple set of routines to initialize the various
                managers ang check Gestalt for Color QuickDraw
 
    Written by: David Hayward   
 
    Copyright:  Copyright © 1994-1999 by Apple Computer, Inc., All Rights Reserved.
 
                You may incorporate this Apple sample source code into your program(s) without
                restriction. This Apple sample source code has been provided "AS IS" and the
                responsibility for its operation is yours. You are not permitted to redistribute
                this Apple sample source code as "Apple sample source code" after having made
                changes. If you're going to re-distribute the source, we require that you make
                it clear in the source that the code was descended from Apple sample source
                code, but that you've made changes.
 
    Change History (most recent first):
                7/1/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
                5/12/95                     updated project for Metrowerks
                2/27/94                     first draft
*/
 
#include <Dialogs.h>
#include <Memory.h>
#include <Windows.h>
#include <QuickDraw.h>
#include <Fonts.h>
#include <GestaltEQU.h>
#include <Traps.h>
#include <TextEdit.h>
#include <OSUtils.h>
 
#include "InitMac.h"
 
#define TrapMask 0x0800
 
 
/**\
|**| ==============================================================================
|**| GLOBALS
|**| ==============================================================================
\**/
SysEnvRec   TheWorld;
Boolean     WNE_available;
Boolean     HasGWorlds;
Boolean     HasCQD;
 
 
 
/*------------------------------------------------------------------------------*\
    NumToolboxTraps
\*------------------------------------------------------------------------------*/
short NumToolboxTraps (void)
{
    if (NGetTrapAddress(_InitGraf, ToolTrap) ==
            NGetTrapAddress(0xAA6E, ToolTrap))
        return(0x0200);
    else
        return(0x0400);
}
 
 
/*------------------------------------------------------------------------------*\
    GetTrapType
\*------------------------------------------------------------------------------*/
TrapType GetTrapType (short theTrap)
{
    if ((theTrap & TrapMask) > 0)
        return(ToolTrap);
    else
        return(OSTrap);
}
 
 
/*------------------------------------------------------------------------------*\
    TrapAvailable
\*------------------------------------------------------------------------------*/
Boolean TrapAvailable (short theTrap)
{
 
    TrapType    tType;
 
    tType = GetTrapType(theTrap);
    if (tType == ToolTrap)
        theTrap &= 0x07FF;
    if (theTrap >= NumToolboxTraps())
        theTrap = _Unimplemented;
 
    return (NGetTrapAddress(theTrap, tType) !=
            NGetTrapAddress(_Unimplemented, ToolTrap));
}
 
 
/*------------------------------------------------------------------------------*\
    WNEAvailable
\*------------------------------------------------------------------------------*/
Boolean WNEAvailable (void)
{
    return TrapAvailable(_WaitNextEvent);
}
 
 
/*------------------------------------------------------------------------------*\
    CheckQuickDraw
\*------------------------------------------------------------------------------*/
void CheckQuickDraw (void)
{
    long      QDvers;  /* Version of QuickDraw on this machine */
    
    /* Find out if GWorlds and CQD are implemented on this machine */
    Gestalt(gestaltQuickdrawVersion, &QDvers);
 
    HasGWorlds = (QDvers > gestaltOriginalQD && QDvers < gestalt8BitQD)
                  || QDvers >= gestalt32BitQD;
    
    HasCQD = (QDvers >= gestalt8BitQD);
}
 
 
/*------------------------------------------------------------------------------*\
    InitToolBox
\*------------------------------------------------------------------------------*/
void InitToolBox (short numberOfMasters)
{
    
    InitGraf((Ptr) &qd.thePort);
    InitFonts();
    InitWindows();
    InitMenus();
    InitCursor();
    TEInit();
    FlushEvents(everyEvent, 0);
    InitDialogs(nil);
    
    while(numberOfMasters--)
        MoreMasters();
        
    MaxApplZone();
    
    SysEnvirons(1,&TheWorld);
    
    WNE_available = WNEAvailable();
 
    CheckQuickDraw ();
}