Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Initialize.c
/* |
File: Initialize.c |
Contains: Initialization code for this application |
Written by: Chris White |
Copyright: Copyright © 1995-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): |
8/5/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
*/ |
#include <Dialogs.h> |
#include <Fonts.h> |
#include <Windows.h> |
#include <Menus.h> |
#include <TextEdit.h> |
#include <Events.h> |
//#include <OSEvents.h> |
#include <Gestalt.h> |
#include <SegLoad.h> |
#include <Drag.h> |
#include <CodeFragments.h> |
#ifndef __FRAGMENTTOOL__ |
#include "FragmentTool.h" |
#endif |
#ifndef __MENUSTUFF__ |
#include "MenuStuff.h" |
#endif |
#ifndef __UTILITIES__ |
#include "Utilities.h" |
#endif |
#ifndef __PROTOTYPES__ |
#include "Prototypes.h" |
#endif |
const int32 kSleepTime = 60L; |
void InitToolbox ( void ) |
{ |
InitGraf ( &qd.thePort ); |
InitFonts ( ); |
InitWindows ( ); |
InitMenus ( ); |
TEInit ( ); |
InitDialogs ( nil ); |
InitCursor ( ); |
FlushEvents ( everyEvent, 0 ); |
return; |
} |
void InitApplication ( void ) |
{ |
SetMenuBar ( GetNewMBar ( kMenuBarID ) ); |
AppendResMenu( GetMenuHandle( kAppleMenu ), 'DRVR' ); |
DrawMenuBar ( ); |
if ( !CheckConfiguration ( ) ) |
{ |
AlertUser ( kNeedSystem7, 0, nil ); |
ExitToShell ( ); |
} |
gQuit = false; // Initialize flag that controls main event loop |
// We need to get null events often enough to blink the caret correctly |
gSleepTime = (GetCaretTime ( ) < kSleepTime) ? GetCaretTime ( ) : kSleepTime; |
InitListClickLoop ( ); // Creates the UPPs (etc) for the ClickLoop |
InitDragHandlers ( ); // Creates the UPPs for the Drag Handlers |
InstallAppleEventHandlers ( ); // Installs the AE handlers for the required AE |
AdjustMenus ( ); |
// Create any other RoutineDescriptors we may need |
gOutlineUserItemUPP = NewUserItemProc ( OutlineUserItem ); |
return; |
} |
// |
// We'll limit the scope of some of our function to the current source file |
// by declairing them static. Although this has limited advantages as |
// far as encapsulation is concerned, it can make the source code a little |
// more readable. |
// |
static Boolean CheckConfiguration ( void ) |
{ |
long theResult; |
OSErr theErr; |
Boolean bHasAppleEvents, bHasFSpTraps, bHasFSpStdFile, bHasCodeFragmentManager; |
// Verify that we can run on the current configuration |
// We require AppleEvent Manager and FSSpec-based file traps and Standard File |
theErr = Gestalt ( gestaltAppleEventsAttr, &theResult ); |
bHasAppleEvents = (theErr == noErr && (theResult & (1L << gestaltAppleEventsPresent))); |
theErr = Gestalt ( gestaltFSAttr, &theResult ); |
bHasFSpTraps = (theErr == noErr && (theResult & (1L << gestaltHasFSSpecCalls))); |
theErr = Gestalt ( gestaltStandardFileAttr, &theResult ); |
bHasFSpStdFile = (theErr == noErr && (theResult & (1L << gestaltStandardFile58))); |
// Ensure CFM or CFM-68K is available |
theErr = Gestalt ( gestaltCFMAttr, &theResult ); |
bHasCodeFragmentManager = (theErr == noErr && (theResult & (1L << gestaltCFMPresent))); |
// We would also like the Drag Manager |
theErr = Gestalt ( gestaltDragMgrAttr, &theResult ); |
gHasDragManager = (theErr == noErr && (theResult & (1L << gestaltDragMgrPresent))); |
// It isn't enough to use Gestalt because we may not have sucessfully linked |
// to the DragLib shared library. So, we also need to test one of the symbols |
// against kUnresolvedSymbol to make sure we have a valid connection to it. |
// Things like memory limitations to someone having the thing open with |
// write permission could cause it to fail. |
#if GENERATINGCFM |
if ( gHasDragManager ) |
gHasDragManager = (InstallTrackingHandler != (void*) kUnresolvedCFragSymbolAddress); |
#endif |
return (bHasAppleEvents & bHasFSpTraps & bHasFSpStdFile & bHasCodeFragmentManager); |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-30