Up   Previous   Next  

Displaying Static Text

MLTE provides an easy way for your application to display static text whether or not it uses other MLTE features to implement editing services. You do not need to initialize MLTE to display static text.

The TXNDrawUnicodeTextBox and TXNDrawCFStringTextBox functions display text that a user cannot edit. You use the TXNDrawUnicodeTextBox function when you want to display a Unicode string and the TXNDrawCFStringTextBox function when you want to display a CFString object. Each function draws the text in a rectangle whose size you specify in the local coordinates of the current graphics port. MLTE uses the ATSUI style you specify to display the text or creates an ATSUI style based on the style associated with the current graphics port. You can specify a number of other options, such as text orientation (horizontal or vertical) and text alignment (right, left, centered, or fully justified).

Listing 3-1 shows how to use the TXNDrawCFSTringTextBox function to display a static string. The TXNDrawCFStringTextBox function draws into the current graphics port.

Listing 3-1 Displaying static text in a text box
static void MyDrawStaticText (WindowRef theWindow) { Rect bounds; CFStringRef myText; GrafPtr myOldPort; // Save the current graphics port. GetPort (&myOldPort); // Set the graphics port to the window port. SetPortWindowPort (theWindow); // Call the QuickDraw function to make sure the rectangle is empty. EraseRect (GetWindowPortBounds (theWindow, &bounds)); // Create the static string you want to display. // You can use the String Services function CFSTR to // convert a C string to a CFString. myText = CFSTR (" This is a static text box created by \r the MLTE function TXNDrawCFStringTextBox."); // Call the MLTE function to draw the static text // in the rectangle. TXNDrawCFStringTextBox (myText, &bounds, NULL, NULL); // Restore the original graphics port. SetPort (myOldPort); }

When you implement the code shown in Listing 3-1, you see the text shown in Figure 3-1.

Figure 3-1  A static text box


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

Up   Previous   Next