[futurebasic] Re: FBtoC: non-scrolling but styled text

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2008 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Tue, 23 Sep 2008 21:18:45 -0400
Mark asked:

> How should I modify or replace the
> scrolling text view example so that I can show a text file ( .rtf
> file) with styled text in a non-scrolling field?


Mark,

This assumes you are creating your "fields"-- or views-- in Interface  
Builder using a nib, rather than creating them programmatically.

Use a Text View (HiTextView) and don't embed it in a Scroll View. You  
can then create the TNXObject from your RTF file and put it into the  
view (AKA "Edit Field").

Once you get the hang of HiTextViews, you won't want to look back. A  
single line of code can copy the view's contents to and from the  
Clipboard and there are functions available to do all sorts of clever  
things with the view's TXNObject, whether it be text or a picture,

Ken

Here's some quick pseudocode to give you the concept:


dim as HIViewRef  @ myTextView, myRoot
dim as OSStatus     ignore
dim as CFURLRef     theUrl
dim as TXNObject    txnObj

// Get the window which contains your HiTextView (AKA "Edit Field")
myRoot = fn HIViewGetRoot( window (_wndRef) )

// Locate the field/view in your window where you want to put your  
RTF text
ignore = fn HIViewFindByID( myRoot, kHIViewWindowContentID.signature,  
kHIViewWindowContentID.id, myTextView )

// Locate the RTF file...

//   (In this example it's a file called "test.rtf"
//    in your application bundle)

// ... and ID it with a CFURLRef
theURL = fn CFBundleCopyResourceURL( fn CFBundleGetMainBundle(), fn  
CFSTR( "test.rtf" ), 0, 0 )

// Once you have the CFURLRef...
long if (theURL )

// Create a TXXObject for data in your selected view
txnObj = fn HITextViewGetTXNObject( myTextView )

// Grab the RTF data and put it into your HiTextView via the view's  
TXNObject
ignore = fn TXNReadFromCFURL( txnObj, _kTXNStartOffset,  
_kTXNEndOffset, 0, theURL, #0 )

// Empty the trash
CFRelease( theURL )

end if