Up   Previous   Next  

Implementing Line Justification

Your application can provide a Layout menu that allows the user to select a line justification setting. Once you create a menu that contains line justification items, you can indicate to the user which justification setting is active by displaying a checkmark or other visual indicator next to the item if it is enabled. Figure 3-4 shows a Layout menu that has the Justify Full item checked.

When a user changes the line justification setting, your application can use the TXNGetTXNObjectControls and TXNSetTXNObjectControls functions to get the current setting, then change the setting appropriately. These functions are used to get and set a number of document-wide settings, so you need to use the iControlTags parameter to specify that line justification is the setting you want to change. MLTE provides a constant called kTXNJustificationTag that you can use for the value of the iControlTags parameter.

You use the iControlData parameter of the TXNSetTXNObjectControls function to specify the new value of the line justification setting. MLTE provides six constants that you can use to specify the value-- kTXNFlushDefault , kTXNFlushLeft , kTXNFlushRight , kTXNCenter , kTXNFullJust , and kTXNForceFullJust . The kTXNFlushDefault constant indicates text should be flush according to the line direction. The constant kTXNForceFullJust indicates that every line of text, including the last line, should be flush left and right.

Listing 3-14 shows a MyDoJustification function that your application can call from a menu-handling function to implement the type of justification your user selects from a Layout menu you create.

Listing 3-14 Handling line justification
void MyDoJustification (WindowPtr theWindow, short menuItem) { TXNObject textObject = NULL; MenuHandle layoutMenu; OSStatus status = noErr; SInt32 justification; TXNControlTag controlTag[1]; TXNControlData controlData[1]; // Call the Menu Manager function to get the menu handle. layoutMenu = GetMenuHandle (mLayout); // Call your own function to get text object. MyGetTextObject (theWindow, &textObject); // Call the Menu Manager function to uncheck any checked items. for (int i = 1; i <= iForceJustify; i++) CheckItem (layoutMenu, i, false); // Assign the appropriate value based on the menu item the user chooses. switch (menuItem) { case iDefaultJustify: // Set justification flush according to line direction. justification = kTXNFlushDefault; break; case iLeftJustify: justification = kTXNFlushLeft; break; case iRightJustify: justification = kTXNFlushRight; break; case iCenterJustify: justification = kTXNCenter; break; case iFullJustify: justification = kTXNFullJust; break; case iForceJustify: // Set justification to flush left and right // for all lines, including the last line. justification = kTXNForceFullJust; break; default: break; } // Call the Menu Manager function to check this menu item. CheckItem (layoutMenu, menuItem, true); // Assign the tag value. Use the MLTE constant to specify // justification. controlTag[0] = kTXNJustificationTag; // Call the MLTE function to get the justification value. status = TXNGetTXNObjectControls (object, 1, controlTag, controlData); // If the justification is new if (controlData[0].sValue != justification) { // assign the new value. controlData[0].sValue = justification; // Call the MLTE function to set the new value. status = TXNSetTXNObjectControls (object, false, 1, controlTag, controlData); } // If there is an error if (status != noErr) // call your own error handling function. AlertUser (eNoJustification); }

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

Up   Previous   Next