source/start.c

/****************************************************/
/*                                                  */
/*  File:       start.c                             */
/*                                                  */
/*  Program:    Imageer                             */
/*                                                  */
/*  By:         Jason Hodges-Harris                 */
/*                                                  */
/*  Created:    26/10/95  00:00:00 AM               */
/*                                                  */
/*  Version:    1.0.0d3                             */
/*                                                  */
/*  Copyright:  © 1995-96 Apple Computer, Inc.,     */ 
/*                  all rights reserved.            */      
/*                                                  */
/****************************************************/
 
 
/**** Macintosh Toolbox Headers *****/
 
#ifndef __CURSORCTL__
#include <CursorCtl.h>
#endif
 
#ifndef __DIALOGS__
#include <Dialogs.h>
#endif
 
#ifndef __FONTS__
#include <Fonts.h>
#endif
 
#ifndef __GESTALT__
#include <Gestalt.h>
#endif
 
#ifndef __GXENVIRONMENT__
#include <GXEnvironment.h>
#endif
 
#ifndef __GXGRAPHICS__
#include <GXGraphics.h>
#endif
 
#ifndef __GXPRINTING__
#include <GXPrinting.h>
#endif
 
#ifndef __MEMORY__
#include <Memory.h>
#endif
 
#ifndef __MENUS__
#include <Menus.h>
#endif
 
#ifndef __QDOFFSCREEN__
#include <QDOffscreen.h>
#endif
 
#ifndef __SEGLOAD__
#include <SegLoad.h>
#endif
 
#ifndef __TEXTEDIT__
#include <TextEdit.h>
#endif
 
#ifndef __WINDOWS__
#include <Windows.h>
#endif
 
 
/****   Application headers and prototypes   ****/
 
 
#ifndef __IMAGEERAPPHEADER__
#include "Imageer.app.h"
#endif
 
#ifndef __IMAGEERPROTOSHEADER__
#include "Imageer.protos.h"
#endif
 
 
/***** Global Variables *****/
 
#if !defined(THINK_C) && !defined(__MWERKS__)
    QDGlobals       qd;
#endif
long                    gTempFolderDirID,
                        gTempFileCount;
short                   gTempFolderVolRef;
short                   gNumOpenWindows;        //  number of open document windows
OSType                  gLoadFileType;
Boolean                 gDone;
Boolean                 gQDGXtrue;
 
 
/**** Initialise Gloabals ****/
 
#pragma segment Main
void InitialiseApp(void)
{
    InitCursorCtl(nil);
    gTempFileCount = 0;                         // reset unique temp file number
    gTempFolderDirID = 0;
    gTempFolderVolRef = 0;
    gNumOpenWindows = 0;                        // No open windows
    gLoadFileType = '????';                     // default to display all valid file formats
    gDone = false;
    MenuBarInit();                              // init menubar
    gQDGXtrue = TestforQuickDrawGX();           // test for QDGX 
    DoAdjustMenus();                            // Initialise menu items
    FindTempFolder();
    return;
}
 
 
/**** Test For QuickDraw GX ****/
 
#pragma segment Main
Boolean TestforQuickDrawGX(void)
{
    long    QDGXversion;
    OSErr   error = noErr;
    
    if(Gestalt('grfx',&QDGXversion) == noErr)
    {
        // check for the QuickDrawGX shared library loaded as Gestalt not always correct for weak linked libraries
        #if defined(powerc) || defined(__powerc)
            if (!GXEnterGraphics)
            {
                DisplayAlert(rGenAlert,rQDGXmessages,iGXLibNotLoaded);
                return false;
            }
        #endif
 
        GXEnterGraphics();  // initialise QuickDrawGX
        error = GXInitPrinting();
        if (error)
        {
            DisplayAlert(rGenAlert,rQDGXmessages,iFailInitPrint);
            return false;
        }
        return true;
    }
    DisplayAlert (rGenWarning,rQDGXmessages,iGXNotInstalled);
    return false;
}
 
 
/**** Main function ****/
 
#pragma segment Main
void    main(void)
{
    long    *AppSize;                       // application size 
    short   i;
    
    AppSize = (long*)(GetApplLimit());
    SetApplLimit (AppSize-32768);
 
    // This decreases the application heap by 32k, which in turn
    // increases the stack by 32k.
 
    MaxApplZone();  // Expand the heap so code segments load at the top.
    for (i=0;i<6;i++)
        MoreMasters();              // allocate more master pointers
 
    //      Initialise the toolbox
 
    InitGraf (&qd.thePort);
    InitFonts();
    InitWindows();
    InitMenus();
    TEInit();
    InitDialogs(0L);
    InitCursor();
    SplashScreen(kSplashScrDelay);  // display splash screen
    InitialiseApp();                // initialise application globals
    EventLoop();                    // Call the main event loop.
    ExitToShell();                  // Quit the application.
}