iacsend.c

Go to the documentation of this file.
00001 
00002 /*  $Id: iacsend.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include "frontier.h"
00008 #include "standard.h"
00009 
00010 #include "iacinternal.h"
00011 
00012 #undef useA4
00013 
00014 #if !__powerc
00015 
00016     #ifdef THINK_C
00017     
00018         #if __option (a4_globals)
00019             #define useA4 1
00020         #endif
00021     
00022         #define PrepareCallback() RememberA4() 
00023         #define EnterCallback() SetUpA4()
00024         #define ExitCallback() RestoreA4()
00025         
00026     #endif
00027 
00028     #ifdef __MWERKS__
00029     
00030         #if !__A5__
00031             #define useA4 1
00032         #endif
00033     
00034     #endif
00035 
00036 #endif
00037 
00038 #if useA4
00039 
00040     #include <SetupA4.h>
00041 
00042 #endif
00043 
00044 
00045 
00046 /*
00047 8/24/92 DW: This file includes routines that are likely to be used by code 
00048 that sends Apple Events.
00049 
00050 6/6/93 JWB: Change #ifdef coderesource instances to #if __option (a4_globals)
00051 to make this automatic.
00052             Change a4IACwaitroutine () to forward the value returned by
00053             IACwaitroutine ()
00054 
00055 7/16/94 dmb: Updated for Univeral Headers, PowerPC.
00056 1/15/96 dmb: Updated for current CW SetupA4.h
00057 */
00058 
00059 
00060 Boolean IACnewverb (OSType receiver, OSType vclass, OSType vtoken, AppleEvent *event) {
00061 
00062     /*
00063     create a new AppleEvent record addressed to the recipient, of the indicated class,
00064     with the indicated token identifier. return true if it worked, false otherwise.
00065     */
00066     
00067     AEAddressDesc adr; 
00068     OSErr errcode;
00069     
00070     AECreateDesc (typeApplSignature, (Ptr) &receiver, sizeof (receiver), &adr);
00071     
00072     errcode = AECreateAppleEvent (vclass, vtoken, &adr, kAutoGenerateReturnID, kAnyTransactionID, event);
00073     
00074     AEDisposeDesc (&adr);
00075     
00076     IACglobals.errorcode = errcode;
00077     
00078     return (errcode == noErr);
00079     } /*IACnewverb*/
00080 
00081 
00082 #if useA4
00083 
00084     static pascal short a4IACwaitroutine (EventRecord *ev, long *sleep, RgnHandle *mousergn) {
00085         
00086         short result;
00087         
00088         EnterCallback ();
00089         
00090         result = IACwaitroutine (ev, sleep, mousergn);
00091         
00092         ExitCallback ();
00093         
00094         return (result);
00095         } /*a4IACwaitroutine*/
00096     
00097     #if GENERATINGCFM
00098         
00099         static RoutineDescriptor a4IACwaitroutineDesc = BUILD_ROUTINE_DESCRIPTOR (uppAEIdleProcInfo, a4IACwaitroutine);
00100         
00101         #define a4IACwaitroutineUPP (&a4IACwaitroutineDesc)
00102         
00103     #else
00104         
00105         #define a4IACwaitroutineUPP ((AEIdleUPP) a4IACwaitroutine)
00106     
00107     #endif
00108 
00109 #endif
00110 
00111 
00112 Boolean IACsendverb (AppleEvent *event, AppleEvent *reply) {
00113 
00114     /*
00115     caller must dispose of the reply.
00116     */
00117 
00118     register OSErr ec;
00119     long mode;
00120     
00121     mode = kAEWaitReply + kAECanInteract + kAECanSwitchLayer;
00122     
00123     #if useA4
00124     
00125         PrepareCallback ();
00126         
00127         ec = AESend (
00128             
00129             event, reply, mode, kAENormalPriority, kNoTimeOut, 
00130             
00131             a4IACwaitroutineUPP, nil);
00132         
00133     #else
00134     
00135         //Code change by Timothy Paustian Friday, July 28, 2000 1:16:49 PM
00136         //Note that the IACwaitroutineUPP is initialized in iacapps line 218
00137         ec = AESend (
00138             
00139             event, reply, mode, kAENormalPriority, kNoTimeOut, 
00140             
00141             IACwaitroutineUPP, nil);
00142         
00143     #endif
00144     
00145     AEDisposeDesc (event);  
00146     
00147     IACglobals.errorcode = ec;
00148     
00149     return (ec == noErr);
00150     } /*IACsendverb*/
00151 
00152 
00153 Boolean IACsendverbnoreply (AppleEvent *event, AppleEvent *reply) {
00154 
00155     OSErr ec;
00156     long mode;
00157  
00158     mode = kAENoReply + kAENeverInteract;
00159  
00160     ec = AESend (event, reply, mode, kAEHighPriority, kNoTimeOut, nil, nil);
00161  
00162     AEDisposeDesc (event); 
00163  
00164     IACglobals.errorcode = ec;
00165     
00166     return (ec == noErr);
00167     } /*IACsendverbnoreply*/
00168 
00169 
00170 Boolean IACiserrorreply (Str255 errorstring) {
00171     
00172     /*
00173     return true if the reply is an error -- if so it has an 'errn' value
00174     and an 'errs' value. if we return false, the reply is not an error.
00175     */
00176     
00177     OSErr ec;
00178     AEDesc desc;
00179     
00180     ec = AEGetParamDesc (IACglobals.reply, (AEKeyword) 'errn', 'shor', &desc);
00181     
00182     if (ec != noErr) /*the reply isn't an error*/
00183         return (false);
00184 
00185     AEDisposeDesc (&desc);
00186     
00187     ec = AEGetParamDesc (IACglobals.reply, (AEKeyword) 'errs', 'TEXT', &desc);
00188     
00189     if (ec != noErr)
00190         IACcopystring ("\pUnknown error.", errorstring);
00191     else {
00192     
00193         #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
00194         
00195             long lenstring = AEGetDescDataSize (&desc);
00196             
00197         #else
00198         
00199             long lenstring = GetHandleSize (desc.dataHandle);
00200         
00201         #endif
00202         
00203         if (lenstring > 255)
00204             lenstring = 255;
00205             
00206         errorstring [0] = (char) lenstring;
00207         //Code change by Timothy Paustian Saturday, May 20, 2000 2:12:15 PM
00208         //Changed to Opaque call for Carbon
00209         //This has not been tested.
00210         #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00211         {
00212         Size dataSize = AEGetDescDataSize(&desc);
00213         Ptr theData = NewPtr(dataSize);
00214         AEGetDescData(&desc, theData, dataSize);
00215         BlockMove (theData, &errorstring [1], lenstring);
00216         DisposePtr(theData);
00217         }
00218         #else
00219         BlockMove (*desc.dataHandle, &errorstring [1], lenstring);
00220         #endif
00221         }
00222     
00223     AEDisposeDesc (&desc);
00224     
00225     return (true); /*there was an error returned*/
00226     } /*IACiserrorreply*/
00227 
00228 
00229 Boolean IACdisposeverb (AppleEvent *event) {
00230     
00231     IACglobals.errorcode = AEDisposeDesc (event);
00232 
00233     return (IACglobals.errorcode == noErr);
00234     } /*IACdisposeverb*/
00235     
00236     
00237 

Generated on Wed May 31 18:19:48 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6