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 _glfwPlatformCloseWindow( void )
{
    if( _glfwWin.WindowFunctions != NULL )
    {
	    if( _glfwWin.WindowUPP != NULL )
	    {
	        DisposeEventHandlerUPP( _glfwWin.WindowUPP );
	        _glfwWin.WindowUPP = NULL;
	    }

	    _glfwWin.WindowFunctions->CloseWindow();

	    if( _glfwWin.AGLContext != NULL )
	    {
		    aglSetCurrentContext( NULL );
		    aglSetDrawable( _glfwWin.AGLContext, NULL );
		    aglDestroyContext( _glfwWin.AGLContext );
		    _glfwWin.AGLContext = NULL;
		}

    	if( _glfwWin.MacWindow != NULL )
    	{
		    ReleaseWindow( _glfwWin.MacWindow );
		    _glfwWin.MacWindow = NULL;
	    }

	    _glfwWin.WindowFunctions = NULL;
    }
}
// --------------------------------------------------------------------------------------
int main(void)
{
	WindowRef window;
	FourCharCode prefsWindowKind;
	
	initialize();		// initialization

	RunApplicationEventLoop();		// application event loop
	
									// finalization
	for (window = FrontNonFloatingWindow(); window != NULL; window = FrontNonFloatingWindow())
	{
		GetWindowProperty(window, kAppSignature, kPrefsWindowKindTag, sizeof(FourCharCode), 
							NULL, &prefsWindowKind);
		
		if (prefsWindowKind == kPrefsWindowKindDialog)
			ClosePrefsDialog(window);
		else	// kPrefsWindowKindWindow
		{
			HICommand closeCommand;
			
			closeCommand.attributes = 0;	// not from a menu, control, or window
			closeCommand.commandID = kHICommandClose;
			ProcessHICommand(&closeCommand);
		}
	}
	
	DisposeAEEventHandlerUPP(gOpenAppAEHandler);
	DisposeAEEventHandlerUPP(gQuitAppAEHandler);
	DisposeAEEventHandlerUPP(gViewsFontChangedAEHandler);
	DisposeEventHandlerUPP(gAppEventHandler);
	
	return 0;
}
// --------------------------------------------------------------------------------------
int main(void)
{
	WindowRef window;
	
	initialize();		// initialization

	RunApplicationEventLoop();		// application event loop
	
									// finalization
	for (window = FrontNonFloatingWindow(); window != NULL; window = FrontNonFloatingWindow())
	{
		if (GetWindowKind(window) == kDialogWindowKind)
			ClosePrefsDialog(GetDialogFromWindow(window));
		else	// kApplicationWindowKind
		{
			HICommand closeCommand;
			
			closeCommand.attributes = 0;	// not from a menu, control, or window
			closeCommand.commandID = kHICommandClose;
			ProcessHICommand(&closeCommand);
		}
	}
	
	DisposeAEEventHandlerUPP(gOpenAppAEHandler);
	DisposeAEEventHandlerUPP(gQuitAppAEHandler);
	DisposeAEEventHandlerUPP(gViewsFontChangedAEHandler);
	DisposeEventHandlerUPP(gAppEventHandler);
	
	return 0;
}
// --------------------------------------------------------------------------------------
void ClosePrefsDialog(DialogRef prefsDialog)
{
	ControlRef listBoxControl;
	ListHandle iconList;
	
	HideWindow(GetDialogWindow(prefsDialog));
	GetDialogItemAsControl(prefsDialog, iIconList, &listBoxControl);
	GetControlData(listBoxControl, kControlEntireControl, kControlListBoxListHandleTag, 
					sizeof(ListHandle), &iconList, NULL);
	ReleaseIconListIcons(iconList);
	DisposeEventHandlerUPP(gDialogEventHandler);
	DisposeEventHandlerUPP(gListBoxControlEventHandler);
	RegisterListDefinition(kIconListLDEF, NULL);	// unregister the list definition
	DisposeDialog(prefsDialog);
	EnableMenuItem(GetMenuRef(mDemonstration), iPrefsDialog);
}
Exemple #6
0
bool unloadPlayerWin()
{
    ControlRef cRef;
    ControlID cID;
    OSStatus iErr;

    cID.signature = FOUR_CHAR_CODE('volu');
    cID.id = 6;
    if (noErr != (iErr = GetControlByID(g_refPlayerWin, &cID, &cRef)))
    {
        /* We don't return false here since this is always called on the way out. */
        fprintf(stderr, "unloadPlayerWin() - GetControlByID() failed, returning %lu!\n", (unsigned long) iErr);
    }
    else
    {
        SetControlAction(cRef, (ControlActionUPP) -1);        
    }
    
    HideWindow(g_refPlayerWin);
    RemoveEventHandler(g_refSeekHdlr);
    RemoveEventHandler(g_refPlayerHdlr);
    DisposeWindow(g_refPlayerWin);
    DisposeEventHandlerUPP(g_lpfnPlayerProc);
    DisposeControlActionUPP(g_lpfnVolumeProc);

    return true;
}
Exemple #7
0
bool unloadInfoWin()
{
    DataBrowserCallbacks dbc;
    ControlRef cRef;
    ControlID cID;

    cID.signature = FOUR_CHAR_CODE('tags');
    cID.id = 16;
    if (noErr == GetControlByID(g_refInfoWin, &cID, &cRef))
    {
        dbc.version = kDataBrowserLatestCallbacks;
        if (noErr == InitDataBrowserCallbacks(&dbc))
        {
            SetDataBrowserCallbacks(cRef, &dbc);
        }
    }

    clearInfoWin();

    HideWindow(g_refInfoWin);
    RemoveEventHandler(g_refInfoHdlr);
    DisposeWindow(g_refInfoWin);
    DisposeEventHandlerUPP(g_lpfnInfoProc);
    DisposeDataBrowserItemDataUPP(g_lpfnGSIDProc);

    /* Clean up any previous contents */
    
    return true;
}
Exemple #8
0
static void
setup_menu_event_handler (void)
{
  static gboolean is_setup = FALSE;

  EventHandlerUPP menu_event_handler_upp;
  EventHandlerRef menu_event_handler_ref;
  const EventTypeSpec menu_events[] = {
    { kEventClassCommand, kEventCommandProcess },
    { kEventClassMenu, kEventMenuTargetItem },
    { kEventClassMenu, kEventMenuOpening },
    { kEventClassMenu, kEventMenuClosed }
  };

  if (is_setup)
    return;

  /* FIXME: We might have to install one per window? */

  menu_event_handler_upp = NewEventHandlerUPP (menu_event_handler_func);
  InstallEventHandler (GetApplicationEventTarget (), menu_event_handler_upp,
		       GetEventTypeCount (menu_events), menu_events, 0,
		       &menu_event_handler_ref);

#if 0
  /* FIXME: Remove the handler with: */
  RemoveEventHandler(menu_event_handler_ref);
  DisposeEventHandlerUPP(menu_event_handler_upp);
#endif

  is_setup = TRUE;
}
Exemple #9
0
bool unloadAboutWin()
{
    HideWindow(g_refAboutWin);
    RemoveEventHandler(g_refAboutHdlr);
    DisposeWindow(g_refAboutWin);
    DisposeEventHandlerUPP(g_lpfnAboutProc);
    return true;
}
Exemple #10
0
//-----------------------------------------------------------------------------
// wxDockTaskBarIcon Destructor
//
// Cleans up mac events and restores the old icon to the dock
//-----------------------------------------------------------------------------
wxDockTaskBarIcon::~wxDockTaskBarIcon()
{
    // clean up event handler and event UPP
    RemoveEventHandler(m_eventHandlerRef);
    DisposeEventHandlerUPP(m_eventupp);

    // restore old icon and menu to the dock
    RemoveIcon();
}
Exemple #11
0
bool8 NPServerDialog (void)
{
	OSStatus	err;
	IBNibRef	nibRef;

	npserver.dialogcancel = true;

	err = CreateNibReference(kMacS9XCFString, &nibRef);
	if (err == noErr)
	{
		WindowRef	tWindowRef;

		err = CreateWindowFromNib(nibRef, CFSTR("ClientList"), &tWindowRef);
		if (err == noErr)
		{
			EventHandlerRef		eref;
			EventLoopTimerRef	tref;
			EventHandlerUPP		eventUPP;
			EventLoopTimerUPP	timerUPP;
			EventTypeSpec		windowEvents[] = { { kEventClassCommand, kEventCommandProcess      },
												   { kEventClassCommand, kEventCommandUpdateStatus } };
			HIViewRef			ctl;
			HIViewID			cid = { 'Chse', 0 };

			npserver.dialogprocess = kNPSDialogInit;

			eventUPP = NewEventHandlerUPP(NPServerDialogEventHandler);
			err = InstallWindowEventHandler(tWindowRef, eventUPP, GetEventTypeCount(windowEvents), windowEvents, (void *) tWindowRef, &eref);

			timerUPP = NewEventLoopTimerUPP(NPServerDialogTimerHandler);
			err = InstallEventLoopTimer(GetCurrentEventLoop(), 0.0f, 0.1f, timerUPP, (void *) tWindowRef, &tref);

			HIViewFindByID(HIViewGetRoot(tWindowRef), cid, &ctl);
			HIViewSetVisible(ctl, false);

			MoveWindowPosition(tWindowRef, kWindowServer, false);
			ShowWindow(tWindowRef);
			err = RunAppModalLoopForWindow(tWindowRef);
			HideWindow(tWindowRef);
			SaveWindowPosition(tWindowRef, kWindowServer);

			err = RemoveEventLoopTimer(tref);
			DisposeEventLoopTimerUPP(timerUPP);

			err = RemoveEventHandler(eref);
			DisposeEventHandlerUPP(eventUPP);

			CFRelease(tWindowRef);
		}

		DisposeNibReference(nibRef);
	}

	return (!npserver.dialogcancel);
}
MacOpMessageLoop::~MacOpMessageLoop()
{
	if (mHandlerRef)
	{
		RemoveEventHandler(mHandlerRef);
	}
	if (mHandlerUPP)
	{
		DisposeEventHandlerUPP(mHandlerUPP);
	}
}
Exemple #13
0
int _glfwPlatformTerminate( void )
{
    if( _glfwWin.MouseUPP != NULL )
    {
        DisposeEventHandlerUPP( _glfwWin.MouseUPP );
        _glfwWin.MouseUPP = NULL;
    }
    if( _glfwWin.CommandUPP != NULL )
    {
        DisposeEventHandlerUPP( _glfwWin.CommandUPP );
        _glfwWin.CommandUPP = NULL;
    }
    if( _glfwWin.KeyboardUPP != NULL )
    {
        DisposeEventHandlerUPP( _glfwWin.KeyboardUPP );
        _glfwWin.KeyboardUPP = NULL;
    }
    
    return GL_TRUE;
}
Exemple #14
0
void exit_mouse(
	short type)
{
	(void) (type);

	RemoveEventHandler(_CEMouseTracker);
	_CEMouseTracker = NULL;
	DisposeEventHandlerUPP(_CEMouseTrackerUPP);
	_CEMouseTrackerUPP = NULL;
	MPDeleteCriticalRegion(CE_MouseLock);
	CE_MouseLock = NULL;
}
void
QMacInputContext::cleanup()
{
    if(input_proc_handler) {
        RemoveEventHandler(input_proc_handler);
        input_proc_handler = 0;
    }
    if(input_proc_handlerUPP) {
        DisposeEventHandlerUPP(input_proc_handlerUPP);
        input_proc_handlerUPP = 0;
    }
}
Exemple #16
0
bool loadAboutWin()
{
    IBNibRef nibFile;
    OSStatus iResult;
    EventTypeSpec pEvent;

    g_lpfnAboutProc = NewEventHandlerUPP(aboutEvtHandler);

    if (noErr != (iResult = CreateNibReference(CFSTR("AboutWin"), &nibFile)))
    {
        DisposeEventHandlerUPP(g_lpfnAboutProc);
        fprintf(stderr, "loadAboutWin() - CreateNibReference(AboutWin) failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }

    if (noErr != (iResult = CreateWindowFromNib(nibFile, CFSTR("FroggAboutWindow"), &g_refAboutWin)))
    {
        DisposeNibReference(nibFile);
        DisposeEventHandlerUPP(g_lpfnAboutProc);
        fprintf(stderr, "loadAboutWin() - CreateWindowFromNib(FroggAboutWindow) failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }

    DisposeNibReference(nibFile);

    pEvent.eventClass = kEventClassWindow;
    pEvent.eventKind = kEventWindowClose;

    if (noErr != (iResult = InstallWindowEventHandler(g_refAboutWin, g_lpfnAboutProc, 1, &pEvent, NULL, &g_refAboutHdlr)))
    {
        DisposeWindow(g_refAboutWin);
        DisposeEventHandlerUPP(g_lpfnAboutProc);
        fprintf(stderr, "loadAboutWin() - InstallWindowEventHandler() failed, returning %lu!\n", (unsigned long) iResult);
        return false;
    }

    g_bLoaded = true;

    return true;
}
Exemple #17
0
void QuartzWindow::close() {
  if (!is_open())
    return;
  CGrafPtr gp = GetWindowPort(my_window());
  if (gp != NULL) // already closed by std handler
    QDEndCGContext( gp, &myContext );
  CGColorRelease((CGColorRef) _red);
  CGColorRelease((CGColorRef) _yellow);
  CGColorRelease((CGColorRef) _black);
  CGColorRelease((CGColorRef) _gray);
  CGColorRelease((CGColorRef) _white);
  CGColorSpaceRelease(_color_space);
  WindowSet::rm_window(my_window());
  if (gp != NULL)
    DisposeWindow(my_window());
  _is_open = false; 
  DisposeEventHandlerUPP(_my_event_handler_upp);
  DisposeEventHandlerUPP(_my_spy_event_handler_upp);
  _my_event_handler = NULL;
  _my_spy_event_handler = NULL;
  _quartz_win = NULL;
}
void
QMacInputContext::cleanup()
{
#ifndef QT_MAC_USE_COCOA
    if(input_proc_handler) {
        RemoveEventHandler(input_proc_handler);
        input_proc_handler = 0;
    }
    if(input_proc_handlerUPP) {
        DisposeEventHandlerUPP(input_proc_handlerUPP);
        input_proc_handlerUPP = 0;
    }
#endif
}
Exemple #19
0
void doloop(void)
{
	EventHandlerRef		menu_event;
	EventHandlerUPP		menu_upp;
	EventTypeSpec		app_menu_events[]={{kEventClassCommand,kEventProcessCommand}};
	
	menu_upp=NewEventHandlerUPP(app_event_menu);						   
	InstallEventHandler(GetApplicationEventTarget(),menu_upp,GetEventTypeCount(app_menu_events),app_menu_events,NULL,&menu_event);
	
	RunApplicationEventLoop();

	RemoveEventHandler(menu_event);
	DisposeEventHandlerUPP(menu_upp);
}
Exemple #20
0
void VSTEffectDialog::RemoveHandler()
{
#if defined(__WXMAC__)
   if (mHandlerRef) {
      ::RemoveEventHandler(mHandlerRef);
      mHandlerRef = NULL;
      MacInstallTopLevelWindowEventHandler();
   }

   if (mHandlerUPP) {
      DisposeEventHandlerUPP(mHandlerUPP);
      mHandlerUPP = NULL;
   }
#endif
}
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);
		}
	}
}
void CSMNativeWindow::resolveLinks(void)
{
    if(_pCarbWindow != NULL)
    {
        _pCarbWindow->setContext(NULL);
    }

    if(_pContext != NULL)
        aglDestroyContext(_pContext);

    if(_pLocalWindow != NULL)
        DisposeWindow(_pLocalWindow);

    if(_pEventHandler != NULL)
        DisposeEventHandlerUPP(_pEventHandler);

    Inherited::resolveLinks();
}
Exemple #23
0
void tool_wind_close(void)
{
	int			t;
	
	for ((t=0);(t!=maxtool);t++) {
		DisposeControl(tool_ctrl[t]);
	}
	
	DisposeControl(magnify_icon);
	DisposeControl(magnify_slider);
	DisposeControlActionUPP(magnify_proc);
	
	DisposeControl(group_combo);
	DisposeMenu(group_menu);

	RemoveEventHandler(tool_wind_event);
	DisposeEventHandlerUPP(tool_wind_upp);
	
	DisposeWindow(toolwind);
}
// --------------------------------------------------------------------------------------
void ClosePrefsWindow(WindowRef prefsWindow)
{
    ListHandle iconList;

    HideWindow(prefsWindow);
    DisableMenuItem(GetMenuRef(mFile), iClose);

    GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL,
                      &iconList);
    ReleaseIconListIcons(iconList);
    LDispose(iconList);
#if TARGET_API_MAC_CARBON
    DisposeListDefUPP(gIconListDef);
    DisposeEventHandlerUPP(gWindowEventHandler);
    DisposePrefsWindowHelpTags();
#endif
    DisposeWindow(prefsWindow);

    EnableMenuItem(GetMenuRef(mDemonstration), iPrefsWindow);
}
// Create, show and run modally our dialog window
OSStatus CreateDialogWindow()
{
    IBNibRef 		nibRef;
    EventTypeSpec 	dialogSpec = {kEventClassCommand, kEventCommandProcess };
    WindowRef 		dialogWindow;
    EventHandlerUPP	dialogUPP;
    OSStatus		err = noErr;

    // Find the dialog nib
    err = CreateNibReference(CFSTR("dialog"), &nibRef);
    require_noerr( err, CantFindDialogNib );

    // Load the window inside it
    err = CreateWindowFromNib(nibRef, CFSTR("dialog"), &dialogWindow);
    require_noerr( err, CantCreateDialogWindow );

    // We don't need the nib reference anymore.
    DisposeNibReference(nibRef);

    // Install our event handler
    dialogUPP =  NewEventHandlerUPP (DialogWindowEventHandler);
    err = InstallWindowEventHandler (dialogWindow, dialogUPP, 1, &dialogSpec, (void *) dialogWindow, NULL);
    require_noerr( err, CantInstallDialogHandler );

    // Show the window
    ShowWindow( dialogWindow );

    // Run modally
    RunAppModalLoopForWindow(dialogWindow);

    HideWindow(dialogWindow);
    DisposeWindow(dialogWindow);
    DisposeEventHandlerUPP(dialogUPP);

CantFindDialogNib:
CantCreateDialogWindow:
CantInstallDialogHandler:

    return err;
}
OSStatus PickMonitor (DisplayIDType *inOutDisplayID, WindowRef parentWindow)
{
	WindowRef theWindow;
	OSStatus status = noErr;
	static const ControlID	kUserPane 		= { 'MONI', 1 };
	
	// Fetch the dialog

	IBNibRef aslNib;
	CFBundleRef theBundle = CFBundleGetMainBundle();
	status = CreateNibReferenceWithCFBundle(theBundle, CFSTR("ASLCore"), &aslNib);
	status = ::CreateWindowFromNib(aslNib, CFSTR( "Pick Monitor" ), &theWindow );
	if (status != noErr)
	{
		assert(false);
		return userCanceledErr;
	}

#if 0
	// Put game name in window title. By default the title includes the token <<<kGameName>>>.

	Str255 windowTitle;
	GetWTitle(theWindow, windowTitle);
	FormatPStringWithGameName(windowTitle);
	SetWTitle(theWindow, windowTitle);
#endif
		
	// Set up the controls

	ControlRef monitorPane;
	GetControlByID( theWindow, &kUserPane, &monitorPane );
	assert(monitorPane);

	SetupPickMonitorPane(monitorPane, *inOutDisplayID);

	// Create our UPP and install the handler.

	EventTypeSpec cmdEvent = { kEventClassCommand, kEventCommandProcess };
	EventHandlerUPP handler = NewEventHandlerUPP( PickMonitorHandler );
	InstallWindowEventHandler( theWindow, handler, 1, &cmdEvent, theWindow, NULL );
	
	// Show the window

	if (parentWindow)
		ShowSheetWindow( theWindow, parentWindow );
	else
		ShowWindow( theWindow );

	// Now we run modally. We will remain here until the PrefHandler
	// calls QuitAppModalLoopForWindow if the user clicks OK or
	// Cancel.

	RunAppModalLoopForWindow( theWindow );

	// OK, we're done. Dispose of our window and our UPP.
	// We do the UPP last because DisposeWindow can send out
	// CarbonEvents, and we haven't explicitly removed our
	// handler. If we disposed the UPP, the Toolbox might try
	// to call it. That would be bad.

	TearDownPickMonitorPane(monitorPane);
	if (parentWindow)
		HideSheetWindow( theWindow );
	DisposeWindow( theWindow );
	DisposeEventHandlerUPP( handler );

	// Return settings to caller

	if (sSelectedDevice != 0)
	{
		// Read back the controls
		DMGetDisplayIDByGDevice (sSelectedDevice, &*inOutDisplayID, true);
		return noErr;
	}
	else
		return userCanceledErr;

}
Exemple #27
0
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));
}
	~Helper()
	{
		RemoveEventHandler( m_Handler );
		DisposeEventHandlerUPP( m_HandlerUPP );
	}
Exemple #29
0
Boolean MCScreenDC::close(Boolean force)
{
	if (m_dst_profile != nil)
	{
		CMCloseProfile(m_dst_profile);
		m_dst_profile = nil;
	}
	
	if (m_srgb_profile != nil)
	{
		CMCloseProfile(m_srgb_profile);
		m_srgb_profile = nil;
	}
	
	SetApplicationDockTileMenu(NULL);
	ReleaseMenu(f_icon_menu);
	DisposeEventHandlerUPP(s_icon_menu_event_handler_upp);
	f_icon_menu = NULL;
	s_icon_menu_event_handler_upp = NULL;
	showmenu(); //if the menu is hidden, show it.
	finalisebackdrop();
	DisposeRgn(mouseMoveRgn); //dispose the region crated in open()
	uint2 i;
	if (ncolors != 0)
	{
		int2 i;
		for (i = 0 ; i < ncolors ; i++)
		{
			if (colornames[i] != NULL)
				MCValueRelease(colornames[i]);
		}
		delete colors;
		delete colornames;
		delete allocs;
	}
	DisposeWindow((WindowPtr)invisibleWin);

	delete vis;
	delete mousewindow;
	delete activewindow;
	delete lastactivewindow;

	//TSM - closes down TSM for this app and removes appleevents
	AERemoveEventHandler(kTextServiceClass, kPos2Offset,
	                     TSMPositionToOffsetUPP, False);
	AERemoveEventHandler(kTextServiceClass, kOffset2Pos,
	                     TSMOffsetToPositionUPP, False);
	AERemoveEventHandler(kTextServiceClass, kUpdateActiveInputArea,
	                     TSMUpdateHandlerUPP, False);
	AERemoveEventHandler(kTextServiceClass, kUnicodeNotFromInputMethod,
	                     TSMUnicodeNotFromInputUPP, False);
	DisposeAEEventHandlerUPP(TSMPositionToOffsetUPP);
	DisposeAEEventHandlerUPP(TSMOffsetToPositionUPP);
	DisposeAEEventHandlerUPP(TSMUpdateHandlerUPP);
	DisposeAEEventHandlerUPP(TSMUnicodeNotFromInputUPP);
	closeIME();





	RemoveReceiveHandler(dragdropUPP, NULL);
	RemoveTrackingHandler(dragmoveUPP, NULL);
	DisposeDragTrackingHandlerUPP(dragmoveUPP);
	DisposeDragReceiveHandlerUPP(dragdropUPP);
	
	opened = False;
	return True;
}
OSStatus _Growl_ShowUpdatePromptForVersion(CFStringRef updateVersion) {
	OSStatus err = noErr;

	if (_checkOSXVersion()) {
		CFBundleRef bundle = CFBundleGetBundleWithIdentifier(GROWL_WITHINSTALLER_FRAMEWORK_IDENTIFIER);
		if (!bundle)
			NSLog(CFSTR("GrowlInstallationPrompt: could not locate framework bundle (forget about installing Growl); had looked for bundle with identifier '%@'"), GROWL_WITHINSTALLER_FRAMEWORK_IDENTIFIER);
		else {
			IBNibRef nib = NULL;
			err = CreateNibReferenceWithCFBundle(bundle, CFSTR("GrowlInstallationPrompt-Carbon"), &nib);
			if (err != noErr) {
				NSLog(CFSTR("GrowlInstallationPrompt: could not obtain nib: CreateNibReferenceWithCFBundle(%@, %@) returned %li"), bundle, CFSTR("GrowlInstallationPrompt-Carbon"), (long)err);
			} else {
				WindowRef window = NULL;

				err = CreateWindowFromNib(nib, CFSTR("Installation prompt"), &window);
				DisposeNibReference(nib);

				if (err != noErr) {
					NSLog(CFSTR("GrowlInstallationPrompt: could not obtain window from nib: CreateWindowFromNib(%p, %@) returned %li"), nib, CFSTR("Installation prompt"), (long)err);
				} else {
					OSStatus fillOutTextErr = _fillOutTextInWindow(window, (updateVersion != nil));
					OSStatus fillOutIconErr = _fillOutIconInWindow(window);

					err = (fillOutTextErr != noErr) ? fillOutTextErr : (fillOutIconErr != noErr) ? fillOutIconErr : noErr;
					if (err == noErr) {
						if (updateVersion) {
							//store the update version on the window.
							updateVersion = CFRetain(updateVersion);
							err = SetWindowProperty(window,
													GROWL_SIGNATURE,
													GIPC_UPDATE_VERSION,
													sizeof(updateVersion),
													&updateVersion);
							if (err != noErr)
								NSLog(CFSTR("GrowlInstallationPrompt: SetWindowProperty returned %li"), (long)err);
						}

						EventHandlerUPP handlerUPP = NewEventHandlerUPP(_handleCommandInWindow);

						struct EventTypeSpec types[] = {
							{ .eventClass = kEventClassCommand, .eventKind = kEventCommandProcess },
						};

						EventHandlerRef handler = NULL;
						err = InstallWindowEventHandler(window,
														handlerUPP,
														GetEventTypeCount(types),
														types,
														/*refcon*/ window,
														&handler);
						if (err != noErr)
							NSLog(CFSTR("GrowlInstallationPrompt: InstallWindowEventHandler returned %li"), (long)err);
						else {
							HIViewID chasingArrowsID = { GROWL_SIGNATURE, chasingArrowsIDNumber };
							HIViewRef chasingArrows = NULL;

							//stop and hide the chasing arrows, until the user clicks Install.
							OSStatus chasingArrowsErr = HIViewFindByID(HIViewGetRoot(window), chasingArrowsID, &chasingArrows);
							if (chasingArrowsErr == noErr) {
								Boolean truth = false;
								SetControlData(chasingArrows,
											   kControlEntireControl,
											   kControlChasingArrowsAnimatingTag,
											   sizeof(truth),
											   &truth);
								HIViewSetVisible(chasingArrows, false);
							}

							SelectWindow(window);
							ShowWindow(window);

							err = RunAppModalLoopForWindow(window);
							if (err != noErr)
								NSLog(CFSTR("GrowlInstallationPrompt: RunAppModalLoopForWindow(%p) returned %li"), window, (long)err);

							RemoveEventHandler(handler);
						}
						DisposeEventHandlerUPP(handlerUPP);
					}

					ReleaseWindow(window);
				}
			}
		}
	}