static OSErr InitializeApplication( void ) { OSErr err; static const EventTypeSpec sApplicationEvents[] = { { kEventClassCommand, kEventCommandProcess } }; BlockZero( &g, sizeof(g) ); g.mainBundle = CFBundleGetMainBundle(); if ( g.mainBundle == NULL ) { err = -1; goto Bail; } err = CreateNibReferenceWithCFBundle( g.mainBundle, CFSTR("WindowFun"), &g.mainNib ); if ( err != noErr ) goto Bail; if ( g.mainNib == NULL ) { err = -1; goto Bail; } err = SetMenuBarFromNib( g.mainNib, CFSTR("MenuBar") ); if ( err != noErr ) goto Bail; InstallApplicationEventHandler( NewEventHandlerUPP(AppEventEventHandlerProc), GetEventTypeCount(sApplicationEvents), sApplicationEvents, 0, NULL ); // Force the document group to be created first, so we can position our groups between the floating and document groups (void) GetWindowGroupOfClass( kDocumentWindowClass ); // Create our default WindowGroups and set their z-order err = CreateWindowGroup( 0, &g.windowGroups[0] ); err = CreateWindowGroup( 0, &g.windowGroups[1] ); err = CreateWindowGroup( 0, &g.windowGroups[2] ); // Position our groups behind the floating group and in front of the document group SendWindowGroupBehind( g.windowGroups[2], GetWindowGroupOfClass( kDocumentWindowClass ) ); SendWindowGroupBehind( g.windowGroups[1], g.windowGroups[2] ); SendWindowGroupBehind( g.windowGroups[0], g.windowGroups[1] ); Bail: return( err ); }
static void dockmenuinstallhandler (void) { EventTypeSpec myevents = {kEventClassCommand, kEventCommandProcess}; InstallApplicationEventHandler (NewEventHandlerUPP (dockcommandhandler), 1, &myevents, 0, NULL); } /*dockmenuinstallhandler*/
COSXScreenSaver::COSXScreenSaver(IEventQueue* events, void* eventTarget) : m_eventTarget(eventTarget), m_enabled(true), m_events(events) { m_autoReleasePool = screenSaverUtilCreatePool(); m_screenSaverController = screenSaverUtilCreateController(); // install launch/termination event handlers EventTypeSpec launchEventTypes[2]; launchEventTypes[0].eventClass = kEventClassApplication; launchEventTypes[0].eventKind = kEventAppLaunched; launchEventTypes[1].eventClass = kEventClassApplication; launchEventTypes[1].eventKind = kEventAppTerminated; EventHandlerUPP launchTerminationEventHandler = NewEventHandlerUPP(launchTerminationCallback); InstallApplicationEventHandler(launchTerminationEventHandler, 2, launchEventTypes, this, &m_launchTerminationEventHandlerRef); DisposeEventHandlerUPP(launchTerminationEventHandler); m_screenSaverPSN.highLongOfPSN = 0; m_screenSaverPSN.lowLongOfPSN = 0; if (isActive()) { getProcessSerialNumber("ScreenSaverEngine", m_screenSaverPSN); } }
void enter_mouse( short type) { (void) (type); snapshot_delta_yaw= snapshot_delta_pitch= snapshot_delta_velocity= false; for(int i = 0; i < MAX_BUTTONS; i++) snapshot_button_state[i] = false; snapshot_delta_scrollwheel = 0; // JTP: Install our Carbon Event mouse handler and create the critical region for safe value sharing static EventTypeSpec mouseEvents[] = { {kEventClassMouse, kEventMouseDown}, {kEventClassMouse, kEventMouseUp}, {kEventClassMouse, kEventMouseWheelMoved}, {kEventClassMouse, kEventMouseMoved}, {kEventClassMouse, kEventMouseDragged} }; _CEMouseTrackerUPP = NewEventHandlerUPP(CEvtHandleApplicationMouseEvents); InstallApplicationEventHandler (_CEMouseTrackerUPP, 5, mouseEvents, NULL, &_CEMouseTracker); MPCreateCriticalRegion(&CE_MouseLock); // Fallback in case the lock cannot be allocated (possible with Classic): if (!CE_MouseLock) GetGlobalMouse(&PrevPosition); #ifndef __MACH__ LoadCGMouseFunctions(); #endif }
void Shell::EventLoop(ShellIdleFunction idle_function) { OSStatus error; error = InstallApplicationEventHandler(NewEventHandlerUPP(InputMacOSX::EventHandler), GetEventTypeCount(INPUT_EVENTS), INPUT_EVENTS, NULL, NULL); if (error != noErr) DisplayError("Unable to install handler for input events, error: %d.", error); error = InstallWindowEventHandler(window, NewEventHandlerUPP(EventHandler), GetEventTypeCount(WINDOW_EVENTS), WINDOW_EVENTS, NULL, NULL); if (error != noErr) DisplayError("Unable to install handler for window events, error: %d.", error); EventLoopTimerRef timer; error = InstallEventLoopIdleTimer(GetMainEventLoop(), // inEventLoop 0, // inFireDelay 5 * kEventDurationMillisecond, // inInterval (200 Hz) NewEventLoopIdleTimerUPP(IdleTimerCallback), // inTimerProc (void*) idle_function, // inTimerData, &timer // outTimer ); if (error != noErr) DisplayError("Unable to install Carbon event loop timer, error: %d.", error); RunApplicationEventLoop(); }
//ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // Carbon_InitMouse //ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // Call this to install CarbonEvent handlers to read the mouse states. //ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ Boolean Carbon_InitMouse( void ) { EventHandlerRef ref; OSStatus status; EventTypeSpec list[] = { {kEventClassMouse, kEventMouseDown }, {kEventClassMouse, kEventMouseUp }, {kEventClassMouse, kEventMouseMoved }, // deltas while mouse button is up {kEventClassMouse, kEventMouseDragged }, // deltas while mouse button is down {kEventClassMouse, kEventMouseWheelMoved } }; // If we don't support Carbon events, bail if ( (Ptr) InstallEventHandler == (Ptr) kUnresolvedCFragSymbolAddress ) { goto bail; } // Install an application event handler sMouseEventHandlerUPP = NewEventHandlerUPP( appMouseEventHandler ); status = InstallApplicationEventHandler( sMouseEventHandlerUPP, 5, list, 0, &ref ); #if TARGET_RT_MAC_CFM // ¥¥¥¥¥¥ if ( status != noErr ) { return false; } #endif // Disable the mouse initially so that any pre-game dialogs will work sMouseEnabled = false; // indicate success return true; bail: return false; }
bool os_initialize( adobe::application_t* theApp ) { // // On the Mac we need to install the application menus, respond // to AppleEvents and set the resource path. We set the resource // path first. // ProcessSerialNumber psn; ADOBE_REQUIRE_STATUS( GetCurrentProcess( &psn ) ); FSRef location; ADOBE_REQUIRE_STATUS( GetProcessBundleLocation( &psn, &location ) ); theApp->set_resource_directory( fsref_to_path( location ) / "Contents" / "Resources" ); // // Now load our bundle, sign up for AppleEvents and show the menu. // CFBundleRef bundle = CFBundleGetMainBundle(); IBNibRef nibs = 0; if( !bundle ) return false; ADOBE_REQUIRE_STATUS( CreateNibReferenceWithCFBundle( bundle, kMainNibFileName, &nibs ) ); if( !nibs ) { ::CFRelease( bundle ); return false; } // // Sign up to handle the "Open" AppleEvent. // static adobe::auto_resource<AEEventHandlerUPP> ae_handler( NewAEEventHandlerUPP( handle_open ) ); AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments, ae_handler.get(), 0, false ); // // Install the menu, and it's event handler. // ADOBE_REQUIRE_STATUS( SetMenuBarFromNib( nibs, kMenuBarNibName ) ); static EventTypeSpec hi_event = { kEventClassCommand, kHICommandFromMenu }; static adobe::auto_resource<EventHandlerUPP> hi_handler( NewEventHandlerUPP( menu_command ) ); InstallApplicationEventHandler( hi_handler.get(), 1, &hi_event, theApp, 0 ); // // Register this app as an Appearance Client // // Apple docs: "This function does nothing on Mac OS X. Do not call it." // // RegisterAppearanceClient(); return true; }
Helper( MemoryCardDriverThreaded_MacOSX *driver ) { m_HandlerUPP = NewEventHandlerUPP( VolumesChanged ); EventTypeSpec types[] = { { kEventClassVolume, kEventVolumeMounted }, { kEventClassVolume, kEventVolumeUnmounted } }; UInt32 numTypes = sizeof(types)/sizeof(types[0]); OSStatus ret = InstallApplicationEventHandler( m_HandlerUPP, numTypes, types, driver, &m_Handler ); ASSERT( ret == noErr ); }
void* CContextOSX::CreateMainWindow(SSize /*Size*/, tint32 /*iWindowsOnly_MenuResourceID = -1*/, tint32 /*iWindowsOnly_IconResourceID = -1*/) { gpMainContext = this; IBNibRef sNibRef; OSStatus err; static const EventTypeSpec kAppEvents[] = { { kEventClassCommand, kEventCommandProcess }, { kCoreEventClass, kAEOpenDocuments } }; // Create a Nib reference, passing the name of the nib file (without the .nib extension). // CreateNibReference only searches into the application bundle. err = CreateNibReference( CFSTR("main"), &sNibRef ); // require_noerr( err, CantGetNibRef ); // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar // object. This name is set in InterfaceBuilder when the nib is created. err = SetMenuBarFromNib( sNibRef, CFSTR("MenuBar") ); // require_noerr( err, CantSetMenuBar ); // Install our handler for common commands on the application target // InstallApplicationEventHandler( NewEventHandlerUPP( AppEventHandler ), // GetEventTypeCount( kAppEvents ), kAppEvents, // 0, NULL ); WindowRef gpWindow; err = CreateWindowFromNib( sNibRef, CFSTR("MainWindow"), &gpWindow ); // Position new windows in a staggered arrangement on the main screen RepositionWindow( gpWindow, NULL, kWindowCascadeOnMainScreen ); // The window was created hidden, so show it // ShowWindow( gpWindow ); ::InvalMenuBar(); ::DrawMenuBar(); // Install application event handler InstallApplicationEventHandler( NewEventHandlerUPP( AppEventHandler ), GetEventTypeCount( kAppEvents ), kAppEvents, this, NULL ); InstallWindowEventHandler(gpWindow, GetWindowEventHandlerUPP(), GetEventTypeCount(kWindowEvents), kWindowEvents, gpWindow, NULL); return (void*)gpWindow; }
MyQApplication(int& argc, char **argv) : QApplication(argc, argv), m_mainwindow(NULL) { EventTypeSpec hkEvents[2]; hkEvents[0].eventClass = kEventClassKeyboard; hkEvents[0].eventKind = kEventHotKeyPressed; hkEvents[1].eventClass = kEventClassKeyboard; hkEvents[1].eventKind = kEventHotKeyReleased; OSStatus oss = InstallApplicationEventHandler(&mac_callback, 2, hkEvents, NULL, NULL); Q_ASSERT(oss == 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; }
int main(void) { OSStatus err; UInt32 response; err = Gestalt(gestaltSystemVersion, (long *) &response); if (err == noErr) { if ( response < 0x1020 ) { SInt16 junkHit; (void) StandardAlert( kAlertStopAlert, "\pLoginItemsAETest requires Mac OS X 10.2 or later.", "\p", NULL, &junkHit ); err = userCanceledErr; } } // Start up the UI. if (err == noErr) { err = SetupUserInterface(); } // Install our HICommand handler. if (err == noErr) { gApplicationEventHandlerUPP = NewEventHandlerUPP(ApplicationEventHandler); assert(gApplicationEventHandlerUPP != NULL); err = InstallApplicationEventHandler(gApplicationEventHandlerUPP, GetEventTypeCount(kApplicationEvents), kApplicationEvents, NULL, NULL); } // Run the application. if (err == noErr) { RunApplicationEventLoop(); } DisplayError(err); return 0; }
COSXScreenSaver::COSXScreenSaver(void* eventTarget) : m_eventTarget(eventTarget), m_enabled(true) { m_autoReleasePool = screenSaverUtilCreatePool(); m_screenSaverController = screenSaverUtilCreateController(); // install launch/termination event handlers EventTypeSpec launchEventTypes[2]; launchEventTypes[0].eventClass = kEventClassApplication; launchEventTypes[0].eventKind = kEventAppLaunched; launchEventTypes[1].eventClass = kEventClassApplication; launchEventTypes[1].eventKind = kEventAppTerminated; EventHandlerUPP launchTerminationEventHandler = NewEventHandlerUPP(launchTerminationCallback); InstallApplicationEventHandler(launchTerminationEventHandler, 2, launchEventTypes, this, &m_launchTerminationEventHandlerRef); DisposeEventHandlerUPP(launchTerminationEventHandler); m_screenSaverPSN.highLongOfPSN = 0; m_screenSaverPSN.lowLongOfPSN = 0; // test if screensaver is running and find process number if (isActive()) { ProcessInfoRec procInfo; Str31 procName; // pascal string. first byte holds length. memset(&procInfo, 0, sizeof(procInfo)); procInfo.processName = procName; procInfo.processInfoLength = sizeof(ProcessInfoRec); ProcessSerialNumber psn; OSErr err = GetNextProcess(&psn); while (err == 0) { memset(procName, 0, sizeof(procName)); err = GetProcessInformation(&psn, &procInfo); if (err != 0) { break; } if (strcmp("ScreenSaverEngine", (const char*)&procName[1]) == 0) { m_screenSaverPSN = psn; break; } err = GetNextProcess(&psn); } } }
pascal OSStatus dummy_event_handler(EventHandlerCallRef call_ref, EventRef in_event, void *ignore) { OSStatus err; EventHandlerRef installed_handler; EventTypeSpec event_spec = { kEventClassApplication, kEventAppQuit }; // From http://developer.apple.com/qa/qa2001/qa1061.html // Trick to move main event queue to use ReceiveNextEvent in an event // handler called by RunApplicationEventLoop err = InstallApplicationEventHandler(g_quit_handler_UPP, 1, &event_spec, NULL, &installed_handler); gsplusmain(g_mac_argc, g_mac_argv); return noErr; }
CV_IMPL int cvInitSystem( int argc, char** argv ) { OSErr err = noErr; if( !wasInitialized ) { hg_windows = 0; err = InstallApplicationEventHandler(NewEventHandlerUPP( keyHandler),GetEventTypeCount(applicationKeyboardEvents),applicationKeyboardEvents,NULL,NULL); if (err != noErr) { fprintf(stderr,"InstallApplicationEventHandler was not ok\n"); } wasInitialized = 1; } return 0; }
int main(int argc, char* argv[]) { IBNibRef nibRef; OSStatus err; // check the correct BASS was loaded if (HIWORD(BASS_GetVersion())!=BASSVERSION) { Error("An incorrect version of BASS was loaded"); return 0; } // initialize default output device if (!BASS_Init(-1,44100,0,NULL,NULL)) { Error("Can't initialize device"); return 0; } BASS_SetConfig(BASS_CONFIG_NET_PLAYLIST,1); // enable playlist processing BASS_SetConfig(BASS_CONFIG_NET_PREBUF,0); // minimize automatic pre-buffering, so we can do it (and display it) instead BASS_SetConfigPtr(BASS_CONFIG_NET_PROXY,proxy); // setup proxy server location // Create Window and stuff err = CreateNibReference(CFSTR("netradio"), &nibRef); if (err) return err; err = CreateWindowFromNib(nibRef, CFSTR("Window"), &win); if (err) return err; DisposeNibReference(nibRef); int a; for (a=10;a<20;a++) SetupControlHandler(a,kEventControlHit,RadioEventHandler); SetupControlHandler(41,kEventControlHit,DirectEventHandler); { EventTypeSpec etype={'blah','blah'}; InstallApplicationEventHandler(NewEventHandlerUPP(CustomEventHandler),1,&etype,NULL,NULL); } ShowWindow(win); RunApplicationEventLoop(); BASS_Free(); return 0; }
int install_app_launch_cb(void *user_data) { static int already_installed = 0; if(!already_installed){ EventHandlerUPP cb_upp; EventTypeSpec event_types[2] = { {kEventClassApplication, kEventAppTerminated}, {kEventClassApplication, kEventAppLaunchNotification}}; if((cb_upp = NewEventHandlerUPP(osx_launch_app_callback)) == NULL) return 1; InstallApplicationEventHandler(cb_upp, 2, event_types, user_data, NULL); already_installed = 1; } return 0; }
wxTaskBarIcon::wxTaskBarIcon(const wxTaskBarIconType& nType) : m_nType(nType), m_pEventHandlerRef(NULL), m_pMenu(NULL), m_theLastMenu((WXHMENU)GetApplicationDockTileMenu()), m_iconAdded(false) { //Register the events that will return the dock menu EventTypeSpec tbEventList[] = { { kEventClassCommand, kEventProcessCommand }, { kEventClassApplication, kEventAppGetDockTileMenu } }; #ifdef __WXDEBUG__ OSStatus err = #endif InstallApplicationEventHandler( GetwxDockEventHandlerUPP(), GetEventTypeCount(tbEventList), tbEventList, this, (&(EventHandlerRef&)m_pEventHandlerRef)); wxASSERT(err == noErr); Connect(wxEVT_TASKBAR_RIGHT_DOWN, wxTaskBarIconEventHandler(wxTaskBarIcon::OnRightDown)); }
void temp_run_application_event_loop(void) { OSStatus err; EventRef dummy_event; EventHandlerRef install_handler; EventTypeSpec event_spec = { 'KWIN', 'KWIN' }; // Create UPP for dummy_event_handler and for quit_event_handler err = noErr; dummy_event = 0; g_dummy_event_handler_UPP = NewEventHandlerUPP(dummy_event_handler); g_quit_handler_UPP = NewEventHandlerUPP(quit_event_handler); if((g_dummy_event_handler_UPP == 0) || (g_quit_handler_UPP == 0)) { err = memFullErr; } if(err == noErr) { err = InstallApplicationEventHandler(g_dummy_event_handler_UPP, 1, &event_spec, 0, &install_handler); if(err == noErr) { err = MacCreateEvent(NULL, 'KWIN', 'KWIN', GetCurrentEventTime(), kEventAttributeNone, &dummy_event); if(err == noErr) { err = PostEventToQueue(GetMainEventQueue(), dummy_event, kEventPriorityHigh); } if(err == noErr) { RunApplicationEventLoop(); } (void)RemoveEventHandler(install_handler); } } if(dummy_event != NULL) { ReleaseEvent(dummy_event); } }
//----------------------------------------------------------------------------- // wxDockTaskBarIcon ctor // // Initializes the dock implementation of wxTaskBarIcon. // // Here we create some Mac-specific event handlers and UPPs. //----------------------------------------------------------------------------- wxDockTaskBarIcon::wxDockTaskBarIcon(wxTaskBarIcon* parent) : wxTaskBarIconImpl(parent), m_eventHandlerRef(NULL), m_pMenu(NULL), m_theLastMenu(GetApplicationDockTileMenu()), m_iconAdded(false) { // register the events that will return the dock menu EventTypeSpec tbEventList[] = { { kEventClassCommand, kEventProcessCommand }, { kEventClassApplication, kEventAppGetDockTileMenu } }; m_eventupp = NewEventHandlerUPP(wxDockEventHandler); wxASSERT(m_eventupp != NULL); OSStatus err = InstallApplicationEventHandler( m_eventupp, GetEventTypeCount(tbEventList), tbEventList, this, &m_eventHandlerRef); verify_noerr( err ); }
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods) { if (!qxt_mac_handler_installed) { EventTypeSpec t; t.eventClass = kEventClassKeyboard; t.eventKind = kEventHotKeyPressed; InstallApplicationEventHandler(&qxt_mac_handle_hot_key, 1, &t, NULL, NULL); } EventHotKeyID keyID; keyID.signature = 'cute'; keyID.id = ++hotKeySerial; EventHotKeyRef ref = 0; bool rv = !RegisterEventHotKey(nativeKey, nativeMods, keyID, GetApplicationEventTarget(), 0, &ref); if (rv) { keyIDs.insert(Identifier(nativeMods, nativeKey), keyID.id); keyRefs.insert(keyID.id, ref); } return rv; }
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 ; }
int main(int argc, char* argv[]) { IBNibRef nibRef; OSStatus err; // Create a Nib reference passing the name of the nib file (without the .nib extension) // CreateNibReference only searches into the application bundle. err = CreateNibReference(CFSTR("main"), &nibRef); require_noerr( err, CantGetNibRef ); // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar // object. This name is set in InterfaceBuilder when the nib is created. err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar")); require_noerr( err, CantSetMenuBar ); MakeWindow(nibRef); // don't need the nib reference anymore. DisposeNibReference(nibRef); const EventTypeSpec commandProcessEvents[] = { { kEventClassCommand, kEventCommandProcess } }; InstallAppleEventHandlers(); InstallApplicationEventHandler( NewEventHandlerUPP(CommandProcessEventHandler), GetEventTypeCount(commandProcessEvents), commandProcessEvents, NULL, NULL ); // Must initialize QuickTime first InitializeQuickTime (); // Call the event loop RunApplicationEventLoop(); CantCreateWindow: CantSetMenuBar: CantGetNibRef: return err; }
//--------------------------------------------------------------------------------------------- int main() { static const EventTypeSpec sApplicationEvents[] = {{ kEventClassCommand, kEventCommandProcess }}; OSErr err; if (!SystemVersionRequired(0x1020)) { DialogRef theAlert; CreateStandardAlert(kAlertStopAlert, CFSTR("Need 10.2 or later!"), NULL, NULL, &theAlert); RunStandardAlert(theAlert, NULL, NULL); return 0; } ProcessSerialNumber psn = {0, kCurrentProcess}; err = GetProcessBundleLocation(&psn, &gApplicationBundleFSRef); err = CreateNibReference(CFSTR("CarbonSketch"), &gOurNibRef ); require_noerr( err, CantGetNibRef ); err = SetMenuBarFromNib( gOurNibRef, CFSTR("MenuBar") ); require_noerr( err, SetMenuBarFromNib_FAILED ); AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, DoOpenApp, 0, false); AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, DoOpenDocuments, 0, false); // AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, DoPrintDocuments, 0, false); InstallApplicationEventHandler( NewEventHandlerUPP(AppEventHandlerProc), GetEventTypeCount(sApplicationEvents), sApplicationEvents, 0, NULL ); RunApplicationEventLoop(); SetMenuBarFromNib_FAILED: DisposeNibReference(gOurNibRef); CantGetNibRef: return err; }
int main(int argc, char* argv[]) { IBNibRef nibRef; WindowRef window; OSStatus err; EventTypeSpec cmdEvent = {kEventClassCommand, kEventCommandProcess}; // Create a Nib reference passing the name of the nib file (without the .nib extension) // CreateNibReference only searches into the application bundle. err = CreateNibReference(CFSTR("main"), &nibRef); require_noerr( err, CantGetNibRef ); // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar // object. This name is set in InterfaceBuilder when the nib is created. err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar")); require_noerr( err, CantSetMenuBar ); // Then create a window. "MainWindow" is the name of the window object. This name is set in // InterfaceBuilder when the nib is created. err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window); require_noerr( err, CantCreateWindow ); // We don't need the nib reference anymore. DisposeNibReference(nibRef); // The window was created hidden so show it. ShowWindow( window ); InstallApplicationEventHandler(NewEventHandlerUPP(appCommandHandler), GetEventTypeCount(cmdEvent), &cmdEvent, 0, NULL); // Call the event loop RunApplicationEventLoop(); CantCreateWindow: CantSetMenuBar: CantGetNibRef: return err; }
//-------------------------------------------------------------------------------------------- int main( int argc, char *argv[] ) { OSStatus status; const EventTypeSpec commandProcessEvents[] = { { kEventClassCommand, kEventCommandProcess } }; status = CreateNibReference( CFSTR("main"), &gMainNibRef ); require_noerr( status, CantGetNibRef ); status = SetMenuBarFromNib( gMainNibRef, CFSTR("MenuBar") ); require_noerr( status, CantSetMenuBar ); InstallApplicationEventHandler( NewEventHandlerUPP(CommandProcessEventHandler), GetEventTypeCount(commandProcessEvents), commandProcessEvents, NULL, NULL ); NSApplicationLoad(); // Needed for Carbon based applications which call into Cocoa DoNewWindow( NULL ); RunApplicationEventLoop(); // In 10.4, RunApplicationEventLoop also handles our AutoRelease pool used in Cocoa. CantSetMenuBar: CantGetNibRef: return( status ); }
static OSErr InitializeApplication( void ) { OSErr err; static const EventTypeSpec sApplicationEvents[] = { { kEventClassCommand, kEventCommandProcess } }; BlockZero( &g, sizeof(g) ); g.mainBundle = CFBundleGetMainBundle(); if ( g.mainBundle == NULL ) { err = -1; goto Bail; } if ( MPLibraryIsLoaded() == false ) { err = -1; goto Bail; } err = CreateNibReferenceWithCFBundle( g.mainBundle, CFSTR("main"), &g.mainNib ); if ( err != noErr ) goto Bail; if ( g.mainNib == NULL ) { err = -1; goto Bail; } err = SetMenuBarFromNib( g.mainNib, CFSTR("MenuBar") ); if ( err != noErr ) goto Bail; InstallApplicationEventHandler( NewEventHandlerUPP(AppEventEventHandlerProc), GetEventTypeCount(sApplicationEvents), sApplicationEvents, 0, NULL ); Bail: return( err ); }
COSXScreen::COSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCursor) : CPlatformScreen(events), m_events(events), MouseButtonEventMap(NumButtonIDs), m_isPrimary(isPrimary), m_isOnScreen(m_isPrimary), m_cursorPosValid(false), m_cursorHidden(false), m_dragNumButtonsDown(0), m_dragTimer(NULL), m_keyState(NULL), m_sequenceNumber(0), m_screensaver(NULL), m_screensaverNotify(false), m_ownClipboard(false), m_clipboardTimer(NULL), m_hiddenWindow(NULL), m_userInputWindow(NULL), m_switchEventHandlerRef(0), m_pmMutex(new CMutex), m_pmWatchThread(NULL), m_pmThreadReady(new CCondVar<bool>(m_pmMutex, false)), m_activeModifierHotKey(0), m_activeModifierHotKeyMask(0), m_lastSingleClick(0), m_lastDoubleClick(0), m_lastSingleClickXCursor(0), m_lastSingleClickYCursor(0), m_autoShowHideCursor(autoShowHideCursor), m_eventTapRLSR(nullptr), m_eventTapPort(nullptr), m_pmRootPort(0) { try { m_displayID = CGMainDisplayID(); updateScreenShape(m_displayID, 0); m_screensaver = new COSXScreenSaver(m_events, getEventTarget()); m_keyState = new COSXKeyState(m_events); // TODO: http://stackoverflow.com/questions/2950124/enable-access-for-assistive-device-programmatically if (m_isPrimary && !AXAPIEnabled()) throw XArch("system setting not enabled: \"Enable access for assistive devices\""); // install display manager notification handler #if defined(MAC_OS_X_VERSION_10_5) CGDisplayRegisterReconfigurationCallback(displayReconfigurationCallback, this); #else m_displayManagerNotificationUPP = NewDMExtendedNotificationUPP(displayManagerCallback); OSStatus err = GetCurrentProcess(&m_PSN); err = DMRegisterExtendedNotifyProc(m_displayManagerNotificationUPP, this, 0, &m_PSN); #endif // install fast user switching event handler EventTypeSpec switchEventTypes[2]; switchEventTypes[0].eventClass = kEventClassSystem; switchEventTypes[0].eventKind = kEventSystemUserSessionDeactivated; switchEventTypes[1].eventClass = kEventClassSystem; switchEventTypes[1].eventKind = kEventSystemUserSessionActivated; EventHandlerUPP switchEventHandler = NewEventHandlerUPP(userSwitchCallback); InstallApplicationEventHandler(switchEventHandler, 2, switchEventTypes, this, &m_switchEventHandlerRef); DisposeEventHandlerUPP(switchEventHandler); constructMouseButtonEventMap(); // watch for requests to sleep m_events->adoptHandler(m_events->forCOSXScreen().confirmSleep(), getEventTarget(), new TMethodEventJob<COSXScreen>(this, &COSXScreen::handleConfirmSleep)); // create thread for monitoring system power state. *m_pmThreadReady = false; LOG((CLOG_DEBUG "starting watchSystemPowerThread")); m_pmWatchThread = new CThread(new TMethodJob<COSXScreen> (this, &COSXScreen::watchSystemPowerThread)); } catch (...) { m_events->removeHandler(m_events->forCOSXScreen().confirmSleep(), getEventTarget()); if (m_switchEventHandlerRef != 0) { RemoveEventHandler(m_switchEventHandlerRef); } #if defined(MAC_OS_X_VERSION_10_5) CGDisplayRemoveReconfigurationCallback(displayReconfigurationCallback, this); #else if (m_displayManagerNotificationUPP != NULL) { DMRemoveExtendedNotifyProc(m_displayManagerNotificationUPP, NULL, &m_PSN, 0); } if (m_hiddenWindow) { ReleaseWindow(m_hiddenWindow); m_hiddenWindow = NULL; } if (m_userInputWindow) { ReleaseWindow(m_userInputWindow); m_userInputWindow = NULL; } #endif delete m_keyState; delete m_screensaver; throw; } // install event handlers m_events->adoptHandler(CEvent::kSystem, m_events->getSystemTarget(), new TMethodEventJob<COSXScreen>(this, &COSXScreen::handleSystemEvent)); // install the platform event queue m_events->adoptBuffer(new COSXEventQueueBuffer(m_events)); }
//------------------------------------------------------------------------ bool platform_support::init(unsigned width, unsigned height, unsigned flags) { if(m_specific->m_sys_format == pix_format_undefined) { return false; } m_window_flags = flags; // application EventTypeSpec eventType; EventHandlerUPP handlerUPP; eventType.eventClass = kEventClassApplication; eventType.eventKind = kEventAppQuit; handlerUPP = NewEventHandlerUPP(DoAppQuit); InstallApplicationEventHandler (handlerUPP, 1, &eventType, nil, nil); eventType.eventClass = kEventClassMouse; eventType.eventKind = kEventMouseDown; handlerUPP = NewEventHandlerUPP(DoMouseDown); InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); eventType.eventKind = kEventMouseUp; handlerUPP = NewEventHandlerUPP(DoMouseUp); InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); eventType.eventKind = kEventMouseDragged; handlerUPP = NewEventHandlerUPP(DoMouseDragged); InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); eventType.eventClass = kEventClassKeyboard; eventType.eventKind = kEventRawKeyDown; handlerUPP = NewEventHandlerUPP(DoKeyDown); InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); eventType.eventKind = kEventRawKeyUp; handlerUPP = NewEventHandlerUPP(DoKeyUp); InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); eventType.eventKind = kEventRawKeyRepeat; handlerUPP = NewEventHandlerUPP(DoKeyDown); // 'key repeat' is translated to 'key down' InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); WindowAttributes windowAttrs; Rect bounds; // window windowAttrs = kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowStandardHandlerAttribute; SetRect (&bounds, 0, 0, width, height); OffsetRect (&bounds, 100, 100); CreateNewWindow (kDocumentWindowClass, windowAttrs, &bounds, &m_specific->m_window); if(m_specific->m_window == nil) { return false; } // I assume the text is ASCII. // Change to kCFStringEncodingMacRoman, kCFStringEncodingISOLatin1, kCFStringEncodingUTF8 or what else you need. SetWindowTitleWithCFString (m_specific->m_window, CFStringCreateWithCStringNoCopy (nil, m_caption, kCFStringEncodingASCII, nil)); eventType.eventClass = kEventClassWindow; eventType.eventKind = kEventWindowClose; handlerUPP = NewEventHandlerUPP(DoWindowClose); InstallWindowEventHandler (m_specific->m_window, handlerUPP, 1, &eventType, this, NULL); eventType.eventKind = kEventWindowDrawContent; handlerUPP = NewEventHandlerUPP(DoWindowDrawContent); InstallWindowEventHandler (m_specific->m_window, handlerUPP, 1, &eventType, this, NULL); // Periodic task // Instead of an idle function I use the Carbon event timer. // You may decide to change the wait value which is currently 50 milliseconds. EventLoopRef mainLoop; EventLoopTimerUPP timerUPP; EventLoopTimerRef theTimer; mainLoop = GetMainEventLoop(); timerUPP = NewEventLoopTimerUPP (DoPeriodicTask); InstallEventLoopTimer (mainLoop, 0, 50 * kEventDurationMillisecond, timerUPP, this, &theTimer); m_specific->create_pmap(width, height, &m_rbuf_window); m_initial_width = width; m_initial_height = height; on_init(); on_resize(width, height); m_specific->m_redraw_flag = true; ShowWindow (m_specific->m_window); SetPortWindowPort (m_specific->m_window); return true; }
// TODO Unfinished, issue #1309. static void process_apple_events_new() { OSStatus handler_install_status; OSStatus handler_remove_status; OSStatus event_received; EventTypeSpec event_types[1]; // List of event types to handle. EventHandlerUPP handler_open_doc; EventHandlerRef handler_ref; // Reference for later removing the event handler. EventRef event_ref; // Event that caused ReceiveNextEvent to return. OSType ev_class; UInt32 ev_kind; EventTimeout timeout = 3.0; // number of ticks (1/60th of a second) VS("LOADER: AppleEvent - processing...\n"); // Event types we are interested in. event_types[0].eventClass = kCoreEventClass; event_types[0].eventKind = kAEOpenDocuments; // Carbon Event Manager requires convert the function pointer to type EventHandlerUPP. // https://developer.apple.com/legacy/library/documentation/Carbon/Conceptual/Carbon_Event_Manager/Tasks/CarbonEventsTasks.html handler_open_doc = NewEventHandlerUPP(do_filenames_conversion_to_argv); // Install the event handler. // InstallApplicationEventHandler is a macro for 'InstallEventHandler' where the event target // is Application. // We do not have any windows so having Application as event target should be fine. handler_install_status = InstallApplicationEventHandler(handler_open_doc, 1, event_types, NULL, &handler_ref); if (handler_install_status == noErr) { VS("LOADER: AppleEvent - installed handler.\n"); // TODO //ReceiveNextEvent(); //RunCurrentEventLoop(timeout); //RunApplicationEventLoop(); // Previous func WaitNextEvent() was deprecated and 32-bit only. // Func ReceiveNextEvent() is threadsafe and available even for 64-bit OS X. //gotEvent = WaitNextEvent(highLevelEventMask, &event, timeout, NULL); //event_received = ReceiveNextEvent(1, event_types, kEventDurationForever, true, &event_ref); //event_received = ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &event_ref); // TODO //handler_remove_status = RemoveEventHandler(handler_ref); /* if (event_received == noErr) { VS("LOADER: AppleEvent - received event.\n"); ev_class = GetEventClass(event_ref); ev_kind = GetEventKind(event_ref); VS("LOADER: AppleEvent - event type: %u\n", ev_kind); //if (GetEventKind(event_ref) == kAEOpenDocuments) if (ev_class == kCoreEventClass) { VS("LOADER: AppleEvent - right class.\n"); } ReleaseEvent(event_ref); } else { VS("LOADER: AppleEvent - ERROR receiving events code: %d\n", event_received); }*/ } else { VS("LOADER: AppleEvent - ERROR installing handler.\n"); } // Remove handler_ref reference when we are done with EventHandlerUPP. // Carbon Event Manager does not do this automatically. DisposeEventHandlerUPP(handler_open_doc) }