iacsysevents.c

Go to the documentation of this file.
00001 
00002 /*  $Id: iacsysevents.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 /*
00013 7/16/94 dmb: Updated for Univeral Headers, PowerPC
00014 */
00015 
00016 
00017 
00018 typedef struct tysystemhandler {
00019     
00020     AEEventClass eventclass;
00021     
00022     AEEventID id;
00023     
00024     tyAEHandler proc;
00025     
00026     long A5;
00027     
00028     THz heapzone;
00029     
00030     struct tysystemhandler **hnexthandler;
00031     } tysystemhandler, **hdlsystemhandler;
00032     
00033 
00034 hdlsystemhandler hfirstsystemhandler = nil;
00035 
00036 
00037 
00038 
00039 static pascal OSErr callhandler (const AppleEvent *event, AppleEvent *reply, long refcon) {
00040 
00041     hdlsystemhandler h = (hdlsystemhandler) refcon;
00042     THz savedzone;
00043     OSErr ec;
00044     
00045     #if !__powerc
00046         
00047         long oldA5;
00048         long appA5;
00049         
00050         appA5 = (**h).A5;
00051         
00052         oldA5 = SetA5 (appA5);
00053         
00054     #endif
00055     //Code change by Timothy Paustian Sunday, June 25, 2000 10:23:48 PM
00056     //sorta conter carbon, but that is what the boys at apple said to do.
00057     #if TARGET_API_MAC_CARBON == 1
00058     savedzone = LMGetApplZone();
00059     #else
00060     savedzone = GetZone ();
00061     #endif
00062         
00063     #if TARGET_API_MAC_CARBON == 1
00064     LMSetApplZone((**h).heapzone);
00065     #else
00066     SetZone ((**h).heapzone);
00067     #endif
00068     
00069     ec = (*(**h).proc) (event, reply, 0L);
00070     #if TARGET_API_MAC_CARBON == 1
00071     LMSetApplZone(savedzone);
00072     #else
00073     SetZone (savedzone);
00074     #endif
00075     #if !__powerc
00076         
00077         SetA5 (oldA5);
00078         
00079     #endif
00080     
00081     return (ec);
00082     } /*callhandler*/
00083 
00084 #if TARGET_API_MAC_CARBON == 1
00085 #define callhandlerUPP ((AEEventHandlerUPP) callhandler)
00086 #else       
00087 #if GENERATINGCFM
00088 
00089     static RoutineDescriptor callhandlerDesc = BUILD_ROUTINE_DESCRIPTOR (uppAEEventHandlerProcInfo, callhandler);
00090 
00091     #define callhandlerUPP (&callhandlerDesc)
00092 
00093 #else
00094     
00095     #define callhandlerUPP ((AEEventHandlerUPP) callhandler)
00096 
00097 #endif
00098 #endif
00099 
00100 Boolean IACinstallsystemhandler (AEEventClass eventclass, AEEventID id, ProcPtr handler) {
00101     
00102     OSErr ec;
00103     hdlsystemhandler h;
00104     
00105     h = (hdlsystemhandler) NewHandle ((long) sizeof (tysystemhandler));
00106     
00107     if (h == nil)
00108         return (false);
00109         
00110     (**h).eventclass = eventclass;
00111     
00112     (**h).id = id;
00113     
00114     (**h).proc = (tyAEHandler) handler;
00115     //Code change by Timothy Paustian Sunday, June 25, 2000 10:26:43 PM
00116     //This has no meaning on PPC.
00117     #if !TARGET_API_MAC_CARBON
00118     (**h).A5 = (long) LMGetCurrentA5 ();
00119     #endif
00120 
00121     #if TARGET_API_MAC_CARBON == 1
00122     (**h).heapzone = LMGetApplZone();
00123     #else   
00124     (**h).heapzone = GetZone ();
00125     #endif
00126     
00127     ec = AEInstallEventHandler (eventclass, id, callhandlerUPP, (long) h, true);
00128     
00129     IACglobals.errorcode = ec;
00130 
00131     if (ec != noErr) {
00132         
00133         DisposeHandle ((Handle) h);
00134         
00135         return (false);
00136         }
00137         
00138     (**h).hnexthandler = hfirstsystemhandler;
00139     
00140     hfirstsystemhandler = h;
00141     
00142     return (true);
00143     } /*IACinstallsystemhandler*/
00144     
00145     
00146 Boolean IACremovesystemhandler (AEEventClass eventclass, AEEventID id, ProcPtr handler) {
00147 #pragma unused(handler)
00148 
00149     hdlsystemhandler h = hfirstsystemhandler;
00150     hdlsystemhandler hprev = nil;
00151     OSErr ec;
00152     
00153     while (h != nil) {
00154         
00155         if (((**h).eventclass == eventclass) && ((**h).id == id)) {
00156             
00157             ec = AERemoveEventHandler (eventclass, id, callhandlerUPP, true);
00158             
00159             if (hprev == nil)
00160                 hfirstsystemhandler = (**h).hnexthandler;
00161             else
00162                 (**hprev).hnexthandler = (**h).hnexthandler;
00163                 
00164             DisposeHandle ((Handle) h);
00165             
00166             return (true);
00167             }
00168         
00169         hprev = h;
00170         
00171         h = (**h).hnexthandler;
00172         } /*while*/
00173         
00174     return (false);
00175     } /*IACremovesystemhandler*/
00176     
00177     
00178 void IACremovesystemhandlers (void) {
00179     
00180     /*
00181     remove all system event handlers that were installed by this application.
00182     
00183     3/4/93 DW: make it possible for this routine to be called two or more times.
00184     */
00185     
00186     hdlsystemhandler h = hfirstsystemhandler;
00187     hdlsystemhandler hnext;
00188     OSErr ec;
00189     
00190     while (h != nil) {
00191         
00192         ec = AERemoveEventHandler ((**h).eventclass, (**h).id, callhandlerUPP, true);
00193         
00194         IACglobals.errorcode = ec;
00195         
00196         hnext = (**h).hnexthandler;
00197         
00198         DisposeHandle ((Handle) h);
00199         
00200         h = hnext;
00201         } /*while*/
00202         
00203     hfirstsystemhandler = nil; /*3/4/93*/
00204     } /*IACremovesystemhandlers*/
00205     
00206     

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