iacapps.c

Go to the documentation of this file.
00001 
00002 /*  $Id: iacapps.c 1198 2006-04-05 22:03:52Z karstenw $    */
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 #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
00013     #include "aeutils.h"  /*PBS 03/14/02: AE OS X fix.*/
00014 #endif
00015 
00016 /*
00017 8/24/92 DW: The routines in this file are usually only needed in double-
00018 clickable applications.
00019 
00020 7/19/94 dmb: Added IACwaitroutineUPP for Universal Headers / PowerPC 
00021 compatibility
00022 */
00023 
00024 #define typeTargetID 'targ'
00025 
00026 OSErr IACdrivefilelist (tyFScallback handlespecroutine) {
00027     
00028     /*
00029     the opendoc and printdoc required events take a list of filespecs as a 
00030     parameter. we factor out the common code, and make it a little easier for an
00031     application to handle these events.
00032     
00033     you supply a callback routine that handles a single filespec, you could
00034     print it or open it, depending on which of the required events is being
00035     invoked.
00036     */
00037 
00038     AEDesc desc;
00039     long ctfiles;
00040     DescType actualtype;
00041     long actualsize;
00042     AEKeyword actualkeyword;
00043     FSSpec fs;
00044     long i;
00045     OSErr ec;
00046                         
00047     ec = AEGetKeyDesc (IACglobals.event, keyDirectObject, typeAEList, &desc);
00048     
00049     IACglobals.errorcode = ec;
00050     
00051     if (ec != noErr) 
00052         return (ec);
00053         
00054     ec = AECountItems (&desc, &ctfiles);
00055     
00056     IACglobals.errorcode = ec;
00057     
00058     if (ec != noErr) 
00059         return (ec);
00060                 
00061     for (i = 1; i <= ctfiles; i ++) {
00062     
00063         ec = AEGetNthPtr (
00064             &desc, i, typeFSS, &actualkeyword, &actualtype, 
00065             
00066             (Ptr) &fs, sizeof (fs), &actualsize);
00067                             
00068         IACglobals.errorcode = ec;
00069     
00070         if (ec != noErr) {
00071         
00072             AEDisposeDesc (&desc);
00073             
00074             return (ec);
00075             }
00076             
00077         if (!(*handlespecroutine) (&fs))
00078             return (-1);
00079         } /*for*/
00080         
00081     return (noErr);
00082     } /*IACdrivefilelist*/
00083 
00084 
00085 static OSType IACgetprocesscreator (void) {
00086     
00087     /*
00088     get the 4-character creator identifier for the application we're running 
00089     inside of.
00090     */
00091     
00092     ProcessSerialNumber psn;
00093     ProcessInfoRec info;
00094     
00095     GetCurrentProcess (&psn);
00096     
00097     info.processInfoLength = (long) sizeof (info);
00098     
00099     info.processName = nil;
00100     
00101     info.processAppSpec = nil;
00102     
00103     //Code check by Timothy Paustian Tuesday, April 25, 2000 10:18:44 PM
00104     //This call should be OK, it is not accessing any forbidden fields
00105     GetProcessInformation (&psn, &info);
00106     
00107     return (info.processSignature);
00108     } /*IACgetprocesscreator*/
00109     
00110     
00111 static pascal OSErr CoerceTargetIDToType (DescType typecode, Ptr dataptr, Size datasize, DescType totype, long refcon, AEDesc *result) {
00112     
00113     #pragma unused (typecode, datasize, totype)
00114     
00115     TargetID target;
00116     Ptr addressoftype;
00117     
00118     #if !TARGET_API_MAC_CARBON
00119     ProcessSerialNumber psn;
00120     ProcessInfoRec info;
00121     OSErr ec;
00122     #endif
00123     
00124     BlockMove (dataptr, &target, sizeof (target));
00125     
00126     //Code change by Timothy Paustian Sunday, June 25, 2000 10:08:45 PM
00127     //This is a bit of a hack but should work. We will just get stuff directly out of
00128     //the target rec. I hope this works. Maybe this never gets called in carbon.
00129     #if !TARGET_API_MAC_CARBON
00130     if (target.location.locationKindSelector == ppcNoLocation) { /*local program*/
00131         
00132         ec = GetProcessSerialNumberFromPortName (&target.name, &psn);
00133         
00134         if (ec != noErr)
00135             return (ec);
00136         
00137         info.processInfoLength = (long) sizeof (info);
00138         
00139         info.processName = nil;
00140         
00141         info.processAppSpec = nil;
00142         
00143         //Code check by Timothy Paustian Tuesday, April 25, 2000 10:20:35 PM
00144         //I think this call is OK, but not sure.
00145         ec = GetProcessInformation (&psn, &info);
00146         
00147         if (ec != noErr)
00148             return (ec);
00149             
00150         addressoftype = (Ptr) &info.processSignature;
00151         }
00152         
00153     else { /*not a local program*/
00154     #endif
00155         
00156         if (target.name.portKindSelector == ppcByCreatorAndType)
00157             addressoftype = (Ptr) &target.name.u.port.portCreator;
00158         else
00159             addressoftype = ((Ptr) &target.name.u.portTypeStr) + 1; /*kloooge*/
00160     
00161     #if !TARGET_API_MAC_CARBON
00162     }
00163     #endif
00164 
00165         
00166     (*result).descriptorType = typeType;
00167     
00168     #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
00169     
00170         return (putdescdatapointer (result, typeType, addressoftype, 4));
00171     
00172     #else
00173     
00174         return (PtrToHand (addressoftype, &(*result).dataHandle, 4));
00175     
00176     #endif
00177     } /*CoerceTargetIDToType*/
00178     
00179     
00180 static pascal OSErr CoercePSNToType (DescType typecode, Ptr dataptr, Size datasize, DescType totype, long refcon, AEDesc *result) {
00181     
00182     #pragma unused (typecode, datasize, totype, refcon)
00183     
00184     ProcessInfoRec info;
00185     OSErr ec;
00186     
00187     info.processInfoLength = (long) sizeof (info);
00188     
00189     info.processName = nil;
00190     
00191     info.processAppSpec = nil;
00192     
00193     //Code check by Timothy Paustian Tuesday, April 25, 2000 10:22:33 PM
00194     //somewhat of a dangerous call, This routine assumed the dataptr coming in
00195     //is a ProcessSerialNumber, only accesses the signature so OK.
00196     ec = GetProcessInformation ((ProcessSerialNumber *) dataptr, &info);
00197     
00198     if (ec != noErr)
00199         return (ec);
00200         
00201     (*result).descriptorType = typeType;
00202     
00203     #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/
00204     
00205         return (putdescdatapointer (result, typeType, &info.processSignature, 4));
00206     
00207     #else
00208     
00209         return (PtrToHand (&info.processSignature, &(*result).dataHandle, 4));
00210     
00211     #endif
00212     } /*CoercePSNToType*/
00213 
00214 
00215 Boolean IACinit (void) {
00216     
00217     /*
00218     returns true if the machine we're running on has Apple events, and if we are
00219     able to install our coercion handlers. it may do more in future versions.
00220     
00221     call this routine before using any of the other iac.c routines. disable your
00222     Apple event support if we return false.
00223     
00224     8/23/92 DW: only initialize once, no matter how many times we're called.
00225     */
00226     
00227     static Boolean fl = false; 
00228     
00229     if (fl) 
00230         return (true);
00231         
00232     fl = true;
00233     
00234     if (!IAChaveappleevents ())
00235         return (false);
00236         
00237     if (!IACinstallcoercionhandler (typeProcessSerialNumber, typeType, (ProcPtr) &CoercePSNToType))
00238         return (false);
00239         
00240     if (!IACinstallcoercionhandler (typeTargetID, typeType, (ProcPtr) &CoerceTargetIDToType))
00241         return (false);
00242     
00243     #if TARGET_API_MAC_CARBON == 1
00244     
00245         IACwaitroutineUPP = NewAEIdleUPP ((AEIdleProcPtr) &IACwaitroutine);
00246     
00247     #else
00248 
00249         IACwaitroutineUPP = NewAEIdleProc (IACwaitroutine);
00250     
00251     #endif
00252     
00253     IACglobals.idprocess = IACgetprocesscreator ();
00254 
00255     IACglobals.waitroutine = nil;
00256     
00257     IACglobals.nextparamoptional = false;
00258         
00259     return (true);
00260     } /*IACinit*/
00261     
00262     
00263 Boolean IAChaveappleevents (void) {
00264 
00265     /*
00266     return true if Apple Events are available.
00267     */
00268     
00269     long lGestaltAppleEventsPresent;
00270     
00271     if (Gestalt (gestaltAppleEventsAttr, &lGestaltAppleEventsPresent) != noErr)
00272         return (false);
00273     
00274     return (lGestaltAppleEventsPresent != 0);
00275     } /*IAChaveappleevents*/
00276 
00277 
00278     
00279     
00280 

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