// --------------------------------------------------------------------------------------
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;
}
Exemple #2
0
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(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 DeinitAppleEvents(void)
{
	DisposeAEEventHandlerUPP(oappUPP);
	DisposeAEEventHandlerUPP(odocUPP);
	DisposeAEEventHandlerUPP(pdocUPP);
	DisposeAEEventHandlerUPP(quitUPP);
	DisposeAEEventHandlerUPP(rappUPP);
}
Exemple #5
0
void wxApp::CleanUp()
{
#if wxUSE_TOOLTIPS
    wxToolTip::RemoveToolTips() ;
#endif

#ifdef __WXMAC_OSX__
    if (m_macEventPosted)
    {
        CFRelease(m_macEventPosted);
    }
    m_macEventPosted = NULL;
#endif

    // One last chance for pending objects to be cleaned up
    wxTheApp->DeletePendingObjects();

    wxMacDestroyNotifierTable() ;

#ifndef __DARWIN__
#  if __option(profile)
    ProfilerDump( (StringPtr)"\papp.prof" ) ;
    ProfilerTerm() ;
#  endif
#endif

    UMACleanupToolbox() ;
    if (s_macCursorRgn) {
        ::DisposeRgn((RgnHandle)s_macCursorRgn);
    }

    if (!sm_isEmbedded)
    {
        RemoveEventHandler( (EventHandlerRef)(wxTheApp->m_macEventHandler) );
    }
	
    if (!sm_isEmbedded)
    {
        AERemoveEventHandler( kCoreEventClass , kAEOpenDocuments ,
                               sODocHandler , FALSE ) ;
        AERemoveEventHandler( kCoreEventClass , kAEOpenApplication ,
                               sOAppHandler , FALSE ) ;
        AERemoveEventHandler( kCoreEventClass , kAEPrintDocuments ,
                               sPDocHandler , FALSE ) ;
        AERemoveEventHandler( kCoreEventClass , kAEReopenApplication ,
                               sRAppHandler , FALSE ) ;
        AERemoveEventHandler( kCoreEventClass , kAEQuitApplication ,
                               sQuitHandler , FALSE ) ;
                               
        DisposeAEEventHandlerUPP( sODocHandler ) ;
        DisposeAEEventHandlerUPP( sOAppHandler ) ;
        DisposeAEEventHandlerUPP( sPDocHandler ) ;
        DisposeAEEventHandlerUPP( sRAppHandler ) ;
        DisposeAEEventHandlerUPP( sQuitHandler ) ;
    }

    wxAppBase::CleanUp();
}
// --------------------------------------------------------------------------------------
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;
}
Exemple #7
0
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*/
Exemple #8
0
AECoreClass::~AECoreClass()
{
	if (mSuspendEventHandlerUPP)
		DisposeAEEventHandlerUPP(mSuspendEventHandlerUPP);

	if (mStandardSuiteHandlerUPP)
		DisposeAEEventHandlerUPP(mStandardSuiteHandlerUPP);
		
	if (mRequiredSuiteHandlerUPP)
		DisposeAEEventHandlerUPP(mRequiredSuiteHandlerUPP);
			
	if (mMozillaSuiteHandlerUPP)
		DisposeAEEventHandlerUPP(mMozillaSuiteHandlerUPP);

	if (mGetURLSuiteHandlerUPP)
		DisposeAEEventHandlerUPP(mGetURLSuiteHandlerUPP);

	if (mSpyGlassSuiteHandlerUPP)
		DisposeAEEventHandlerUPP(mSpyGlassSuiteHandlerUPP);	
	
	if (mCreateElementHandlerUPP)
		DisposeAEEventHandlerUPP(mCreateElementHandlerUPP);
		
	if (mPropertyFromListAccessor)
		DisposeOSLAccessorUPP(mPropertyFromListAccessor);

	if (mAnythingFromAppAccessor)
		DisposeOSLAccessorUPP(mAnythingFromAppAccessor);

	if (mCountItemsCallback)
		DisposeOSLCountUPP(mCountItemsCallback);

	if (mCompareItemsCallback)
		DisposeOSLCompareUPP(mCompareItemsCallback);
}
Exemple #9
0
bool removeAEHandlers()
{
    AERemoveEventHandler(kCoreEventClass, kAEShowPreferences, g_lpfnAEProc, FALSE);
    AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments, g_lpfnAEProc, FALSE);
    AERemoveEventHandler(kCoreEventClass, kAEQuitApplication, g_lpfnAEProc, FALSE);
    DisposeAEEventHandlerUPP(g_lpfnAEProc);

    return true;
}
Exemple #10
0
extern "C" void SATerminate(void){
	if(SampleHandlerUPP){
		for(int i=0;i<gEventDescriptionCount;i++){
		    AERemoveEventHandler(gEventDescriptionList[i].theAEEventClass,gEventDescriptionList[i].theAEEventID,SampleHandlerUPP, true);
		}
		DisposeAEEventHandlerUPP(SampleHandlerUPP);
		SampleHandlerUPP=0;
	}
}
void QTApp_Stop (UInt32 theStopPhase)
{	
	// do any shut-down activities that should occur before the movie windows are destroyed
	if (theStopPhase & kStopAppPhase_BeforeDestroyWindows) {
		
	}
	
	// do any shut-down activities that should occur after the movie windows are destroyed
	if (theStopPhase & kStopAppPhase_AfterDestroyWindows) {
#if TARGET_OS_MAC
		// dispose of routine descriptors for Apple event handlers
		DisposeAEEventHandlerUPP(gHandleOpenAppAEUPP);
		DisposeAEEventHandlerUPP(gHandleOpenDocAEUPP);
		DisposeAEEventHandlerUPP(gHandlePrintDocAEUPP);
		DisposeAEEventHandlerUPP(gHandleQuitAppAEUPP);
#endif
	
	}
}
Exemple #12
0
static void
gui_unique_mac_exit (void)
{
  unique_gimp = NULL;

  AERemoveEventHandler (kCoreEventClass, kAEOpenDocuments,
                        open_document_callback_proc, TRUE);

  DisposeAEEventHandlerUPP(open_document_callback_proc);
}
Exemple #13
0
void wxApp::DoCleanUp()
{
    if (!sm_isEmbedded)
        RemoveEventHandler( (EventHandlerRef)(wxTheApp->m_macEventHandler) );

    if (!sm_isEmbedded)
    {
        AERemoveEventHandler( kCoreEventClass , kAEOpenDocuments ,
                               sODocHandler , FALSE ) ;
        AERemoveEventHandler( kInternetEventClass, kAEGetURL,
                               sGURLHandler , FALSE ) ;
        AERemoveEventHandler( kCoreEventClass , kAEOpenApplication ,
                               sOAppHandler , FALSE ) ;
        AERemoveEventHandler( kCoreEventClass , kAEPrintDocuments ,
                               sPDocHandler , FALSE ) ;
        AERemoveEventHandler( kCoreEventClass , kAEReopenApplication ,
                               sRAppHandler , FALSE ) ;
        AERemoveEventHandler( kCoreEventClass , kAEQuitApplication ,
                               sQuitHandler , FALSE ) ;

        DisposeAEEventHandlerUPP( sODocHandler ) ;
        DisposeAEEventHandlerUPP( sGURLHandler ) ;
        DisposeAEEventHandlerUPP( sOAppHandler ) ;
        DisposeAEEventHandlerUPP( sPDocHandler ) ;
        DisposeAEEventHandlerUPP( sRAppHandler ) ;
        DisposeAEEventHandlerUPP( sQuitHandler ) ;
    }
}
// --------------------------------------------------------------------------------------
int main(void)
{
	WindowRef window;
	
	initialize();		// initialization

	gDone = false;
	while (!gDone)		// application event loop
	{
		EventRecord event;
		
		if (WaitNextEvent(everyEvent, &event, ULONG_MAX, NULL))
		{
			if (IsDialogEvent(&event))
				HandleDialogEvents(&event);
			else
				handleEvents(&event);
		}
		else
			doIdleProcessing();
	}
									// finalization
	for (window = FrontNonFloatingWindow(); window != NULL; window = FrontNonFloatingWindow())
	{
		if (GetWindowKind(window) == kDialogWindowKind)
			ClosePrefsDialog(GetDialogFromWindow(window));
		else	// kApplicationWindowKind
			ClosePrefsWindow(window);
	}
	
	DisposeAEEventHandlerUPP(gOpenAppAEHandler);
	DisposeAEEventHandlerUPP(gQuitAppAEHandler);
	DisposeAEEventHandlerUPP(gViewsFontChangedAEHandler);
	
	return 0;
}
Exemple #15
0
Word BURGERCALL SystemProcessFilenames(SystemProcessCallBackProc Proc) 
{
	long result;				/* Gestalt temp */
	Word OldFlag;				/* Previous MacSystemTaskFlag */
	AEEventHandlerUPP OpenFileProc;		/* Current proc pointer */
	AEEventHandlerUPP PrevFileProc;		/* Previous proc pointer */
	long PrevRefCon;				/* Previous proc refcon */
	OSErr PrevErr;					/* Error getting the previous event handler */
	Foo_t FooData;					/* Data state */

	FooData.Result = TRUE;					/* Nothing processed */
	FooData.Proc = Proc;

	if (Proc && !Gestalt(gestaltAppleEventsAttr,&result)) {	/* Do I have apple events? */
		OpenFileProc = NewAEEventHandlerUPP(HandleOdoc);	/* Get the file */
		if (OpenFileProc) {
			Word i;
			
			/* Install the event handler */
			PrevErr = AEGetEventHandler(kCoreEventClass,kAEOpenDocuments,&PrevFileProc,&PrevRefCon,FALSE);
			AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,OpenFileProc,(long)&FooData, FALSE);
			i = 50;
			OldFlag = MacSystemTaskFlag;		/* Save */
			MacSystemTaskFlag = TRUE;			/* I WANT SystemTask() to be called */
			do {
				KeyboardGet();					/* Give some time to MacOS */
			} while (--i);
			MacSystemTaskFlag = OldFlag;	/* Restore the flag */
			AERemoveEventHandler(kCoreEventClass,kAEOpenDocuments,OpenFileProc,FALSE);
			DisposeAEEventHandlerUPP(OpenFileProc);	/* Kill my routine */
			if (!PrevErr) {
				AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,PrevFileProc,PrevRefCon, FALSE);
			}
		}
	}
	return FooData.Result;
}
Exemple #16
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;
}
// --------------------------------------------------------------------------------------
static pascal OSErr openApplicationAEHandler(const AppleEvent *appleEvent, AppleEvent *reply, 
												long 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)
	{
		MenuRef menu;
		CFStringRef aboutString;
		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);
		
#if TARGET_API_MAC_OSX
#pragma unused (reply, refcon)
		menu = GetMenuRef(mAppleApplication);
		aboutString = CFCopyLocalizedString(CFSTR("About Item"), NULL);
		SetMenuItemTextWithCFString(menu, iAbout, aboutString);		// get rid of the "..."
		CFRelease(aboutString);									// if we're running in OS X
		
		menu = GetMenuRef(mFile);
		ChangeMenuAttributes(menu, kMenuAttrAutoDisable, 0);
		DeleteMenuItem(menu, iQuit);				// remove the Quit item and separator
		DeleteMenuItem(menu, iQuitSeparator);		// if we're running in OS X
#else
#pragma unused (reply, refcon, menu, aboutString)
#endif
		
		gAppEventHandler = NewEventHandlerUPP(appEventHandler);
		InstallApplicationEventHandler(gAppEventHandler, GetEventTypeCount(applicationEvents), 
										applicationEvents, NULL, NULL);
		
		InitIconDataBrowser();
		
		error = noErr;
	}
	
	return error;
}