+pascal void __wxterminate(void)
+{
+ wxStAppResource::CloseSharedLibraryResource() ;
+ __terminate() ;
+}
+
+#endif /* WXMAKINGDLL && !__DARWIN__ */
+
+int WXDLLEXPORT wxEntryStart( int argc, char *argv[] )
+{
+ return wxApp::Initialize();
+}
+
+int WXDLLEXPORT wxEntryInitGui()
+{
+ return wxTheApp->OnInitGui();
+}
+
+void WXDLLEXPORT wxEntryCleanup()
+{
+ wxApp::CleanUp();
+}
+
+int wxEntry( int argc, char *argv[] , bool enterLoop )
+{
+#ifdef __MWERKS__
+#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
+ // This seems to be necessary since there are 'rogue'
+ // objects present at this point (perhaps global objects?)
+ // Setting a checkpoint will ignore them as far as the
+ // memory checking facility is concerned.
+ // Of course you may argue that memory allocated in globals should be
+ // checked, but this is a reasonable compromise.
+ wxDebugContext::SetCheckpoint();
+#endif
+#endif
+ if (!wxEntryStart(argc, argv)) {
+ return 0;
+ }
+ // create the application object or ensure that one already exists
+ if (!wxTheApp)
+ {
+ // The app may have declared a global application object, but we recommend
+ // the IMPLEMENT_APP macro is used instead, which sets an initializer
+ // function for delayed, dynamic app object construction.
+ wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
+ wxT("No initializer - use IMPLEMENT_APP macro.") );
+
+ wxTheApp = (wxApp*) (*wxApp::GetInitializerFunction()) ();
+ }
+
+ wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
+
+#ifdef __DARWIN__
+ // Mac OS X passes a process serial number command line argument when
+ // the application is launched from the Finder. This argument must be
+ // removed from the command line arguments before being handled by the
+ // application (otherwise applications would need to handle it)
+
+ if (argc > 1) {
+ char theArg[6] = "";
+ strncpy(theArg, argv[1], 5);
+
+ if (strcmp(theArg, "-psn_") == 0) {
+ // assume the argument is always the only one and remove it
+ --argc;
+ }
+ }
+#else
+ argc = 0 ; // currently we don't support files as parameters
+#endif
+ // we could try to get the open apple events here to adjust argc and argv better
+
+ wxTheApp->argc = argc;
+ wxTheApp->argv = argv;
+
+ // GUI-specific initialization, such as creating an app context.
+ wxEntryInitGui();
+
+ // Here frames insert themselves automatically
+ // into wxTopLevelWindows by getting created
+ // in OnInit().
+
+ int retValue = 0;
+
+ if ( wxTheApp->OnInit() )
+ {
+ if ( enterLoop )
+ {
+ retValue = wxTheApp->OnRun();
+ }
+ else
+ // We want to initialize, but not run or exit immediately.
+ return 1;
+ }
+ //else: app initialization failed, so we skipped OnRun()
+
+ wxWindow *topWindow = wxTheApp->GetTopWindow();
+ if ( topWindow )
+ {
+ // Forcibly delete the window.
+ if ( topWindow->IsKindOf(CLASSINFO(wxFrame)) ||
+ topWindow->IsKindOf(CLASSINFO(wxDialog)) )
+ {
+ topWindow->Close(TRUE);
+ wxTheApp->DeletePendingObjects();
+ }
+ else
+ {
+ delete topWindow;
+ wxTheApp->SetTopWindow(NULL);
+ }
+ }
+
+ wxTheApp->OnExit();
+
+ wxEntryCleanup();
+
+ return retValue;
+}
+
+#if TARGET_CARBON
+
+bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec)
+{
+ bool converted = ConvertEventRefToEventRecord( event,rec) ;
+ OSStatus err = noErr ;
+ if ( !converted )
+ {
+ switch( GetEventClass( event ) )
+ {
+ case kEventClassKeyboard :
+ {
+ converted = true ;
+ switch( GetEventKind(event) )
+ {
+ case kEventRawKeyDown :
+ rec->what = keyDown ;
+ break ;
+ case kEventRawKeyRepeat :
+ rec->what = autoKey ;
+ break ;
+ case kEventRawKeyUp :
+ rec->what = keyUp ;
+ break ;
+ case kEventRawKeyModifiersChanged :
+ rec->what = nullEvent ;
+ break ;
+ default :
+ converted = false ;
+ break ;
+ }
+ if ( converted )
+ {
+ UInt32 keyCode ;
+ unsigned char charCode ;
+ UInt32 modifiers ;
+ GetMouse( &rec->where) ;
+
+ err = GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers);
+ err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode);
+ err = GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode);
+ rec->modifiers = modifiers ;
+ rec->message = (keyCode << 8 ) + charCode ;
+ }
+ }
+ break ;
+ case kEventClassTextInput :
+ {
+ switch( GetEventKind( event ) )
+ {
+ case kEventTextInputUnicodeForKeyEvent :
+ {
+ EventRef rawEvent ;
+ err = GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ;
+ converted = true ;
+ {
+ UInt32 keyCode ;
+ unsigned char charCode ;
+ UInt32 modifiers ;
+ GetMouse( &rec->where) ;
+ rec->what = keyDown ;
+ err = GetEventParameter(rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers);
+ err = GetEventParameter(rawEvent, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode);
+ err = GetEventParameter(rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode);
+ rec->modifiers = modifiers ;
+ rec->message = (keyCode << 8 ) + charCode ;
+ }
+ }
+ break ;
+ default :
+ break ;
+ }
+ }
+ break ;
+ }
+ }
+
+ return converted ;
+}
+
+pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+
+ EventRecord rec ;
+ switch ( GetEventClass( event ) )
+ {
+ case kEventClassKeyboard :
+ if ( wxMacConvertEventToRecord( event , &rec ) )
+ {
+ wxTheApp->MacHandleOneEvent( &rec ) ;
+ result = noErr ;
+ }
+ break ;
+ case kEventClassTextInput :
+ if ( wxMacConvertEventToRecord( event , &rec ) )
+ {
+ wxTheApp->MacHandleOneEvent( &rec ) ;
+ result = noErr ;
+ }
+ break ;
+ default :
+ break ;
+ }
+ return result ;
+}
+
+#endif