home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
macintosh-pascal
/
macintoshp-1.2-demos.sit.hqx
/
chap08pascal_demo
/
AppleEventsPascal.p
next >
Wrap
Text File
|
1999-04-05
|
19KB
|
727 lines
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
// AppleEventsPascal.p
// ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
//
//
// This program:
//
// • Installs handlers for the required Apple events.
//
// • Responds to the receipt of required Apple events by displaying descriptive text in
// a window opened for that purpose, and by opening simulated document windows as
// appropriate. These responses result from the user:
//
// • Double clicking on the application's icon, or selecting the icon and choosing
// Open from the Finder's File menu, thus causing the receipt of an Open
// Application event.
//
// • Double clicking on one of the document icons, selecting one or both of the
// document icons and choosing Open from the Finder's File menu, or dragging one
// or both of the document icons onto the application's icon, thus causing the
// receipt of an Open Documents event.
//
// • Selecting one or both of the document icons and choosing Print from the
// Finder's file menu, thus causing the receipt of a Print Documents event and,
// if the application was not already running, a subsequent Quit Application event.
//
// • While the application is running, choosing Shut Down or Restart from the
// Finder's Special menu, thus causing the receipt of a Quit Application event.
//
// The program, which is intended to be run as a built application and not from within
// CodeWarrior, utilises the following resources:
//
// • 'WIND' resources (purgeable) (initially visible) for the descriptive text display
// window and simulated document windows.
//
// • 'MBAR' and 'MENU' resources (preload, non-purgeable).
//
// • An 'ALRT' resource, and associated 'DITL' and 'STR#' resources, for displaying
// error messages (purgeable).
//
// • 'ICN#', 'ics#', 'ics4', 'ics8', 'icl4', and 'icl8' resources (that is, an icon
// family) for the application and for the application's documents. (Purgeable.)
//
// • 'FREF' resources for the application and the application's 'TEXT' documents, which
// link the icons with the file types they represent, and which allow users to launch
// the application by dragging the document icons to the application icon. (Non-
// purgeable.)
//
// • The application's signature resource (non-purgeable), which enables the Finder to
// identify and start up the application when the user double clicks the application's
// document icons.
//
// • A 'BNDL' resource (non-purgeable), which groups together the application's
// signature, icon and 'FREF' resources.
//
// • An 'hfdr' resource (purgeable), which provides the customised help balloon for the
// application icon.
//
// • A 'vers' resource (purgeable), which allows users to ascertain the version number
// of the application.
//
// • A 'SIZE' resource with the isHighLevelEventAware, acceptSuspendResumeEvents, and
// and is32BitCompatible flags set.
//
// ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }
program AppleEventsPascal(input, output);
{ ………………………………………………………………………………………………………………… include the following Universal Interfaces }
uses
Windows, Fonts, Menus, TextEdit, Quickdraw, Dialogs, QuickdrawText, Processes, Types,
Memory, Events, TextUtils, ToolUtils, OSUtils, Devices, AppleEvents, Errors, Files,
EPPC, Segload;
{ ………………………………………………………………………………………………………………………………………………… define the following constants }
const
mApple = 128;
mFile = 129;
iQuit = 11;
rMenubar = 128;
rDisplayWindow = 128;
rDocWindow = 129;
rErrorAlert = 128;
rErrorStrings = 128;
eInstallHandler = 1;
eGetRequiredParam = 2;
eGetDescriptorRecord = 3;
eMissedRequiredParam = 4;
eCannotOpenFile = 5;
eCannotPrintFile = 6;
eCannotOpenWindow = 7;
eMenus = 8;
{ ……………………………………………………………………………………………………………………………………………………………………………………… global variables }
var
gDone : boolean;
gWindowPtr : WindowPtr;
gWindowPtrs : array [0..10] of WindowPtr;
gNumberOfWindows : integer;
gApplicationWasOpen : boolean;
eventRec : EventRecord;
menubarHdl : Handle;
menuHdl : MenuHandle;
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoInitManagers }
procedure DoInitManagers;
begin
MaxApplZone;
MoreMasters;
InitGraf(@qd.thePort);
InitFonts;
InitWindows;
InitMenus;
TEInit;
InitDialogs(nil);
InitCursor;
FlushEvents(everyEvent, 0);
end;
{of procedure DoInitManagers}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoAppleMenu }
procedure DoAppleMenu(menuItem : integer);
var
itemName : string;
daDriverRefNum : integer;
begin
GetMenuItemText(GetMenuHandle(mApple), menuItem, itemName);
daDriverRefNum := OpenDeskAcc(itemName);
end;
{of procedure DoAppleMenu}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoFileMenu }
procedure DoFileMenu(menuItem : integer);
begin
if (menuItem = iQuit) then
gDone := true;
end;
{of procedure DoFileMenu}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMenuChoice }
procedure DoMenuChoice(menuChoice : longint);
var
menuID, menuItem : integer;
begin
menuID := HiWord(menuChoice);
menuItem := LoWord(menuChoice);
if (menuID = 0) then
Exit(DoMenuChoice);
case (menuID) of
mApple:
begin
DoAppleMenu(menuItem);
end;
mFile:
begin
DoFileMenu(menuItem);
end;
end;
{of case statement}
HiliteMenu(0);
end;
{of procedure DoMenuChoice}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoError }
procedure DoError(errorType : integer);
var
errorString : string;
ignored : OSErr;
begin
SetCursor(qd.arrow);
GetIndString(errorString, rErrorStrings, errorType);
ParamText(errorString, '', '', '');
if (errorType < 7)
then ignored := CautionAlert(rErrorAlert, nil)
else begin
ignored := StopAlert(rErrorAlert, nil);
ExitToShell;
end;
end;
{of procedure DoError}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ HasGotRequiredParams }
function HasGotRequiredParams(appEvent : AppleEvent) : OSErr;
var
returnedType : DescType;
actualSize : Size;
theErr : OSErr;
begin
theErr := AEGetAttributePtr(appEvent, keyMissedKeywordAttr, typeWildCard, returnedType,
nil, 0, actualSize);
if (theErr = errAEDescNotFound)
then HasGotRequiredParams := noErr
else if (theErr = noErr)
then HasGotRequiredParams := errAEParamMissed
else HasGotRequiredParams := noErr;
end;
{of function HasGotRequiredParams}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DrawTextString }
procedure DrawTextString(eventString : string);
var
tempRegion : RgnHandle;
begin
tempRegion := NewRgn;
ScrollRect(gWindowPtr^.portRect, 0, -15, tempRegion);
DisposeRgn(tempRegion);
MoveTo(8, 176);
DrawString(eventString);
end;
{of procedure DrawTextString}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoPrepareToTerminate }
procedure DoPrepareToTerminate;
var
finalTicks : UInt32;
begin
DrawTextString('Received an Apple event: QUIT APPLICATION');
if (gApplicationWasOpen)
then begin
DrawTextString(' • I would now ask the user to save any unsaved files');
DrawTextString(' before terminating myself in reponse to the event.');
DrawTextString(' • Click the mouse when ready to terminate.');
while not (Button) do;
end
else begin
DrawTextString(' • Terminating myself in response');
Delay(300, finalTicks);
end;
{ If the user did not click the Cancel button in a Save dialog box: }
gDone := true;
end;
{of procedure DoPrepareToTerminate}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoNewWindow }
function DoNewWindow : WindowPtr;
begin
gWindowPtrs[gNumberOfWindows] := GetNewWindow(rDocWindow, nil, WindowPtr(-1));
if (gWindowPtrs[gNumberOfWindows] = nil) then
DoError(eCannotOpenWindow);
gNumberOfWindows := gNumberOfWindows + 1;
DoNewWindow := gWindowPtrs[gNumberOfWindows - 1];
end;
{of function DoNewWindow}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoOpenFile }
function DoOpenFile(var fileSpec : FSSpec; index, numberOfItems : longint) : boolean;
var
myWindowPtr : WindowPtr;
finalTicks : UInt32;
begin
gApplicationWasOpen := true;
if (index = 1) then
DrawTextString('Received an Apple event: OPEN DOCUMENTS.');
if (numberOfItems = 1)
then begin
DrawTextString(' • The file to open is: ');
DrawString(fileSpec.name);
DrawTextString(' • Opening titled window in reponse.');
Delay(100, finalTicks);
end
else begin
if(index = 1)
then begin
DrawTextString(' • The files to open are: ');
DrawString(fileSpec.name);
end
else begin
DrawString('p and ');
DrawString(fileSpec.name);
DrawTextString(' • Opening titled windows in reponse.');
Delay(100, finalTicks);
end;
end;
myWindowPtr := DoNewWindow;
if (myWindowPtr <> nil)
then begin
SetWTitle(myWindowPtr, fileSpec.name);
DoOpenFile := true;
end
else DoOpenFile := false;
end;
{of function DoOpenFile}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoPrintFile }
function DoPrintFile(var fileSpec : FSSpec; index, numberOfItems : longint) : boolean;
var
myWindowPtr : WindowPtr;
finalTicks : UInt32;
begin
if (index = 1) then
DrawTextString('Received an Apple event: PRINT DOCUMENTS');
if (numberOfItems = 1)
then begin
DrawTextString(' • The file to print is: ');
DrawString(fileSpec.name);
myWindowPtr := DoNewWindow;
SetWTitle(myWindowPtr, fileSpec.name);
DrawTextString(' • I would present the Print dialog box first and then');
DrawTextString(' print the document when the user has made his settings.');
Delay(100, finalTicks);
DrawTextString(' • Assume that I am now printing the document.');
end
else begin
if (index = 1)
then begin
DrawTextString(' • The first file to print is: ');
DrawString(fileSpec.name);
DrawTextString(' I would present the Print dialog box for the first file');
DrawTextString(' only and use the users settings to print both files.');
end
else begin
Delay(200, finalTicks);
DrawTextString(' • The second file to print is: ');
DrawString(fileSpec.name);
DrawTextString(' I am using the Print dialog box settings used for the');
DrawTextString(' first file.');
end;
myWindowPtr := DoNewWindow;
SetWTitle(myWindowPtr, fileSpec.name);
Delay(200, finalTicks);
DrawTextString(' • Assume that I am now printing the document.');
Delay(200, finalTicks);
end;
if (numberOfItems = index) then
begin
if not (gApplicationWasOpen)
then begin
DrawTextString(' Since the application was not already open, I expect to');
DrawTextString(' receive a QUIT APPLICATION event when I have finished.');
end
else begin
DrawTextString(' Since the application was already open, I do NOT expect');
DrawTextString(' to receive a QUIT APPLICATION event when I have finished.');
end;
Delay(500, finalTicks);
DrawTextString(' • Finished print job.');
end;
DisposeWindow(myWindowPtr);
DoPrintFile := true;
end;
{of function DoPrintFiles}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoOpenAppEvent }
function DoOpenAppEvent(var appEvent, reply : AppleEvent; handlerRefCon : longint)
: OSErr;
var
theErr : OSErr;
myWindowPtr : WindowPtr;
finalTicks : UInt32;
begin
gApplicationWasOpen := true;
theErr := HasGotRequiredParams(appEvent);
if (theErr = noErr)
then begin
DrawTextString('Received an Apple event: OPEN APPLICATION.');
DrawTextString(' • Opening an untitled window in reponse.');
Delay(100, finalTicks);
myWindowPtr := DoNewWindow;
SetWTitle(myWindowPtr, 'Untitled 1');
DoOpenAppEvent := noErr;
end
else DoOpenAppEvent := theErr;
end;
{of function DoOpenAppEvent}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoOpenDocsEvent }
function DoOpenDocsEvent(var appEvent, reply : AppleEvent; handlerRefCon : longint)
: OSErr;
var
fileSpec : FSSpec;
docList : AEDescList;
theErr, ignoreErr : OSErr;
index, numberOfItems : SInt32;
actualSize : Size;
keyWord : AEKeyword;
returnedType : DescType;
result : boolean;
begin
theErr := AEGetParamDesc(appEvent, keyDirectObject, typeAEList, docList);
if (theErr = noErr)
then begin
theErr := HasGotRequiredParams(appEvent);
if (theErr = noErr)
then begin
ignoreErr := AECountItems(docList, numberOfItems);
if (theErr = noErr) then
begin
for index := 1 to numberOfItems do
begin
theErr := AEGetNthPtr(docList, index, typeFSS, keyWord, returnedType,
@fileSpec, sizeof(fileSpec), actualSize);
if (theErr = noErr)
then begin
result := DoOpenFile(fileSpec, index, numberOfItems);
if (result = false) then
DoError(eCannotOpenFile);
end
else DoError(eGetDescriptorRecord);
end;
{of for loop}
end;
end
else DoError(eMissedRequiredParam);
ignoreErr := AEDisposeDesc(docList);
end
else DoError(eGetRequiredParam);
DoOpenDocsEvent := theErr;
end;
{of DoOpenDocsEvent}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoPrintDocsEvent }
function DoPrintDocsEvent(var appEvent, reply : AppleEvent; handlerRefCon : longint)
: OSErr;
var
fileSpec : FSSpec;
docList : AEDescList;
theErr, ignoreErr : OSErr;
index, numberOfItems : longint;
actualSize : Size;
keyWord : AEKeyword;
returnedType : DescType;
result : boolean;
begin
theErr := AEGetParamDesc(appEvent, keyDirectObject, typeAEList, docList);
if (theErr = noErr)
then begin
theErr := HasGotRequiredParams(appEvent);
if (theErr = noErr)
then begin
ignoreErr := AECountItems(docList, numberOfItems);
if (theErr = noErr) then
begin
for index := 1 to numberOfItems do
begin
theErr := AEGetNthPtr(docList, index, typeFSS, keyWord, returnedType,
@fileSpec, sizeof(fileSpec), actualSize);
if (theErr = noErr)
then begin
result := DoPrintFile(fileSpec, index, numberOfItems);
if (result = false) then
DoError(eCannotPrintFile);
end
else DoError(eGetDescriptorRecord);
end;
{of for loop}
end;
end
else DoError(eMissedRequiredParam);
ignoreErr := AEDisposeDesc(docList);
end
else DoError(eGetRequiredParam);
DoPrintDocsEvent := theErr;
end;
{of function DoPrintDocsEvent}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoQuitAppEvent }
function DoQuitAppEvent(var appEvent, reply : AppleEvent; handlerRefCon : longint)
: OSErr;
var
theErr : OSErr;
begin
theErr := HasGotRequiredParams(appEvent);
if (theErr = noErr)
then begin
DoPrepareToTerminate;
DoQuitAppEvent := theErr;
end
else DoQuitAppEvent := theErr;
end;
{of function DoQuitAppEvent}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoInstallAEHandlers }
procedure DoInstallAEHandlers;
var
err : OSErr;
begin
err := AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
AEEventHandlerUPP(@DoOpenAppEvent), 0, false);
if (err <> noErr) then
DoError(eInstallHandler);
err := AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
AEEventHandlerUPP(@DoOpenDocsEvent), 0, false);
if (err <> noErr) then
DoError(eInstallHandler);
err := AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
AEEventHandlerUPP(@DoPrintDocsEvent), 0, false);
if (err <> noErr) then
DoError(eInstallHandler);
err := AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
AEEventHandlerUPP(@DoQuitAppEvent), 0, false);
if (err <> noErr) then
DoError(eInstallHandler);
end;
{of procedure DoInstallAEHandlers}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMouseDown }
procedure DoMouseDown(eventRec : EventRecord);
var
myWindowPtr : WindowPtr;
partCode : integer;
menuChoice : longint;
begin
partCode := FindWindow(eventRec.where, myWindowPtr);
case (partCode) of
inMenuBar:
begin
menuChoice := MenuSelect(eventRec.where);
DoMenuChoice(menuChoice);
end;
inSysWindow:
begin
SystemClick(eventRec, myWindowPtr);
end;
inDrag:
begin
DragWindow(myWindowPtr, eventRec.where, qd.screenBits.bounds);
end;
end;
{of case statement}
end;
{of procedure DoMouseDown}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoEvents }
procedure DoEvents(eventRec : EventRecord);
var
charCode : char;
ignored : OSErr;
begin
case (eventRec.what) of
kHighLevelEvent:
begin
ignored := AEProcessAppleEvent(eventRec);
end;
mouseDown:
begin
DoMouseDown(eventRec);
end;
keyDown, autoKey:
begin
charCode := chr(BAnd(eventRec.message, charCodeMask));
if (BAnd(eventRec.modifiers, cmdKey) <> 0) then
DoMenuChoice(MenuKey(charCode));
end;
updateEvt:
begin
BeginUpdate(WindowPtr(eventRec.message));
EndUpdate(WindowPtr(eventRec.message));
end;
osEvt:
begin
HiliteMenu(0);
end;
end;
{of case statement}
end;
{of procedure DoEvents}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ start of main program }
begin
gNumberOfWindows := 0;
gApplicationWasOpen := false;
{ …………………………………………………………………………………………………………………………………………………………………… initialize managers }
DoInitManagers;
{ …………………………………………………………………………………………………………………………………………………………………………………… open a window }
gWindowPtr := GetNewWindow(rDisplayWindow, nil, WindowPtr(-1));
if (gWindowPtr = nil) then
begin
DoError(eCannotOpenWindow);
ExitToShell;
end;
SetPort(gWindowPtr);
TextSize(10);
{ …………………………………………………………………………………………………………………………………………………… set up menu bar and menus }
menubarHdl := GetNewMBar(rMenubar);
if (menubarHdl = nil) then
DoError(eMenus);
SetMenuBar(menubarHdl);
DrawMenuBar;
menuHdl := GetMenuHandle(mApple);
if (menuHdl = nil)
then DoError(eMenus)
else AppendResMenu(menuHdl,'DRVR');
{ …………………………………………………………………………………………………………………………………………… install Apple event handlers }
DoInstallAEHandlers;
{ …………………………………………………………………………………………………………………………………………………………………………………………… event loop }
gDone := false;
while not (gDone) do
if (WaitNextEvent(everyEvent, eventRec, 180, nil)) then
DoEvents(eventRec);
end.
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }