static void Install(void) { short err=0; err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, NewAEEventHandlerUPP(OpenApplicationStuff), 0, 0); err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(OpenFinderDoc), 0, 0); err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, NewAEEventHandlerUPP(DoNothing), 0, 0); err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(SetUpQuitMessage), 0, 0); err = AEInstallEventHandler('PLT ', 'cmdl', NewAEEventHandlerUPP(CmdLineMessage), 0, 0); }
void unicorn::Application::init() { #ifdef Q_OS_MAC addLibraryPath( applicationDirPath() + "/../plugins" ); #elif defined Q_OS_WIN addLibraryPath( applicationDirPath() + "/plugins" ); #endif #ifdef Q_WS_MAC qt_mac_set_menubar_icons( false ); #endif CoreApplication::init(); setupHotKeys(); #ifdef __APPLE__ setGetURLEventHandler(); AEEventHandlerUPP urlHandler = NewAEEventHandlerUPP( appleEventHandler ); AEInstallEventHandler( kInternetEventClass, kAEGetURL, urlHandler, 0, false ); setOpenApplicationEventHandler(); AEEventHandlerUPP openHandler = NewAEEventHandlerUPP( appleEventHandler ); AEInstallEventHandler( kCoreEventClass, kAEReopenApplication, openHandler, 0, false ); #endif #ifdef Q_WS_MAC #define CSS_PATH "/../Resources/" #else #define CSS_PATH "/" #endif refreshStyleSheet(); translate(); m_icm = new lastfm::InternetConnectionMonitor( this ); connect( m_icm, SIGNAL( up( QString ) ), this, SIGNAL( internetConnectionUp() ) ); connect( m_icm, SIGNAL( down( QString ) ), this, SIGNAL( internetConnectionDown() ) ); connect( &m_bus, SIGNAL( wizardRunningQuery( QString )), SLOT( onWizardRunningQuery( QString ))); connect( &m_bus, SIGNAL( sessionQuery( QString )), SLOT( onBusSessionQuery( QString ))); connect( &m_bus, SIGNAL( sessionChanged( const QMap<QString, QString>& )), SLOT( onBusSessionChanged( const QMap<QString, QString>& ))); connect( &m_bus, SIGNAL( lovedStateChanged(bool)), SIGNAL( busLovedStateChanged(bool))); m_bus.board(); #ifdef __APPLE__ setQuitOnLastWindowClosed( false ); #endif }
/* * If we got no arguments install the apple event handlers and our event loop. */ void LauncherSetup_md(int argc) { OSErr err; AEEventHandlerUPP openDocEventHandler; AEEventHandlerUPP openAppEventHandler; char **argv = NULL; int no = 0; // If we got more than one argument we were launched from the commandline, // so don't install any handlers. if (argc > 1) return; if (gInitialized) return; gInitialized = true; // We need to handle open events for the functionality we're looking for. openDocEventHandler = NewAEEventHandlerUPP((AEEventHandlerProcPtr)OpenDocEventHandler); openAppEventHandler = NewAEEventHandlerUPP((AEEventHandlerProcPtr)OpenAppEventHandler); err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, openDocEventHandler, 0, TRUE); if(err) { fprintf(stderr, "Error installing open event handler\n"); exit(-1); } err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, openAppEventHandler, 0, TRUE); if(err) { fprintf(stderr, "Error installing open app handler\n"); exit(-1); } // Enter the event loop and handle appleevents. If we were given files to open // they will appear here. RunApplicationEventLoop(); if (gRunAppManager) { // Three arguments -- app name, no file, and null. argv = (char**)malloc(sizeof(char*) * 3); no = 0; argv[no++] = GetWebStartAppName(); argv[no] = NULL; // Call into our main app. main(no, argv); } else { exit(0); } }
// -------------------------------------------------------------------------------------- static pascal OSErr openApplicationAEHandler(const AppleEvent *appleEvent, AppleEvent *reply, long refcon) { #pragma unused (reply, refcon) OSErr error; DescType returnedType; Size actualSize; error = AEGetAttributePtr(appleEvent, keyMissedKeywordAttr, typeWildCard, &returnedType, NULL, 0, &actualSize); if (error == noErr) error = errAEParamMissed; else if (error == errAEDescNotFound) { EventTypeSpec applicationEvents[] = { {kEventClassCommand, kEventCommandProcess} }; /* For our program running in Carbon, a Quit Application Apple Event handler is unnecessary because RunApplicationEventLoop installs one for us that calls QuitApplicationEventLoop. However we will leave ours here in case we ever need it to do something different so that we know where it belongs. */ gQuitAppAEHandler = NewAEEventHandlerUPP(quitApplicationAEHandler); error = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, gQuitAppAEHandler, 0, false); if (error != noErr) // if we can't allow the user a mechanism to quit { // we'd better just quit right now DisposeAEEventHandlerUPP(gOpenAppAEHandler); DisposeAEEventHandlerUPP(gQuitAppAEHandler); ExitToShell(); } gViewsFontChangedAEHandler = NewAEEventHandlerUPP(viewsFontChangedAEHandler); error = AEInstallEventHandler(kAppearanceEventClass, kAEViewsFontChanged, gViewsFontChangedAEHandler, 0, false); gAppEventHandler = NewEventHandlerUPP(appEventHandler); InstallApplicationEventHandler(gAppEventHandler, GetEventTypeCount(applicationEvents), applicationEvents, NULL, NULL); Gestalt(gestaltSystemVersion, &gMacOSVersion); // get the version of Mac OS we're // running on InitIconDataBrowser(); error = noErr; } return error; }
Boolean IACremovehandler (AEEventClass eventclass, AEEventID id, ProcPtr handler) { OSErr ec; #if TARGET_RT_MAC_CFM #if TARGET_API_MAC_CARBON == 1 AEEventHandlerUPP theHandler = NewAEEventHandlerUPP(handler); ec = AERemoveEventHandler (eventclass, id, theHandler, false); DisposeAEEventHandlerUPP(theHandler); #else long refcon; ec = AEGetEventHandler (eventclass, id, (AEEventHandlerUPP *) &handler, &refcon, false); if (ec == noErr) ec = AERemoveEventHandler (eventclass, id, (AEEventHandlerUPP) handler, false); #endif//TARGET_API_MAC_CARBON == 0 #else ec = AERemoveEventHandler (eventclass, id, (AEEventHandlerUPP) handler, false); #endif//end TARGET_RT_MAC_CFM IACglobals.errorcode = ec; return (ec == noErr); } /*IACremovehandler*/
void setUp() { Handle menuBar; OSErr anErr = noErr; long aLong; long response; anErr = Gestalt(gestaltSystemVersion, &response); // Carbon Porting guidelines say provide alternate menu bar/menu scheme for OS X // This is just one way of doing this, which is pretty static if (response >= 0x01000) menuBar = GetNewMBar(MENU_BAR_IDX); else menuBar = GetNewMBar(MENU_BAR_ID); if ( menuBar == nil || anErr != noErr ) ExitToShell(); SetMenuBar(menuBar); DisposeHandle(menuBar); DrawMenuBar(); // Install 'quit' event handler if ((Gestalt(gestaltAppleEventsAttr, &aLong) == noErr)) { anErr = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(AEQuitHandler), 0, false); if (anErr != noErr) ExitToShell(); } }
// -------------------------------------------------------------------------------------- static void initialize(void) { OSStatus status; IBNibRef nib; OSErr error; RegisterAppearanceClient(); status = CreateNibReference(CFSTR("ExamplePrefs"), &nib); if (status != noErr) ExitToShell(); status = SetMenuBarFromNib(nib, CFSTR("MenuBar")); if (status != noErr) ExitToShell(); DisposeNibReference(nib); DrawMenuBar(); // do non time sensitive initialization after we get the application event loop going gOpenAppAEHandler = NewAEEventHandlerUPP(openApplicationAEHandler); error = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, gOpenAppAEHandler, 0, false); if (error != noErr) ExitToShell(); /* If we supported them, we would install open documents and print documents handlers here and we would do most of the same initialization stuff that we do in the open application handler */ }
bool installAEHandlers() { OSErr iErr = noErr; g_lpfnAEProc = NewAEEventHandlerUPP(aplEventHdlr); if (noErr != (iErr = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, g_lpfnAEProc, FOUR_CHAR_CODE('QUIT'), FALSE))) { DisposeAEEventHandlerUPP(g_lpfnAEProc); fprintf(stderr, "installAEHandlers() - AEInstallEventHandler(kAEQuitApplication) failed, returning %lu!\n", (unsigned long) iErr); return false; } if (noErr != (iErr = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, g_lpfnAEProc, FOUR_CHAR_CODE('OPEN'), FALSE))) { AERemoveEventHandler(kCoreEventClass, kAEQuitApplication, g_lpfnAEProc, FALSE); DisposeAEEventHandlerUPP(g_lpfnAEProc); fprintf(stderr, "installAEHandlers() - AEInstallEventHandler(kAEOpenDocuments) failed, returning %lu!\n", (unsigned long) iErr); return false; } if (noErr != (iErr = AEInstallEventHandler(kCoreEventClass, kAEShowPreferences, g_lpfnAEProc, FOUR_CHAR_CODE('PREF'), FALSE))) { AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments, g_lpfnAEProc, FALSE); AERemoveEventHandler(kCoreEventClass, kAEQuitApplication, g_lpfnAEProc, FALSE); DisposeAEEventHandlerUPP(g_lpfnAEProc); fprintf(stderr, "installAEHandlers() - AEInstallEventHandler(kAEShowPreferences) failed, returning %lu!\n", (unsigned long) iErr); return false; } return true; }
int main( int argc, char ** argv ) { QApplication a( argc, argv ); a.setOrganizationName("sqlitebrowser"); a.setApplicationName("SQLite Database Browser"); // Set character encoding to UTF8 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); // Enable translation QTranslator translator; translator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); a.installTranslator(&translator); QTranslator apptranslator; apptranslator.load("translations/tr_" + QLocale::system().name()); a.installTranslator(&apptranslator); MainWindow w; #if defined(Q_WS_MAC) AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(odocHandler),reinterpret_cast<long>(&w),false); #endif // Q_WS_MAC w.show(); if (argc>1) { //first and only argument we accept is the name of the database to open w.fileOpen(QString(argv[1])); } a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) ); return a.exec(); }
// -------------------------------------------------------------------------------------- static void initialize(void) { MenuBarHandle menuBar; OSErr error; MoreMasters(); // I doubt we actually need any extra master pointers InitGraf(&qd.thePort); // but I left the calls here as a reminder for where they InitFonts(); // belong if they are needed InitWindows(); InitMenus(); TEInit(); InitDialogs(NULL); InitCursor(); RegisterAppearanceClient(); menuBar = GetNewMBar(rMenuBar); // draw the menu bar as soon as possible if (menuBar == NULL) ExitToShell(); SetMenuBar(menuBar); DrawMenuBar(); // do non time sensitive initialization after we get the application event loop going gOpenAppAEHandler = NewAEEventHandlerUPP(openApplicationAEHandler); error = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, gOpenAppAEHandler, 0, false); if (error != noErr) ExitToShell(); /* If we supported them, we would install open documents and print documents handlers here and we would do most of the same initialization stuff that we do in the open application handler. */ FlushEvents(everyEvent, 0); }
// -------------------------------------------------------------------------------------- static void initialize(void) { MenuBarHandle menuBar; OSErr error; /* I doubt we actually need any extra master pointers but I left the call here as a reminder for where it belongs if it is needed. */ MoreMasterPointers(64); // each call to MoreMasters allocates 64 master pointers InitCursor(); RegisterAppearanceClient(); menuBar = GetNewMBar(rMenuBar); // draw the menu bar as soon as possible if (menuBar == NULL) ExitToShell(); SetMenuBar(menuBar); DrawMenuBar(); // do non time sensitive initialization after we get the application event loop going gOpenAppAEHandler = NewAEEventHandlerUPP(openApplicationAEHandler); error = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, gOpenAppAEHandler, 0, false); if (error != noErr) ExitToShell(); /* If we supported them, we would install open documents and print documents handlers here and we would do most of the same initialization stuff that we do in the open application handler. */ }
void init_AE(void) { PyObject *m; PyObject *d; upp_AEIdleProc = NewAEIdleUPP(AEIdleProc); upp_GenericEventHandler = NewAEEventHandlerUPP(GenericEventHandler); upp_GenericCoercionHandler = NewAECoerceDescUPP(GenericCoercionHandler); PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_New); PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_NewBorrowed); PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc, AEDesc_Convert); m = Py_InitModule("_AE", AE_methods); d = PyModule_GetDict(m); AE_Error = PyMac_GetOSErrException(); if (AE_Error == NULL || PyDict_SetItemString(d, "Error", AE_Error) != 0) return; AEDesc_Type.ob_type = &PyType_Type; if (PyType_Ready(&AEDesc_Type) < 0) return; Py_INCREF(&AEDesc_Type); PyModule_AddObject(m, "AEDesc", (PyObject *)&AEDesc_Type); /* Backward-compatible name */ Py_INCREF(&AEDesc_Type); PyModule_AddObject(m, "AEDescType", (PyObject *)&AEDesc_Type); }
void init_AE(void) { PyObject *m; PyObject *d; upp_AEIdleProc = NewAEIdleUPP(AEIdleProc); upp_GenericEventHandler = NewAEEventHandlerUPP(GenericEventHandler); upp_GenericCoercionHandler = NewAECoerceDescUPP(GenericCoercionHandler); m = Py_InitModule("_AE", AE_methods); d = PyModule_GetDict(m); AE_Error = PyMac_GetOSErrException(); if (AE_Error == NULL || PyDict_SetItemString(d, "Error", AE_Error) != 0) return; AEDesc_Type.ob_type = &PyType_Type; if (PyType_Ready(&AEDesc_Type) < 0) return; Py_INCREF(&AEDesc_Type); PyModule_AddObject(m, "AEDesc", (PyObject *)&AEDesc_Type); /* Backward-compatible name */ Py_INCREF(&AEDesc_Type); PyModule_AddObject(m, "AEDescType", (PyObject *)&AEDesc_Type); PyObject *aeAPIObj = PyCObject_FromVoidPtr((void *)&aeAPI, NULL); PyModule_AddObject(m, "aeAPI", aeAPIObj); }
static void InstallAppleEventHandlers( void ) { OSErr status; status = AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(HandleAppleEventOdoc), 0, false ); require_noerr( status, CantInstallAppleEventHandler ); // Note: Since RunApplicationEventLoop installs a Quit AE Handler, there is no need to do it here. CantInstallAppleEventHandler: return; }
void Initialize() /* Initialize some managers */ { OSErr err; InitCursor(); err = AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP((AEEventHandlerProcPtr)QuitAppleEventHandler), 0, false ); if (err != noErr) ExitToShell(); }
void InitAppleEvents(void) { OSErr err; oappUPP = NewAEEventHandlerUPP(AEoapp); err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, oappUPP, 0L, false); odocUPP = NewAEEventHandlerUPP(AEodoc); err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, odocUPP, 0L, false); pdocUPP = NewAEEventHandlerUPP(AEpdoc); err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, pdocUPP, 0L, false); quitUPP = NewAEEventHandlerUPP(AEquit); err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, quitUPP, 0L, false); rappUPP = NewAEEventHandlerUPP(AErapp); err = AEInstallEventHandler(kCoreEventClass, kAEReopenApplication, rappUPP, 0L, false); }
/* ----------- private code */ static void initialize_application( void) { Handle menubar; StringHandle userName; #ifndef OP_PLATFORM_MAC_CARBON_FLAG MaxApplZone(); MoreMasters(); MoreMasters(); MoreMasters(); InitGraf(&qd.thePort); InitFonts(); InitWindows(); InitMenus(); TEInit(); InitDialogs(NULL); #else MoreMasterPointers(192); #endif // ! OP_PLATFORM_MAC_CARBON_FLAG InitCursor(); FlushEvents(everyEvent, 0); menubar= GetNewMBar(rMENU_BAR_ID); op_assert(menubar); SetMenuBar(menubar); DisposeHandle(menubar); AppendResMenu(GetMenuHandle(mApple), 'DRVR'); DrawMenuBar(); // Get the user name from the systemÉ userName = GetString (-16096); if (userName == NULL) strcpy(gNameString, "OpenPlay Test"); else { doCopyP2CStr(*userName,gNameString); ReleaseResource ((Handle) userName); } // ecf - we wanna enable enumeration by default... check_menu_item(mSpecial, iActiveEnumeration, active_enumeration); //install apple event handler for quitting AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,NewAEEventHandlerUPP((AEEventHandlerProcPtr)do_quit_apple_event),0L,false); return; }
/* The 10.4 Entry point */ extern "C" OSErr SAInitialize(CFBundleRef b) { OSErr err=0; additionBundle=b; SampleHandlerUPP = NewAEEventHandlerUPP(MyLocalSampleHandler); for(int i=0;i<gEventDescriptionCount;i++){ err=AEInstallEventHandler( gEventDescriptionList[i].theAEEventClass, gEventDescriptionList[i].theAEEventID, SampleHandlerUPP, gEventDescriptionList[i].refCon, true); if(err) return err; } return err; }
/* Install event handlers for the Apple Events we care about */ static OSErr install_apple_event_handlers(void) { OSErr err; err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, NewAEEventHandlerUPP(OpenApplicationAE), 0, false); require_noerr(err, CantInstallAppleEventHandler); err = AEInstallEventHandler(kCoreEventClass, kAEReopenApplication, NewAEEventHandlerUPP(ReopenApplicationAE), 0, false); require_noerr(err, CantInstallAppleEventHandler); err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(OpenDocumentsAE), 0, false); require_noerr(err, CantInstallAppleEventHandler); err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(QuitApplicationAE), 0, false); require_noerr(err, CantInstallAppleEventHandler); err = AEInstallEventHandler(kCoreEventClass, kAEShowPreferences, NewAEEventHandlerUPP(ShowPreferencesAE), 0, false); require_noerr(err, CantInstallAppleEventHandler); /* some debugging code, for now */ if ( getenv("HOME")!=NULL ) { char buffer[1024]; #ifdef __VMS sprintf( buffer, "%s/_FontForge-LogFile.txt", getenv("HOME")); #else sprintf( buffer, "%s/.FontForge-LogFile.txt", getenv("HOME")); #endif logfile = fopen("/Users/gww/LogFile.txt","w"); } if ( logfile==NULL ) logfile = stderr; CantInstallAppleEventHandler: return err; }
bool Sys_CreateWindow(const char *title, unsigned int w, unsigned int h, bool fs) { OSErr result; ProcessSerialNumber psn; windowRect.top = 100; windowRect.left = 100; windowRect.bottom = windowRect.top + h; windowRect.right = windowRect.left + w; g_Window.height = h; g_Window.width = w; g_Window.fs = fs; result = CreateNewWindow(kDocumentWindowClass, (kWindowStandardDocumentAttributes | kWindowInWindowMenuAttribute | kWindowStandardHandlerAttribute) & ~kWindowResizableAttribute, &windowRect, &g_Window.window); if (result != noErr) return false; SetWindowTitleWithCFString( g_Window.window, CFStringCreateWithCString(0, title, CFStringGetSystemEncoding()) ); result = GetCurrentProcess(&psn); if (result == noErr) { TransformProcessType(&psn, kProcessTransformToForegroundApplication); SetFrontProcess(&psn); } ShowWindow(g_Window.window); SelectWindow(g_Window.window); g_Window.glctx = createContext(g_Window.window); if (!g_Window.glctx) return false; /* static EventTypeSpec suspendResume[2] = {{kEventClassApplication, kEventAppActivated}, {kEventClassApplication, kEventAppDeactivated}}; InstallApplicationEventHandler(NewEventHandlerUPP(suspendResumeHandler), 2, suspendResume, &g_Window.window, NULL); */ AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(quitEventHandler), 0, false); return true; }
bool wxApp::OnInitGui() { if ( !wxAppBase::OnInitGui() ) return false ; InstallStandardEventHandler( GetApplicationEventTarget() ) ; if (!sm_isEmbedded) { InstallApplicationEventHandler( GetwxMacAppEventHandlerUPP(), GetEventTypeCount(eventList), eventList, wxTheApp, (EventHandlerRef *)&(wxTheApp->m_macEventHandler)); } if (!sm_isEmbedded) { sODocHandler = NewAEEventHandlerUPP(AEHandleODoc) ; sOAppHandler = NewAEEventHandlerUPP(AEHandleOApp) ; sPDocHandler = NewAEEventHandlerUPP(AEHandlePDoc) ; sRAppHandler = NewAEEventHandlerUPP(AEHandleRApp) ; sQuitHandler = NewAEEventHandlerUPP(AEHandleQuit) ; AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , sODocHandler , 0 , FALSE ) ; AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , sOAppHandler , 0 , FALSE ) ; AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , sPDocHandler , 0 , FALSE ) ; AEInstallEventHandler( kCoreEventClass , kAEReopenApplication , sRAppHandler , 0 , FALSE ) ; AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , sQuitHandler , 0 , FALSE ) ; } if ( !wxMacInitCocoa() ) return false; return true ; }
static void gui_unique_mac_init (Gimp *gimp) { g_return_if_fail (GIMP_IS_GIMP (gimp)); g_return_if_fail (unique_gimp == NULL); unique_gimp = gimp; open_document_callback_proc = NewAEEventHandlerUPP(gui_unique_mac_open_documents); AEInstallEventHandler (kCoreEventClass, kAEOpenDocuments, open_document_callback_proc, 0L, TRUE); }
//---------------------------------------------------------------------- int main(int argc, char **argv) { #if !TARGET_CARBON // Set up the toolbox and (if DEBUG) the console InitializeMacToolbox(); #endif // Install a Quit AppleEvent handler. #ifdef DEBUG OSErr err = #endif AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(handleQuitApplication), 0, false); NS_ASSERTION((err==noErr), "AEInstallEventHandler failed"); #ifdef XP_MACOSX // use the location of the executable to learn where everything is, this // is because the current working directory is ill-defined when the // application is double-clicked from the Finder. { char* path = strdup(argv[0]); char* lastSlash = strrchr(path, '/'); if (lastSlash) { *lastSlash = '\0'; setenv("MOZILLA_FIVE_HOME", path, 1); } free(path); } #endif // Start up XPCOM? nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed"); gTheApp = new nsNativeViewerApp(); if (gTheApp != nsnull) { NS_ADDREF(gTheApp); if (gTheApp->Initialize(argc, argv) == NS_OK) gTheApp->Run(); NS_RELEASE(gTheApp); } // Shutdown XPCOM? rv = NS_ShutdownXPCOM(nsnull); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return 0; }
int init_macintosh( void) { static int initdone = 0; Handle menuBar; long attributes; /* semaphore required for preemptive threads */ if( initdone) return initdone == 1; initdone = -1; /* should I check for MLNK resource too as launch-filtering is done based on it? */ /* too late--since I'm running there likely wasn't a problem (this time anyway). */ menuBar = GetNewMBar(rMenuBar); if( menuBar){ SetMenuBar(menuBar); DisposeHandle(menuBar); }else{ MenuHandle am, fm, em; am = NewMenu( mApple, (unsigned char*)"\001\024"); fm = NewMenu( mFile, (unsigned char*)"\004File"); em = NewMenu( mEdit, (unsigned char*)"\004Edit"); if( !am || !fm || !em) return 0; AppendMenu( am, (unsigned char*)"\022About MathLink\252\311;-"); DisableMenuItem(am, 0); InsertMenu( am, 0); AppendMenu( fm, (unsigned char*)"\006Quit/Q"); InsertMenu( fm, 0); AppendMenu( em, (unsigned char*)"\043Undo/Z;-;Cut/X;Copy/C;Paste/V;Clear"); DisableMenuItem(em, 0); InsertMenu( em, 0); } AppendResMenu( GetMenuHandle(mApple), 'DRVR'); set_about_item(); DrawMenuBar(); about_filter_upp = NewModalFilterUPP( about_filter); outline_hook_upp = NewUserItemUPP( outline_hook); if( Gestalt( gestaltAppleEventsAttr, &attributes) == noErr && ((1 << gestaltAppleEventsPresent) & attributes)){ handle_core_ae_upp = NewAEEventHandlerUPP( handle_core_ae); (void) AEInstallEventHandler( kCoreEventClass, typeWildCard, handle_core_ae_upp, 0, false); }else{ return 0; /* this may be too strong since I am, after all, running. */ } initdone = 1; return initdone == 1; }
void QTApp_InstallAppleEventHandlers (void) { long myAttrs; OSErr myErr = noErr; // see whether the Apple Event Manager is available in the present operating environment; // if it is, install handlers for the four required Apple Events myErr = Gestalt(gestaltAppleEventsAttr, &myAttrs); if (myErr == noErr) { if (myAttrs & (1L << gestaltAppleEventsPresent)) { // create routine descriptors for the Apple event handlers gHandleOpenAppAEUPP = NewAEEventHandlerUPP(QTApp_HandleOpenApplicationAppleEvent); gHandleOpenDocAEUPP = NewAEEventHandlerUPP(QTApp_HandleOpenDocumentAppleEvent); gHandlePrintDocAEUPP = NewAEEventHandlerUPP(QTApp_HandlePrintDocumentAppleEvent); gHandleQuitAppAEUPP = NewAEEventHandlerUPP(QTApp_HandleQuitApplicationAppleEvent); // install the handlers AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, gHandleOpenAppAEUPP, 0L, false); AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, gHandleOpenDocAEUPP, 0L, false); AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, gHandlePrintDocAEUPP, 0L, false); AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, gHandleQuitAppAEUPP, 0L, false); } } }
void init_apple_menu(const char* product) { // Load up a proper menu bar. { OSStatus err; IBNibRef nib = NULL; // NOTE: DO NOT translate or brand this string. It's an internal name in the .nib file, and MUST match exactly. err = CreateNibReference(CFSTR("SecondLife"), &nib); if(err == noErr) { // NOTE: DO NOT translate or brand this string. It's an internal name in the .nib file, and MUST match exactly. SetMenuBarFromNib(nib, CFSTR("MenuBar")); } if(nib != NULL) { DisposeNibReference(nib); } } // Install a handler for 'gurl' AppleEvents. This is how secondlife:// URLs get passed to the viewer. if(AEInstallEventHandler('GURL', 'GURL', NewAEEventHandlerUPP(AEGURLHandler),0, false) != noErr) { // Couldn't install AppleEvent handler. This error shouldn't be fatal. llinfos << "Couldn't install 'GURL' AppleEvent handler. Continuing..." << llendl; } // Install a handler for 'quit' AppleEvents. This makes quitting the application from the dock work. if(AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(AEQuitHandler),0, false) != noErr) { // Couldn't install AppleEvent handler. This error shouldn't be fatal. llinfos << "Couldn't install Quit AppleEvent handler. Continuing..." << llendl; } }
OSErr MRInstallAEHandlers(AEInstallStructPtr installUs,short numToInstall) { OSErr err = noErr; short count; for (count=0; count<numToInstall; count++) { err = AEInstallEventHandler(installUs[count].theEventClass, installUs[count].theEventID, NewAEEventHandlerUPP(installUs[count].theHandler), 0L,false); if (err) return err; } return err; }
/** * JNI Method to register interest in callback. * Obtained from: * javah -classpath plugins/ui_swing.jar com.dmdirc.addons.ui_swing.Apple * Reference: * http://developer.apple.com/documentation/Carbon/Reference/Apple_Event_Manager/Reference/reference.html#//apple_ref/c/func/AEInstallEventHandler * * @param env The JNIEnvironment for this callback. * @param this The object that is registering the callback */ JNIEXPORT jint JNICALL Java_com_dmdirc_addons_ui_1swing_Apple_registerOpenURLCallback (JNIEnv *env, jobject object) { // Find the callback in the object callbackMethod = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, object), "handleOpenURL", "(Ljava/lang/String;)V"); // Check if the callback exists. if (callbackMethod != 0) { // Store the JVM for this callback, and a global reference to the Apple object (*env)->GetJavaVM(env, &jvm); apple = (*env)->NewGlobalRef(env, object); // Now register the callback to ourself. return (jint)AEInstallEventHandler(kInternetEventClass, kAEGetURL, NewAEEventHandlerUPP((AEEventHandlerProcPtr)openURLCallback), 0, false); } else { return 1; } }
unicorn::Application::Application( int& argc, char** argv ) throw( StubbornUserException ) : QApplication( argc, argv ), m_logoutAtQuit( false ) { #ifdef Q_WS_MAC qt_mac_set_menubar_icons( false ); #endif CoreApplication::init(); #ifdef __APPLE__ AEEventHandlerUPP h = NewAEEventHandlerUPP( appleEventHandler ); AEInstallEventHandler( kCoreEventClass, kAEReopenApplication, h, 0, false ); #endif translate(); CoreSettings s; if (s.value( "Username" ).toString().isEmpty() || s.value( "SessionKey" ).toString().isEmpty() || Settings().logOutOnExit()) { LoginDialog d( s.value( "Username" ).toString() ); if (d.exec() == QDialog::Accepted) { // if LogOutOnExit is enabled, really, we shouldn't store these, // but it means other Unicorn apps can log in while the client is // loaded, and we delete the settings on exit if logOut is on s.setValue( "Username", d.username() ); s.setValue( "SessionKey", d.sessionKey() ); s.setValue( "Password", d.passwordHash() ); UserSettings().setValue( UserSettings::subscriptionKey(), d.isSubscriber() ); } else { throw StubbornUserException(); } } Ws::Username = s.value( "Username" ).toString(); Ws::SessionKey = s.value( "SessionKey" ).toString(); connect( AuthenticatedUser().getInfo(), SIGNAL(finished( WsReply* )), SLOT(onUserGotInfo( WsReply* )) ); #ifdef __APPLE__ setQuitOnLastWindowClosed( false ); #endif }
play_tree_t *macosx_finder_args(m_config_t *config, int argc, char **argv) { ProcessSerialNumber myPsn; char myPsnStr[5+10+1+10+1]; GetCurrentProcess(&myPsn); snprintf(myPsnStr, 5+10+1+10+1, "-psn_%u_%u", myPsn.highLongOfPSN, myPsn.lowLongOfPSN); myPsnStr[5+10+1+10]=0; if((argc==2) && !strcmp(myPsnStr, argv[1])) { m_config_set_option(config, "quiet", NULL); InitCursor(); AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(AppleEventHandlerProc), 0, FALSE); RunApplicationEventLoop(); } return files; }