Exemple #1
0
// Event handling for window focus acquired events
pascal OSStatus
WindowFocusAcquired(EventHandlerCallRef nextHandler, EventRef theEvent, void* userData)
{
#pragma unused (nextHandler, userData)
	WindowRef window;
	OSStatus status = noErr;

	GetEventParameter(theEvent, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window);
	require_noerr( status, CantGetEventParameter);

	if ( window != NULL )
	{
		HIViewRef textView;
		status = GetTextViewFromWindow(window, textView);
		
		if ( status == noErr )
		{
			UniChar mark; // For checking menu items

			// Handle font panel menu item and palette
			if ( TextViewIsFontPanelSupportEnabled(textView) ) {
				EnableMenuCommand(NULL, kHICommandShowHideFontPanel);
				if ( ! FPIsFontPanelVisible() )
					verify_noerr( FPShowHideFontPanel() );
			} else {
				DisableMenuCommand(NULL, kHICommandShowHideFontPanel);
				if ( FPIsFontPanelVisible() )
					verify_noerr( FPShowHideFontPanel() );
			}
			
			// Handle spelling menu items
			if ( TextViewIsSpellingSupportEnabled(textView) ) {
				EnableMenuCommand(NULL, kHICommandShowSpellingPanel);
				EnableMenuCommand(NULL, kToggleAutoSpellcheckCommand);
				MyShowSpellCheckPanel();
			} else {
				DisableMenuCommand(NULL, kHICommandShowSpellingPanel);
				DisableMenuCommand(NULL, kToggleAutoSpellcheckCommand);
			}
				
			// Auto-spellcheck menu item
			mark = ( TXNGetSpellCheckAsYouType(HITextViewGetTXNObject(textView)) ) ? kMenuCheckmarkGlyph : kMenuNullGlyph;
			verify_noerr( SetMenuCommandMark(NULL, kToggleAutoSpellcheckCommand, mark) );
		}
	}

CantGetEventParameter:
	return status;
}
Exemple #2
0
OSStatus
TextViewFontPanelSupport( HIViewRef textView, Boolean on )
{
	OSStatus status = noErr;
	TXNCommandEventSupportOptions options = 0;
	TXNObject txnObj =  HITextViewGetTXNObject(textView);
	
	// Got TXNObject?
	require( txnObj != NULL, EXIT );

	// Get existing option settings...
	status = TXNGetCommandEventSupport( txnObj, &options );
	require_noerr( status, EXIT );
	
	// Add or subract font command support as requested,
	// (and enable/disable menu items appropriately)
	if( on )	
	{
		options |= kTXNSupportFontCommandProcessing;
		options |= kTXNSupportFontCommandUpdating;
		EnableMenuCommand(NULL, kHICommandShowHideFontPanel);
		if ( ! FPIsFontPanelVisible() )
			verify_noerr( FPShowHideFontPanel() );
		verify_noerr( SignalHelpMessage( HIViewGetWindow( textView ), CFSTR("FontPanelEnable") ));
	}
	else
	{
		if( options & kTXNSupportFontCommandProcessing )
			options ^= kTXNSupportFontCommandProcessing;
		if( options & kTXNSupportFontCommandUpdating )
			options ^= kTXNSupportFontCommandUpdating;
		DisableMenuCommand(NULL, kHICommandShowHideFontPanel);
		if ( FPIsFontPanelVisible() )
			verify_noerr( FPShowHideFontPanel() );
		verify_noerr( SignalHelpMessage( HIViewGetWindow( textView ), CFSTR("FontPanelDisable") ));
	}
	// reset modified options
	status = TXNSetCommandEventSupport(txnObj, options );
	verify_noerr( status );
	
	EXIT:
	;
	return status;
}
Exemple #3
0
OSStatus
TextViewDemoFontPanelSupport( HIViewRef textView )
{
	OSStatus status = paramErr;
	static const CFStringRef taskCFStr = CFSTR("TaskFontPanel");

	status = TextViewFontPanelSupport( textView, true );

	if ( ! FPIsFontPanelVisible() )
		verify_noerr( FPShowHideFontPanel() );

	verify_noerr( SignalHelpMessage( HIViewGetWindow( textView ), taskCFStr ) );
	return status; 
}
/*****************************************************
*
* Handle_CommandUpdateStatus(inHandlerCallRef, inEvent, inUserData) 
*
* Purpose:  called to update status of the commands, enabling or disabling the menu items
*
* Inputs:   inHandlerCallRef    - reference to the current handler call chain
*				inEvent             - the event
*           inUserData          - app-specified data you passed in the call to InstallEventHandler
*
* Returns:  OSStatus            - noErr indicates the event was handled
*                                 eventNotHandledErr indicates the event was not handled and the Toolbox should take over
*/
static pascal OSStatus Handle_CommandUpdateStatus(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
	{
	OSStatus status = eventNotHandledErr;
	
	HICommand aCommand;
	GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &aCommand);
	
	// Do we have a front window containing a HIATSUIView?
	WindowRef frontWindow;
	HIViewRef atsuiView;
	Get_FrontWindowAndATSUIView(&frontWindow, &atsuiView, false);
	
	// Do we have some selected text?
	Boolean textSelected = false;
	if (atsuiView != NULL)
		{
		UniCharArrayOffset start, end;
		HIATSUIViewGetSelection(atsuiView, &start, &end);
		textSelected = (start != end);
		}

	if (frontWindow == NULL)
		{
		// no window, let's disable all relevant menu items
		switch (aCommand.commandID)
			{
			case kHICommandSelectAll:
			case kHICommandCopy:
			case kHICommandClose:
				DisableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex);
				break;
			}
		}
	else
		{
		switch (aCommand.commandID)
			{
			// the "Copy" menu item is enabled only is some text is selected
			case kHICommandCopy:
				if (textSelected)
					EnableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex);
				else
					DisableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex);
				break;
			
			// the "Select All" menu item is enabled only if there is a HIATSUIView in the front window
			case kHICommandSelectAll:
				if (atsuiView != NULL)
					EnableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex);
				else
					DisableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex);
				break;
			
			// the "Close" menu item is enabled only if there is a window
			case kHICommandClose:
				EnableMenuItem(aCommand.menu.menuRef, aCommand.menu.menuItemIndex);
				break;
			}
		}
	
	// let's adjust the "Show/Hide Fonts" menu item title depending on the visibility of the Standard Font panel
	if (aCommand.commandID == kHICommandShowHideFontPanel)
		{
		CFStringRef menuItemString;
		if (FPIsFontPanelVisible())
			menuItemString = CFCopyLocalizedString( CFSTR("Hide Fonts"), CFSTR("") );
		else
			menuItemString = CFCopyLocalizedString( CFSTR("Show Fonts"), CFSTR("") );
		SetMenuItemTextWithCFString(aCommand.menu.menuRef, aCommand.menu.menuItemIndex, menuItemString);
		CFRelease(menuItemString);
		}

	return status;
	}   // Handle_CommandUpdateStatus