SDL  2.0
mac_support.cpp File Reference
#include <Carbon/Carbon.h>
#include <fx.h>
+ Include dependency graph for mac_support.cpp:

Go to the source code of this file.

Functions

static pascal OSErr HandleQuitMessage (const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
 
static pascal OSErr HandleReopenMessage (const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
 
static pascal OSErr HandleWildCardMessage (const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
 
OSStatus AEHandler (EventHandlerCallRef inCaller, EventRef inEvent, void *inRefcon)
 
static void HandleEvent (EventRecord *event)
 
void init_apple_message_system ()
 
void check_apple_events ()
 

Variables

FXMainWindow * g_main_window
 

Function Documentation

◆ AEHandler()

OSStatus AEHandler ( EventHandlerCallRef  inCaller,
EventRef  inEvent,
void inRefcon 
)

Definition at line 40 of file mac_support.cpp.

Referenced by init_apple_message_system().

41 {
42  Boolean release = false;
43  EventRecord eventRecord;
44  OSErr ignoreErrForThisSample;
45 
46  // Events of type kEventAppleEvent must be removed from the queue
47  // before being passed to AEProcessAppleEvent.
48  if (IsEventInQueue(GetMainEventQueue(), inEvent))
49  {
50  // RemoveEventFromQueue will release the event, which will
51  // destroy it if we don't retain it first.
52  RetainEvent(inEvent);
53  release = true;
54  RemoveEventFromQueue(GetMainEventQueue(), inEvent);
55  }
56  // Convert the event ref to the type AEProcessAppleEvent expects.
57  ConvertEventRefToEventRecord(inEvent, &eventRecord);
58  ignoreErrForThisSample = AEProcessAppleEvent(&eventRecord);
59  if (release)
60  ReleaseEvent(inEvent);
61  // This Carbon event has been handled, even if no AppleEvent handlers
62  // were installed for the Apple event.
63  return noErr;
64 }

◆ check_apple_events()

void check_apple_events ( )

Definition at line 122 of file mac_support.cpp.

Referenced by MainWindow::onMacTimeout().

123 {
124  RgnHandle cursorRgn = NULL;
125  Boolean gotEvent=TRUE;
126  EventRecord event;
127 
128  while (gotEvent) {
129  gotEvent = WaitNextEvent(everyEvent, &event, 0L/*timeout*/, cursorRgn);
130  if (gotEvent) {
131  HandleEvent(&event);
132  }
133  }
134 }
struct _cl_event * event
#define TRUE
Definition: edid-parse.c:33
#define NULL
Definition: begin_code.h:164
static void HandleEvent(EventRecord *event)
Definition: mac_support.cpp:66

◆ HandleEvent()

static void HandleEvent ( EventRecord *  event)
static

Definition at line 66 of file mac_support.cpp.

References g_main_window.

Referenced by check_apple_events().

67 {
68  //printf("What: %d message %x\n", event->what, event->message);
69  if (event->what == osEvt) {
70  if (((event->message >> 24) & 0xff) == suspendResumeMessage) {
71  if (event->message & resumeFlag) {
72  g_main_window->show();
73  }
74  }
75  }
76 
77 #if 0
78  switch (event->what)
79  {
80  case mouseDown:
81  //HandleMouseDown(event);
82  break;
83  case keyDown:
84  case autoKey:
85  //HandleKeyPress(event);
86  break;
87  case kHighLevelEvent:
88  puts("Calling ProcessAppleEvent\n");
89  AEProcessAppleEvent(event);
90  break;
91  }
92 #endif
93 }
struct _cl_event * event
FXMainWindow * g_main_window
Definition: test.cpp:98

◆ HandleQuitMessage()

static pascal OSErr HandleQuitMessage ( const AppleEvent *  theAppleEvent,
AppleEvent *  reply,
long  handlerRefcon 
)
static

Definition at line 17 of file mac_support.cpp.

Referenced by init_apple_message_system().

19 {
20  puts("Quitting\n");
21  FXApp::instance()->exit();
22  return 0;
23 }

◆ HandleReopenMessage()

static pascal OSErr HandleReopenMessage ( const AppleEvent *  theAppleEvent,
AppleEvent *  reply,
long  handlerRefcon 
)
static

Definition at line 25 of file mac_support.cpp.

References g_main_window.

Referenced by init_apple_message_system().

27 {
28  puts("Showing");
29  g_main_window->show();
30  return 0;
31 }
FXMainWindow * g_main_window
Definition: test.cpp:98

◆ HandleWildCardMessage()

static pascal OSErr HandleWildCardMessage ( const AppleEvent *  theAppleEvent,
AppleEvent *  reply,
long  handlerRefcon 
)
static

Definition at line 33 of file mac_support.cpp.

35 {
36  puts("WildCard\n");
37  return 0;
38 }

◆ init_apple_message_system()

void init_apple_message_system ( )

Definition at line 96 of file mac_support.cpp.

Referenced by MainWindow::create().

97 {
98  OSErr err;
99  static const EventTypeSpec appleEvents[] =
100  {
101  { kEventClassAppleEvent, kEventAppleEvent }
102  };
103 
104  /* Install the handler for Apple Events */
105  InstallApplicationEventHandler(NewEventHandlerUPP(AEHandler),
106  GetEventTypeCount(appleEvents), appleEvents, 0, NULL);
107 
108  /* Install handlers for the individual Apple Events that come
109  from the Dock icon: the Reopen (click), and the Quit messages. */
110  err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
111  NewAEEventHandlerUPP(HandleQuitMessage), 0, false);
112  err = AEInstallEventHandler(kCoreEventClass, kAEReopenApplication,
113  NewAEEventHandlerUPP(HandleReopenMessage), 0, false);
114 #if 0
115  // Left as an example of a wild card match.
116  err = AEInstallEventHandler(kCoreEventClass, typeWildCard,
117  NewAEEventHandlerUPP(HandleWildMessage), 0, false);
118 #endif
119 }
static pascal OSErr HandleQuitMessage(const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
Definition: mac_support.cpp:17
OSStatus AEHandler(EventHandlerCallRef inCaller, EventRef inEvent, void *inRefcon)
Definition: mac_support.cpp:40
static pascal OSErr HandleReopenMessage(const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
Definition: mac_support.cpp:25
#define NULL
Definition: begin_code.h:164

Variable Documentation

◆ g_main_window

FXMainWindow* g_main_window

Definition at line 98 of file test.cpp.

Referenced by HandleEvent(), and HandleReopenMessage().