home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-06 | 5.3 KB | 190 lines | [TEXT/CWIE] |
- // Program Author: Paul Baxter
- // pbaxter@assistivetech.com
- //
- //
- #include <Speech.h>
- #include <Ctype.h>
- #include <DeskBus.h>
- #include <Retrace.h>
-
- #include "pref.h"
- #include "globals.h"
- #include "aeevents.h"
- #include "aerecord.h"
- #include "aeutils.h"
- #include "aetoken.h"
-
- // * ****************************************************************************** *
- // * IssueQuitCommand
- // * Issue a quit command
- // * ****************************************************************************** *
- void IssueQuitCommand(void)
- {
- AppleEvent myAppleEvent;
- AppleEvent defReply;
- OSErr myErr = noErr;
- OSErr ignoreErr;
- AEAddressDesc selfAddr;
-
- if (HasAppleEvents()) {
- myAppleEvent.dataHandle = nil;
- selfAddr.dataHandle = nil;
-
- myErr = MakeSelfAddress(&selfAddr);
-
- // Build event
-
- if (myErr == noErr)
- myErr = AECreateAppleEvent(kCoreEventClass, kAEQuitApplication, &selfAddr,
- kAutoGenerateReturnID, kAnyTransactionID, &myAppleEvent);
- // send the event
-
- if (myErr==noErr)
- myErr = AESend(&myAppleEvent, &defReply, kAENoReply+kAEAlwaysInteract,
- kAENormalPriority, kAEDefaultTimeout, nil, nil);
-
- if (myAppleEvent.dataHandle)
- ignoreErr = AEDisposeDesc(&myAppleEvent);
-
- if (selfAddr.dataHandle)
- ignoreErr = AEDisposeDesc(&selfAddr);
- }
- return;
- }
-
-
- // * ****************************************************************************** *
- // * IssueSetVoice
- // * Issue an AppleEvent to change the voice
- // * ****************************************************************************** *
- OSErr IssueSetVoice(void)
- {
- AEDesc StringDesc;
- AEAddressDesc theAddress;
- OSErr err = noErr;
-
- if (HasAppleEvents()) {
- err = MakeSelfAddress(&theAddress);
- if (err==noErr)
- err = PutPStringToDescriptor(&StringDesc, (**gPrefs).voice);
-
- if (err==noErr)
- err = SendAESetAppProp(typeVoiceProperty, &StringDesc, &theAddress);
- }
- return err;
- }
-
- // * ****************************************************************************** *
- // * IssueSetSpeakChars
- // * Issue an AppleEvent to speak chars
- // * ****************************************************************************** *
- OSErr IssueSetSpeakChars(void)
- {
- AEDesc LongDesc;
- AEAddressDesc theAddress;
- OSErr err = noErr;
-
- if (HasAppleEvents()) {
- err = MakeSelfAddress(&theAddress);
- if (err==noErr)
- err = PutLongIntToDescriptor(&LongDesc, (**gPrefs).speakChars);
-
- if (err==noErr)
- err = SendAESetAppProp(typeSpeakCharProperty, &LongDesc, &theAddress);
- }
- return err;
- }
-
- // * ****************************************************************************** *
- // * IssueSetSpeakWords
- // * Issue an AppleEvent to speak words
- // * ****************************************************************************** *
- OSErr IssueSetSpeakWords(void)
- {
- AEDesc LongDesc;
- AEAddressDesc theAddress;
- OSErr err = noErr;
-
- if (HasAppleEvents()) {
- err = MakeSelfAddress(&theAddress);
- if (err==noErr)
- err = PutLongIntToDescriptor(&LongDesc, (**gPrefs).speakWords);
-
- if (err==noErr)
- err = SendAESetAppProp(typeSpeakWordProperty, &LongDesc, &theAddress);
- }
- return err;
- }
-
- // * ****************************************************************************** *
- // * IssueSetSpeakSentences
- // * Issue an AppleEvent to speak sentences
- // * ****************************************************************************** *
- OSErr IssueSetSpeakSentences(void)
- {
- AEDesc LongDesc;
- AEAddressDesc theAddress;
- OSErr err = noErr;
-
- if (HasAppleEvents()) {
- err = MakeSelfAddress(&theAddress);
- if (err==noErr)
- err = PutLongIntToDescriptor(&LongDesc, (**gPrefs).speakSentence);
-
- if (err==noErr)
- err = SendAESetAppProp(typeSpeakSentenceProperty, &LongDesc, &theAddress);
- }
- return err;
- }
-
- // * ****************************************************************************** *
- // * SendAESetAppProp
- // * Creates a property object from an object,
- // * a property type and its data and sends it to
- // * the requested address, and cleans up zapping params too
- // * ****************************************************************************** *
- OSErr SendAESetAppProp(DescType theProp, AEDesc *theData, AEAddressDesc *toWhom)
- {
- AEDesc propObjSpec;
- AEDesc nullDesc = {typeNull, NULL};
- AEDesc theObj;
- AppleEvent myAppleEvent;
- AppleEvent defReply;
- OSErr myErr;
- OSErr ignoreErr;
-
- myErr = AECreateDesc(typeType, (Ptr)&theProp, sizeof(theProp), &theObj);
-
- if (myErr==noErr)
- myErr = CreateObjSpecifier(cProperty, &nullDesc, formPropertyID,
- &theObj, true, &propObjSpec);
- if (myErr==noErr)
- myErr = AECreateAppleEvent(kAECoreSuite, kAESetData, toWhom, 0, 0, &myAppleEvent);
-
- // add prop obj spec to the event
- if (myErr==noErr)
- myErr = AEPutParamDesc(&myAppleEvent, keyDirectObject, &propObjSpec);
-
- // add prop data to the event
- if (myErr==noErr)
- myErr = AEPutParamDesc(&myAppleEvent,keyAEData, theData);
-
- // send event
- if (myErr==noErr)
- myErr = AESend(&myAppleEvent, &defReply, kAENoReply+kAEAlwaysInteract,
- kAENormalPriority, kAEDefaultTimeout, nil, nil);
-
- if (myAppleEvent.dataHandle)
- ignoreErr = AEDisposeDesc(&myAppleEvent);
-
- if (&propObjSpec.dataHandle)
- ignoreErr = AEDisposeDesc(&propObjSpec);
-
- if (theData->dataHandle)
- ignoreErr = AEDisposeDesc(theData);
-
- if (toWhom->dataHandle)
- ignoreErr = AEDisposeDesc(toWhom);
-
- return(myErr);
- }