コード例 #1
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus
TextViewEditCommandSupport( 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 subtract edit command support as requested
	if( on )	
	{
		options |= kTXNSupportEditCommandProcessing;
		options |= kTXNSupportEditCommandUpdating;
	}
	else
	{
		if( options & kTXNSupportEditCommandProcessing )
			options ^= kTXNSupportEditCommandProcessing;
		if( options & kTXNSupportEditCommandUpdating )
			options ^= kTXNSupportEditCommandUpdating;
	}
	// reset modified options
	status = TXNSetCommandEventSupport(txnObj, options );
	verify_noerr( status );
	
	EXIT:
	;
	return status;
}
コード例 #2
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus
TextViewDefaultSettings( HIViewRef textView )
{
	OSStatus status = paramErr;
	static const CFStringRef taskCFStr = CFSTR("TaskDefault");
	WindowRef window;
	
	status = AddTextToTheTextView( textView );
	check_noerr( status );
	status = TextViewEditCommandSupport( textView, true );
	check_noerr( status );
	status = TextViewFontPanelSupport( textView, false );
	check_noerr( status );
	status = TextViewSpellingSupport( textView, false );
	check_noerr( status );
	status = TextViewScrollingOptions( textView, (UInt32)kTXNAutoScrollInsertionIntoView );
	check_noerr( status );
	status = TXNSetSelection(HITextViewGetTXNObject(textView), kTXNStartOffset, kTXNStartOffset);
	check_noerr( status );
	status = HIScrollViewNavigate(HIViewGetSuperview(textView),kHIScrollViewScrollToTop) ;
	check_noerr( status );

	status = SignalHelpMessage( HIViewGetWindow( textView ), taskCFStr );

	return status;
}
コード例 #3
0
//---------------------------------------------------------------------
// Sets some default options in our main text view.
//
OSStatus MySetTextViewOptions(HIViewRef textView)
{
	TXNCommandEventSupportOptions options;
	TXNObject txnObj;
	OSStatus status;

	// We are setting options that must be set in the
	// underlying MLTE object, so get a reference to it
	txnObj = HITextViewGetTXNObject(textView);
	require( (txnObj != NULL), CantGetTXNObject );

	// Get the previous options
	status = TXNGetCommandEventSupport(txnObj, &options);
	require_noerr( status, CantGetCommandOptions );

	// Add the font panel support options
	options |= kTXNSupportFontCommandProcessing;
	options |= kTXNSupportFontCommandUpdating;

	// Add the spelling panel support options
	options |= kTXNSupportSpellCheckCommandProcessing;
	options |= kTXNSupportSpellCheckCommandUpdating;

	// Apply above changes to the object
	status = TXNSetCommandEventSupport(txnObj, options);
	require_noerr( status, CantSetCommandOptions );

CantSetCommandOptions:
CantGetCommandOptions:
CantGetTXNObject:
	return status;
}
コード例 #4
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus
TextViewReadCFURL( HIViewRef textView, CFURLRef cfURL )
{
	OSStatus status = paramErr;
	CFDictionaryRef dataOptions = NULL;
	static const CFStringRef taskCFStr = CFSTR("TaskReadCFURL");
	static const CFStringRef taskErrorCFStr = CFSTR("TaskReadCFURLError");

	status = TXNReadFromCFURL( HITextViewGetTXNObject(textView),
							kTXNStartOffset, kTXNEndOffset,
							dataOptions,
							cfURL,
							NULL /*docAttributes*/ );
	if( status != noErr )
	{
		WarnStatusString( "TXNReadFromCFURL returned: %lu ", status );
		SignalHelpMessage( HIViewGetWindow( textView ), taskErrorCFStr );
	}
	else
	{
		CMLTEViewData* mlteData = NULL;
		SignalHelpMessage( HIViewGetWindow( textView ), taskCFStr );
		HIViewSetNeedsDisplay( textView, true );
	
		// in some scenarios, it is useful to remember where we got the file
		// data from at a later time, so save the URL in our custom instance data object
		mlteData = TextViewRetrieveMLTEInstanceData( textView );
		if( mlteData != NULL )
			mlteData->SetURL( cfURL );
	}
	
	return status;
}
コード例 #5
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus
TextViewSpellCheckAsYouType( HIViewRef textView, Boolean enable )
{
	UniChar mark = ( enable ) ? kMenuCheckmarkGlyph : kMenuNullGlyph;
	verify_noerr( SetMenuCommandMark(NULL, kToggleAutoSpellcheckCommand, mark) );
	return TXNSetSpellCheckAsYouType( HITextViewGetTXNObject(textView), enable );
}
コード例 #6
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus
TextViewAddActionNameMapper( HIViewRef textView )
{
	if( gActionNameMapperUPP == NULL )
		gActionNameMapperUPP = NewTXNActionNameMapperUPP( MyActionNameMapperCallback );
		
	return TXNSetActionNameMapper( HITextViewGetTXNObject(textView), gActionNameMapperUPP, NULL /*userData*/ );
}
コード例 #7
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus
TextViewSetFontStyleOfThisRange( HIViewRef textView, UInt32 setStyle, TXNOffset startRng, TXNOffset endRng )
{
	TXNTypeAttributes typeAttr[] = {{kTXNQDFontStyleAttribute, kTXNQDFontStyleAttributeSize,
									{0}}};
	typeAttr[0].data.dataValue = setStyle;
	return TXNSetTypeAttributes( HITextViewGetTXNObject(textView), 1, typeAttr, startRng, endRng );
}
コード例 #8
0
ファイル: carbon_gui.cpp プロジェクト: dyne/MuSE
/* initialize the status window (used to show console messages in the graphic environment */
void CARBON_GUI::setupStatusWindow() 
{
	OSStatus err=CreateWindowFromNib(nibRef,CFSTR("StatusWindow"),&statusWindow);
	if(err!=noErr) msg->error("Can't create status window (%d)!!",err);
	//SetDrawerParent(statusWindow,window);
	//SetDrawerPreferredEdge(statusWindow,kWindowEdgeBottom);
	//SetDrawerOffsets(statusWindow,20,20);
	
	/* install an eventHandler to intercept close requests */
	err = InstallWindowEventHandler (statusWindow, 
		NewEventHandlerUPP (StatusWindowEventHandler), 
		GetEventTypeCount(statusEvents), statusEvents, this, NULL);
	if(err != noErr) msg->error("Can't install status window eventHandler");
	
	/* and then install a command handler (to handle "clear" requests) */
	err=InstallWindowEventHandler(statusWindow,NewEventHandlerUPP(StatusWindowCommandHandler),
		GetEventTypeCount(commands),commands,this,NULL);
		
	/* obtain an HIViewRef for the status text box ... we have to use it 
	 * to setup various properties and to obain a TXNObject needed to manage its content */
	const ControlID txtid={ CARBON_GUI_APP_SIGNATURE, STATUS_TEXT_ID };
	err= HIViewFindByID(HIViewGetRoot(statusWindow), txtid, &statusTextView);
	if(err!=noErr) return;// msg->warning("Can't get textView for status window (%d)!!",err);
	statusText = HITextViewGetTXNObject(statusTextView);
	if(!statusText) {
		msg->error("Can't get statusText object from status window!!");
	}
//	TXNControlTag iControlTags[1] = { kTXNAutoScrollBehaviorTag };
//	TXNControlData iControlData[1] = { kTXNAutoScrollNever }; //kTXNAutoScrollWhenInsertionVisible };
//	err = TXNSetTXNObjectControls(statusText,false,1,iControlTags,iControlData);
	//TextViewSetObjectControlData
	//TextViewSetObjectControlData(statusText,kTXNAutoScrollBehaviorTag,kUn kTXNAutoScrollWhenInsertionVisible)
	/* setup status text font size and color */
	// Create type attribute data structure
	UInt32   fontSize = 10 << 16; // needs to be in Fixed format
	TXNAttributeData fsData,fcData;
	fsData.dataValue=fontSize;
	fcData.dataPtr=(void *)&black;
	TXNTypeAttributes attributes[] = {
		//{ kTXNQDFontStyleAttribute, kTXNQDFontStyleAttributeSize, bold },
		{ kTXNQDFontColorAttribute, kTXNQDFontColorAttributeSize,fcData}, //&lgrey },
		{ kTXNQDFontSizeAttribute, kTXNFontSizeAttributeSize,fsData }
	};
	err= TXNSetTypeAttributes( statusText, 2, attributes,
		kTXNStartOffset,kTXNEndOffset );
		
	/* block user input in the statusText box */
	TXNControlTag tags[] = { kTXNNoUserIOTag };
	TXNControlData vals[] = { kTXNReadOnly };
	err=TXNSetTXNObjectControls(statusText,false,1,tags,vals);
	if(err!=noErr) msg->error("Can't set statusText properties (%d)!!",err);
	// TXNSetScrollbarState(statusText,kScrollBarsAlwaysActive);
		
	//struct TXNBackground bg = {  kTXNBackgroundTypeRGB, black };
	//TXNSetBackground(statusText,&bg);
}
コード例 #9
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus
TextViewSetupSpellingContextualMenu( HIViewRef textView )
{
	if( gContextualMenuUPP == NULL )
		gContextualMenuUPP = NewTXNContextualMenuSetupUPP( MyContextualMenuCallback );

	return TXNSetContextualMenuSetup( HITextViewGetTXNObject(textView),
										gContextualMenuUPP,
										NULL /*userData*/ );
}
コード例 #10
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus
TextViewIncrementFontSizeOfThisRange( HIViewRef textView,
									  TXNOffset startRng, TXNOffset endRng,
									  Boolean incrementUp, UInt32 count = 1 /*unused*/ )
{
    SInt32 direction =  incrementUp?kTXNIncrementTypeSize:kTXNDecrementTypeSize;
    
	TXNTypeAttributes	typeAttr[] = {{kTXNQDFontSizeAttribute, kTXNQDFontSizeAttributeSize,
										{0}}};
	typeAttr[0].data.dataValue = direction;
	return TXNSetTypeAttributes( HITextViewGetTXNObject(textView), 1, typeAttr, startRng, endRng );
}
コード例 #11
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus
TextViewSpellingSupport( 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 subtract spelling support as requested
	// (and enable/disable menu items appropriately)
	if( on )	
	{
		options |= kTXNSupportSpellCheckCommandProcessing;
		options |= kTXNSupportSpellCheckCommandUpdating;
		EnableMenuCommand(NULL, kHICommandShowSpellingPanel);
		EnableMenuCommand(NULL, kToggleAutoSpellcheckCommand);
		verify_noerr( SignalHelpMessage( HIViewGetWindow( textView ), CFSTR("SpellSupportEnable") ));
	}
	else
	{
		if( options & kTXNSupportSpellCheckCommandProcessing )
			options ^= kTXNSupportSpellCheckCommandProcessing;
		if( options & kTXNSupportSpellCheckCommandUpdating )
			options ^= kTXNSupportSpellCheckCommandUpdating;
		DisableMenuCommand(NULL, kHICommandShowSpellingPanel);
		DisableMenuCommand(NULL, kToggleAutoSpellcheckCommand);
		verify_noerr( SignalHelpMessage( HIViewGetWindow( textView ), CFSTR("SpellSupportDisable") ));
	}

	// Set auto spell check state accordingly
	status = TextViewSpellCheckAsYouType(textView, on);
	verify_noerr( status );

	// reset modified options
	status = TXNSetCommandEventSupport(txnObj, options);
	verify_noerr( status );
	
	HIViewSetNeedsDisplay( textView, true );

	EXIT:
	;
	return status;
}
コード例 #12
0
ファイル: main.cpp プロジェクト: arnelh/Examples
// 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;
}
コード例 #13
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus
TextViewSetObjectControlData( HIViewRef textView, TXNControlTag controlTag, Boolean isSigned, 
                                 SInt32 iSignedData, UInt32 iUnsignedData )
{
    OSStatus status = noErr;
    
	TXNControlTag iControlTags[1] = {controlTag};
	TXNControlData iControlData[1];
	if( isSigned )
		iControlData[0].sValue = (SInt32)iSignedData;
	else
		iControlData[0].uValue = (UInt32)iUnsignedData;

	return TXNSetTXNObjectControls( HITextViewGetTXNObject(textView), false, 1, iControlTags, iControlData );
}
コード例 #14
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
Boolean
TextViewIsFontPanelSupportEnabled( HIViewRef textView )
{
	Boolean state = false;
	TXNCommandEventSupportOptions options = 0;
	TXNObject txnObj =  HITextViewGetTXNObject(textView);	

	verify_noerr( TXNGetCommandEventSupport( txnObj, &options ) );
	
	if ( (options & kTXNSupportFontCommandProcessing) &&
		 (options & kTXNSupportFontCommandUpdating) )
		state = true;
	
	return state;
}
コード例 #15
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
Boolean
TextViewToggleSpellCheckAsYouType( HIViewRef textView )
{
	Boolean spellCheckOn = TXNGetSpellCheckAsYouType(HITextViewGetTXNObject(textView));
	OSStatus status = TextViewSpellCheckAsYouType( textView, !spellCheckOn );
	
	if( status != noErr )
	{
		// console output
		char uMsg[255];
		sprintf( uMsg, "TextViewSpellCheckAsYouType returned %lu", status );
		WarnString( uMsg );
	}
	
	return !spellCheckOn;
}
コード例 #16
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus
TextViewSetMargins( HIViewRef textView, SInt16 top, SInt16 left, SInt16 right )
{
	TXNMargins margins;
	
	margins.topMargin = top;
	margins.leftMargin = left;
	margins.bottomMargin = 0; // cannot change bottomMargin in MLTE at this time
	margins.rightMargin = right;

	//	Set the margins in the object.
	TXNControlTag	iControlTags[] = {kTXNMarginsTag};
	TXNControlData	iControlData[1];
	iControlData[0].marginsPtr = &margins;

	return TXNSetTXNObjectControls( HITextViewGetTXNObject(textView), false, 1, iControlTags, iControlData );
}
コード例 #17
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus
TextViewDemoActionGroup( HIViewRef textView )
{
	const char* sampleText = "bigger...\n";
	static const CFStringRef taskCFStr = CFSTR("TaskActionGroup");

	static const CFStringRef actionLabel = CFSTR("Example Action Group");
	
	TXNObject txnObj = HITextViewGetTXNObject(textView);
	
    TXNTypeAttributes	typeAttr[] = {{kTXNQDFontSizeAttribute,
									   kTXNQDFontSizeAttributeSize,
										{0}}};
	typeAttr[0].data.dataValue = (24 << 16);
	
	TXNBeginActionGroup( txnObj, actionLabel);
	
	TXNSetData( txnObj, kTXNTextData, sampleText, strlen( sampleText ), kTXNStartOffset, kTXNEndOffset );

	TXNSetTypeAttributes( txnObj, 1, typeAttr, kTXNStartOffset, kTXNEndOffset );
					  
	typeAttr[0].data.dataValue = (36 << 16);
	TXNSetTypeAttributes( txnObj, 1, typeAttr, kTXNEndOffset, kTXNEndOffset );
	
	TXNSetData( txnObj, kTXNTextData, sampleText, strlen( sampleText ), kTXNEndOffset, kTXNEndOffset );
				  
	typeAttr[0].data.dataValue = (48 << 16);
	TXNSetTypeAttributes( txnObj, 1, typeAttr, kTXNEndOffset, kTXNEndOffset );
	
	TXNSetData( txnObj, kTXNTextData, sampleText, strlen( sampleText ), kTXNEndOffset, kTXNEndOffset );
	
	typeAttr[0].data.dataValue = (72 << 16);
	TXNSetTypeAttributes( txnObj, 1, typeAttr, kTXNEndOffset, kTXNEndOffset );
	
	TXNSetData( txnObj, kTXNTextData, sampleText, strlen( sampleText ), kTXNEndOffset, kTXNEndOffset );
	
	typeAttr[0].data.dataValue = (96 << 16);
	TXNSetTypeAttributes( txnObj, 1, typeAttr, kTXNEndOffset, kTXNEndOffset );
	
	TXNSetData( txnObj, kTXNTextData, sampleText, strlen( sampleText ) - 1 /*don't set last line return*/, 
				kTXNEndOffset, kTXNEndOffset );
	
	TXNEndActionGroup( txnObj );  
	SignalHelpMessage( HIViewGetWindow( textView ), taskCFStr );
	return noErr;
}
コード例 #18
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
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;
}
コード例 #19
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus 				
TextViewGetObjectControlData( HIViewRef textView, TXNControlTag controlTag, Boolean isSigned, 
                                SInt32& oSignedData, UInt32& oUnsignedData )
{
    OSStatus	status = paramErr;
    TXNControlTag	oControlTags[1] = {controlTag};
    TXNControlData	oControlData[1];

    status = ::TXNGetTXNObjectControls(	HITextViewGetTXNObject(textView), 1, oControlTags, oControlData );
    if (status == noErr)
    {
        if( isSigned )
            oSignedData = oControlData[0].sValue;
        else
            oUnsignedData = oControlData[0].uValue;
    }                                 
    fail:
    return status;
}
コード例 #20
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus
TextViewWriteToCFURL( HIViewRef textView, CFURLRef fileURL, OSType type, Boolean replacing )
{
	static const CFStringRef taskCFStr = CFSTR("TaskWriteCFURL");
	static const CFStringRef taskErrorCFStr = CFSTR("TaskWriteCFURLERROR");
	OSStatus status = paramErr;	
	FSRef createdFSRef;
	CFNumberRef encodingNumber = NULL;
	
	// create a file based on the URL provided
	status = CreateFileWithCFURL( fileURL, createdFSRef, type, replacing );

	// specify data type info
	CFStringRef dataKeys[2];   // this array of keys only contains CFStringRefs
	
	const void* dataValues[2]; // this array contains a CFStringRef and an CFNumber
							   // so we will use void* for the array type
	
	dataKeys[0] = kTXNDataOptionDocumentTypeKey;
	
	// set an appropriate document type and encoding
	// we are still using the old Textension file type constants for passing
	// the file type selection from Navigation Services, but please note that
	// these constants are being deprecated in Tiger.
	switch( type )
	{
		case 'RTF ':
			dataValues[0] = kTXNRTFDocumentType;
			encodingNumber = UtilCreateEncodingCFNumberRef( kCFStringEncodingUnicode );
			break;
		case kTXNUnicodeTextFile: // old MLTE Unicode file constant
			dataValues[0] = kTXNPlainTextDocumentType;
			encodingNumber = UtilCreateEncodingCFNumberRef( kCFStringEncodingUnicode );
			break;
		case 'text':
		case kTXNTextFile: // old MLTE text file constant
			dataValues[0] = kTXNPlainTextDocumentType;
			encodingNumber = UtilCreateEncodingCFNumberRef( kCFStringEncodingMacRoman );
			break;
		case kTXNTextensionFile: // old MLTE Textension file format file constant
		default:
			dataValues[0] = kTXNMLTEDocumentType;
			encodingNumber = UtilCreateEncodingCFNumberRef( kCFStringEncodingUnicode );
			break;
	}
	
	dataKeys[1] =	kTXNDataOptionCharacterEncodingKey;
	dataValues[1] = (void*)encodingNumber;
	
	CFDictionaryRef iDataOptionsDict = CFDictionaryCreate( NULL /*allocator*/,
														   (const void**)dataKeys,		
														   (const void**)dataValues, 
														   sizeof(dataKeys) / sizeof(CFStringRef), /*itemCount*/
														   &kCFCopyStringDictionaryKeyCallBacks, 
														   &(kCFTypeDictionaryValueCallBacks));
														   
	// Now make some meta data
	CFStringRef docKeys[6];
	CFStringRef docValues[6];
	
	docKeys[0] = kTXNDocumentAttributeTitleKey;
	docValues[0] = CFSTR("Example File");
	
	docKeys[1] = kTXNDocumentAttributeCompanyNameKey;
	docValues[1] = CFSTR("__MyCompanyName__");
	
	docKeys[2] = kTXNDocumentAttributeSubjectKey;
	docValues[2] = CFSTR("Example of saving a file");
	
	docKeys[3] = kTXNDocumentAttributeAuthorKey;
	docValues[3] = CFSTR("Me");
	
	docKeys[4] = kTXNDocumentAttributeKeywordsKey;
	docValues[4] = CFSTR("Textension, MLTE, File, Save, CFURL");
	
	docKeys[5] = kTXNDocumentAttributeCommentKey;
	docValues[5] = CFSTR("This is just a demonstration.");
	
	CFDictionaryRef iDocAttributesDict = CFDictionaryCreate( NULL							 /*allocator*/,
														    (const void**)docKeys,		
														    (const void**)docValues, 
										  					sizeof(docKeys) / sizeof(CFStringRef), /*itemCount*/
										  					&kCFCopyStringDictionaryKeyCallBacks, 
										  					&(kCFTypeDictionaryValueCallBacks));
	

	// console output
	WarnString( "Call TXNWriteRangeToCFURL with url: ");
	CFShow( fileURL );
	
	status = TXNWriteRangeToCFURL( HITextViewGetTXNObject(textView),
									kTXNStartOffset,
									kTXNEndOffset,
									iDataOptionsDict,
									iDocAttributesDict,
									fileURL );

	// clean up all the CFTypes we made
	if( iDataOptionsDict != NULL )
		CFRelease( iDataOptionsDict );
	if( iDocAttributesDict != NULL )
		CFRelease( iDocAttributesDict );
	
	if( status == noErr )
		SignalHelpMessage( HIViewGetWindow( textView ), taskCFStr );
	else
	{
		// If we fail to write a file, we'll leave the bad / broken file we created
		// to save the data into -- as evidence of the error.
		SignalHelpMessage( HIViewGetWindow( textView ), taskErrorCFStr );
	}
	
	return status;
}
コード例 #21
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus
TextViewEndActionGroup( HIViewRef textView )
{
	return TXNEndActionGroup( HITextViewGetTXNObject(textView));
}				
コード例 #22
0
ファイル: TextView.cpp プロジェクト: arnelh/Examples
OSStatus
TextViewBeginActionGroup( HIViewRef textView, CFStringRef iActionGroupName )
{
	return TXNBeginActionGroup( HITextViewGetTXNObject(textView), iActionGroupName);
}
コード例 #23
0
ファイル: llappviewermacosx.cpp プロジェクト: Boy/netbook
OSStatus DisplayReleaseNotes(void)
{
	OSStatus err;
	IBNibRef nib = NULL;
	WindowRef window = NULL;
	
	err = CreateNibReference(CFSTR("SecondLife"), &nib);
	
	if(err == noErr)
	{
		CreateWindowFromNib(nib, CFSTR("Release Notes"), &window);
	}
		
	if(err == noErr)
	{
		// Get the text view control
		HIViewRef textView;
		ControlID id;

		id.signature = 'text';
		id.id = 0;

		LLString releaseNotesText;
		
		_read_file_into_string(releaseNotesText, "releasenotes.txt");		// Flawfinder: ignore

		err = HIViewFindByID(HIViewGetRoot(window), id, &textView);
		
		if(err == noErr)
		{
			// Convert from the encoding used in the release notes.
			CFStringRef str = CFStringCreateWithBytes(
				NULL, 
				(const UInt8*)releaseNotesText.c_str(), 
				releaseNotesText.size(), 
				kCFStringEncodingWindowsLatin1, 		// This matches the way the Windows version displays the release notes.
				FALSE);
			
			if(str != NULL)
			{
				int size = CFStringGetLength(str);

				if(size > 0)
				{
					UniChar *chars = new UniChar[size + 1];
					CFStringGetCharacters(str, CFRangeMake(0, size), chars);
				
					err = TXNSetData(HITextViewGetTXNObject(textView), kTXNUnicodeTextData, chars, size * sizeof(UniChar), kTXNStartOffset, kTXNStartOffset);
					
					delete[] chars;
				}
				
				CFRelease(str);
			}
			else
			{
				// Creating the string failed.  Probably an encoding problem.  Display SOMETHING...
				err = TXNSetData(HITextViewGetTXNObject(textView), kTXNTextData, releaseNotesText.c_str(), releaseNotesText.size(), kTXNStartOffset, kTXNStartOffset);
			}
		}
		
		// Set the selection to the beginning of the text and scroll it into view.
		if(err == noErr)
		{
			err = TXNSetSelection(HITextViewGetTXNObject(textView), kTXNStartOffset, kTXNStartOffset);
		}
		
		if(err == noErr)
		{
			// This function returns void.
			TXNShowSelection(HITextViewGetTXNObject(textView), false);
		}
	}

	if(err == noErr)
	{
		ShowWindow(window);
	}

	if(err == noErr)
	{
		// Set up an event handler for the window.
		EventHandlerRef handler = NULL;
		EventTypeSpec handlerEvents[] = 
		{
			{ kEventClassCommand, kEventCommandProcess }
		};

		InstallWindowEventHandler(
				window, 
				NewEventHandlerUPP(simpleDialogHandler), 
				GetEventTypeCount (handlerEvents), 
				handlerEvents, 
				(void*)window, 
				&handler);
	}
			
	if(err == noErr)
	{
		RunAppModalLoopForWindow(window);
	}
			
	if(window != NULL)
	{
		DisposeWindow(window);
	}
	
	if(nib != NULL)
	{
		DisposeNibReference(nib);
	}

	return(err);
}