#include <Carbon/Carbon.h>
#include <fx.h>
extern FXMainWindow *g_main_window;
static pascal OSErr HandleQuitMessage(const AppleEvent *theAppleEvent, AppleEvent
*reply, long handlerRefcon)
{
puts("Quitting\n");
FXApp::instance()->exit();
return 0;
}
static pascal OSErr HandleReopenMessage(const AppleEvent *theAppleEvent, AppleEvent
*reply, long handlerRefcon)
{
puts("Showing");
g_main_window->show();
return 0;
}
static pascal OSErr HandleWildCardMessage(const AppleEvent *theAppleEvent, AppleEvent
*reply, long handlerRefcon)
{
puts("WildCard\n");
return 0;
}
OSStatus AEHandler(EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon)
{
Boolean release = false;
EventRecord eventRecord;
OSErr ignoreErrForThisSample;
if (IsEventInQueue(GetMainEventQueue(), inEvent))
{
RetainEvent(inEvent);
release = true;
RemoveEventFromQueue(GetMainEventQueue(), inEvent);
}
ConvertEventRefToEventRecord(inEvent, &eventRecord);
ignoreErrForThisSample = AEProcessAppleEvent(&eventRecord);
if (release)
ReleaseEvent(inEvent);
return noErr;
}
static void HandleEvent(EventRecord *event)
{
if (event->what == osEvt) {
if (((event->message >> 24) & 0xff) == suspendResumeMessage) {
if (event->message & resumeFlag) {
g_main_window->show();
}
}
}
#if 0#endif
}
void
init_apple_message_system()
{
OSErr err;
static const EventTypeSpec appleEvents[] =
{
{ kEventClassAppleEvent, kEventAppleEvent }
};
InstallApplicationEventHandler(NewEventHandlerUPP(AEHandler),
GetEventTypeCount(appleEvents), appleEvents, 0, NULL);
err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
NewAEEventHandlerUPP(HandleQuitMessage), 0, false);
err = AEInstallEventHandler(kCoreEventClass, kAEReopenApplication,
NewAEEventHandlerUPP(HandleReopenMessage), 0, false);
#if 0#endif
}
void
check_apple_events()
{
RgnHandle cursorRgn = NULL;
Boolean gotEvent=TRUE;
EventRecord event;
while (gotEvent) {
gotEvent = WaitNextEvent(everyEvent, &event, 0L, cursorRgn);
if (gotEvent) {
HandleEvent(&event);
}
}
}