Up   Previous   Next  

Creating a Text Object

You create a text object using the TXNNewObject function. Listing 3-5 shows a sample function-- MyCreateTextObject --that creates a text object and attaches it to a window. Error handling code has been omitted in the sample function so that you can more easily read the sequence of functions calls.

Once the text object is attached to the window, the MyCreateTextObject function sets the state of the scroll bars using the TXNActivate function and then prepares the Font menu for display. The function TXNPrepareFontMenu displays a checkmark next to the active font in the Font menu the first time the user opens the Font menu associated with the text object. If you don't call the TXNPrepareFontMenu function, the checkmark is not displayed until the second time the user opens the Font menu associated with the text object.

Listing 3-5 Creating a text object
OSStatus MyCreateTextObject (const FSSpec *fileSpecPtr, WindowRef theWindow) { TXNObject textObject = NULL; // text object TXNFrameID frameID = 0; // ID for text frame TXNFrameOptions frameOptions; // ------------Setting Options for the Text Object's Frame-----------// // Assign values to frame options so the frame shows vertical and // horizontal scroll bars and a size box. Use the MLTE constants. frameOptions = kTXNShowWindowMask | kTXNWantVScrollBarMask | kTXNWantHScrollBarMask |kTXNDrawGrowIconMask. //--------------Creating a Text Object-------------------------------// // Call the MLTE function to create a new text object. // If fileSpecPtr is NULL, the object is empty. Otherwise, the object // has the contents of the file to which fileSpecPtr points. status = TXNNewObject (fileSpecPtr, // text object contents theWindow, // use this window NULL, // use window's port rectangle frameOptions, // set frame options kTXNTextEditStyleFrameType, // TextEdit-style frame kTXNTextensionFile, // use MLTE file format kTXNSystemDefaultEncoding, // use default text encoding &textObject, // get back text object &frameID, // get back text frame ID 0); // no private data // Your application will need to retrieve the text object and its // frame ID when it calls other MLTE functions later. You can save // the text object and frame ID in a number of way. One way is // to use the Window Manager function SetWindowProperty, as shown below. SetWindowProperty (theWindow, kPropertyTag, kObjectTag, sizeof (TXNObject), &textObject); SetWindowProperty (theWindow, kPropertyTag, kFrameTag, sizeof (TXNFrameID),&frameID); // Activate the text object. status = TXNActivate (object, frameID, ScrollBarsAlwaysActive); // Prepare the Font menu for display. When you call this MLTE function, // a checkmark will be displayed next to the active font. // You should call this function only if you have already // created a Font menu object. status = TXNPrepareFontMenu (object, gTXNFontMenuObject); return status; }

Copyright © 2001 Apple Computer, Inc. (Last Updated January 11, 2001)

Up   Previous   Next