home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-Developer.iso / NextLibrary / Frameworks / AppKit.framework / Versions / B / Headers / NSLayoutManager.h < prev    next >
Text File  |  1996-12-20  |  31KB  |  402 lines

  1. /*
  2.         NSLayoutManager.h
  3.         Application Kit
  4.         Copyright (c) 1994-1996, NeXT Software, Inc.
  5.         All rights reserved.
  6. */
  7.  
  8. #ifndef STRICT_OPENSTEP
  9.  
  10. // An NSLayoutManager stores glyphs, attributes, and layout information generated from a NSTextStorage by a NSTextLayout.  It can map between ranges of unichars in the NSTextStorage and ranges of glyphs within itself.  It understands and keeps track of two types of range invalidation.  A character range can need glyphs generated for it or it can need its glyphs laid out.  
  11. // When a NSLayoutManager is asked for information which would require knowledge of glyphs or layout which is not currently available, the NSLayoutManager must cause the appropriate recalculation to be done.
  12.  
  13. #import <Foundation/Foundation.h>
  14. #import <AppKit/NSFont.h>
  15.  
  16. @class NSTextStorage;
  17. @class NSTypesetter;
  18. @class NSGlyphGenerator;
  19. @class NSTextContainer;
  20. @class NSTextView;
  21. @class NSWindow;
  22. @class NSColor;
  23. @class NSRulerView;
  24. @class NSParagraphStyle;
  25. @class NSRulerMarker;
  26. @class NSBox;
  27. @class NSTextField;
  28. @class NSMatrix;
  29. @class NSTabWell;
  30. @class NSStorage;
  31. @class NSRunStorage;
  32. @class NSSortedArray;
  33. @class NSView;
  34. @class NSEvent;
  35.  
  36. // These glyph attributes are used only inside the glyph generation machinery, but must be shared between componenets.
  37. enum _NSGlyphAttribute {
  38.     NSGlyphAttributeSoft = 0,
  39.     NSGlyphAttributeElastic = 1,
  40.     NSGlyphAttributeInscribe = 5,
  41. };
  42.  
  43. // The inscribe attribute of a glyph determines how it is laid out relative to the previous glyph.
  44. typedef enum {
  45.     NSGlyphInscribeBase = 0,
  46.     NSGlyphInscribeBelow = 1,
  47.     NSGlyphInscribeAbove = 2,
  48.     NSGlyphInscribeOverstrike = 3,
  49.     NSGlyphInscribeOverBelow = 4
  50. } NSGlyphInscription;
  51.  
  52. @interface NSLayoutManager : NSObject {
  53.  
  54.   @private
  55.     NSTextStorage *_textStorage;
  56.     NSGlyphGenerator *_glyphGenerator;
  57.     NSTypesetter *_typesetter;
  58.  
  59.     NSMutableArray *_textContainers;
  60.     NSStorage *_containerUsedRects;
  61.  
  62.     NSStorage *_glyphs;
  63.     NSRunStorage *_containerRuns;
  64.     NSRunStorage *_fragmentRuns;
  65.     NSRunStorage *_glyphLocations;
  66.     NSRunStorage *_glyphRotationRuns;
  67.     
  68.     NSRect _extraLineFragmentRect;
  69.     NSRect _extraLineFragmentUsedRect;
  70.     NSTextContainer *_extraLineFragmentContainer;
  71.  
  72.     NSSortedArray *_glyphHoles;
  73.     NSSortedArray *_layoutHoles;
  74.  
  75.     struct __lmFlags {
  76.         unsigned int containersAreFull:1;
  77.         unsigned int glyphsMightDrawOutsideLines:1;
  78.         unsigned int backgroundLayoutEnabled:1;
  79.         unsigned int resizingInProgress:1;
  80.         unsigned int allowScreenFonts:1;
  81.         unsigned int cachedRectArrayInUse:1;
  82.         unsigned int displayInvalidationInProgress:1;
  83.         unsigned int insertionPointNeedsUpdate:1;
  84.         unsigned int layoutManagerInDirtyList:1;
  85.         unsigned int usingGlyphCache:1;
  86.         unsigned int showInvisibleCharacters:1;
  87.         unsigned int showControlCharacters:1;
  88.         unsigned int delegateRespondsToDidInvalidate:1;
  89.         unsigned int delegateRespondsToDidComplete:1;
  90.         unsigned int glyphFormat:2;
  91.         unsigned int textStorageRespondsToIsEditing:1;
  92.         unsigned int notifyEditedInProgress:1;
  93.         unsigned int containersChanged:1;
  94.         unsigned int isGeneratingGlyphs:1;
  95.         unsigned int hasNonGeneratedGlyphData:1;
  96.         
  97.         unsigned int _pad:11;
  98.     } _lmFlags;
  99.  
  100.     id _delegate;
  101.  
  102.     // Enable/disable stacks
  103.     unsigned short _textViewResizeDisableStack;
  104.     unsigned short _displayInvalidationDisableStack;
  105.     NSRange _deferredDisplayCharRange;
  106.  
  107.     // Cache for first text view (that is text view of the first text container which has one) (Cost: 4 bytes)
  108.     NSTextView *_firstTextView;
  109.  
  110.     // Cache for rectangle arrays (Cost: 8 bytes + malloced 16 * <max number of rects returned in an array> bytes)
  111.     NSRect *_cachedRectArray;
  112.     unsigned _cachedRectArrayCapacity;
  113.  
  114.     // Cache for glyph strings (used when drawing) (Cost: 8 bytes + malloced glyph buffer size)
  115.     char *_glyphBuffer;
  116.     unsigned _glyphBufferSize;
  117.  
  118.     // Cache for faster glyph location lookup (Cost: 20 bytes)
  119.     NSRange _cachedLocationNominalGlyphRange;
  120.     unsigned _cachedLocationGlyphIndex;
  121.     NSPoint _cachedLocation;
  122.  
  123.     // Cache for faster glyph location lookup (Cost: 12 bytes)
  124.     NSRange _cachedFontCharRange;
  125.     NSFont *_cachedFont;
  126.  
  127.     // Cache for first unlaid glypha and character (Cost: 8 bytes)
  128.     unsigned _firstUnlaidGlyphIndex;
  129.     unsigned _firstUnlaidCharIndex;
  130.  
  131.     // Outlets for ruler accessory view.
  132.     NSBox *_rulerAccView;
  133.     NSMatrix *_rulerAccViewAlignmentButtons;
  134.     NSTextField *_rulerAccViewLeadingField;
  135.     NSTabWell *_rulerAccViewLeftTabWell;
  136.     NSTabWell *_rulerAccViewRightTabWell;
  137.     NSTabWell *_rulerAccViewCenterTabWell;
  138.     NSTabWell *_rulerAccViewDecimalTabWell;
  139.     NSMatrix *_rulerAccViewIncrementLineHeightButtons;
  140.     NSMatrix *_rulerAccViewFixedLineHeightButtons;
  141.  
  142.     NSRange _newlyFilledGlyphRange;
  143.     
  144.     float _hyphenationFactor;
  145. }
  146.  
  147. /**************************** Initialization ****************************/
  148.  
  149. - (id)init;
  150.     // Designated Initializer.  Sets up this instance.  Finds the shared NSGlyphGenerator and the shared default NSTypesetter.  The NSLayoutManager starts off without a NSTextStorage
  151.  
  152. /*************************** Helper objects ***************************/
  153.  
  154. - (NSTextStorage *)textStorage;
  155. - (void)setTextStorage:(NSTextStorage *)textStorage;
  156.     // The set method generally should not be called directly, but you may want to override it.  Used to get and set the text storage.  The set method is called by the NSTextStorage's addTextStorageObserver/removeTextStorageObserver methods.
  157.  
  158. - (void)replaceTextStorage:(NSTextStorage *)newTextStorage;
  159.     // This method should be used instead of the primitive -setTextStorage: if you need to replace a NSLayoutManager's NSTextStorage with a new one leaving the rest of the web intact.  This method deals with all the work of making sure the NSLayoutManager doesn't get deallocated and transferring all the NSLayoutManager s on the old NSTextStorage to the new one.
  160.  
  161. - (id)delegate;
  162. - (void)setDelegate:(id)delegate;
  163.     // Sets or gets the NSLayoutManager's delegate.
  164.  
  165. /**************************** Containers ****************************/
  166.  
  167. - (NSArray *)textContainers;
  168.  
  169. - (void)addTextContainer:(NSTextContainer *)container;
  170.     // Add a container to the end of the array.  Must invalidate layout of all glyphs after the previous last container (ie glyphs that were not previously laid out because they would not fit anywhere).
  171. - (void)insertTextContainer:(NSTextContainer *)container atIndex:(unsigned)index;
  172.     // Insert a container into the array before the container at index.  Must invalidate layout of all glyphs in the containers from the one previously at index to the last container.
  173. - (void)removeTextContainerAtIndex:(unsigned)index;
  174.     // Removes the container at index from the array.  Must invalidate layout of all glyphs in the container being removed and any containers which come after it.
  175.  
  176. - (void)textContainerChangedGeometry:(NSTextContainer *)container;
  177.     // Invalidates layout of all glyphs in container and all subsequent containers.
  178.  
  179. - (void)textContainerChangedTextView:(NSTextContainer *)container;
  180.     // Called by NSTextContainer whenever its textView changes.  Used to keep notifications in synch.
  181.  
  182. /************************** Invalidation primitives **************************/
  183.  
  184. - (void)invalidateGlyphsForCharacterRange:(NSRange)charRange changeInLength:(int)delta actualCharacterRange:(NSRange *)actualCharRange;
  185.     // This removes all glyphs for the old character range, adjusts the character indices of all the subsequent glyphs by the change in length, and invalidates the new character range.  If actualCharRange is non-NULL it will be set to the actual range invalidated after any necessary expansion.
  186.  
  187. - (void)invalidateLayoutForCharacterRange:(NSRange)charRange isSoft:(BOOL)flag actualCharacterRange:(NSRange *)actualCharRange;
  188.     // This invalidates the layout information (glyph location and rotation) for the given range of characters.  If flag is YES then this range is marked as a hard layout invalidation.  If NO, then the invalidation is soft.  A hard invalid layout range indicates that layout information must be completely recalculated no matter what.  A soft invalid layout range means that there is already old layout info for the range in question, and if the NSLayoutManager is smart enough to figure out how to avoid doing the complete relayout, it may perform any optimization available.  If actualCharRange is non-NULL it will be set to the actual range invalidated after any necessary expansion.
  189.  
  190. - (void)invalidateDisplayForGlyphRange:(NSRange)glyphRange;
  191. #ifndef STRICT_40
  192. - (void)invalidateDisplayForCharacterRange:(NSRange)charRange;
  193. #endif
  194.     // Invalidates display for the glyph or character range given.  For the glyph range variant any part of the range that does not yet have glyphs generated is ignored.  For the character range variant, unlaid parts of the range are remembered and will definitely be redisplayed at some point later when the layout is available.  Neither method actually causes layout.
  195.  
  196. /******************* Invalidation sent by NSTextStorage *******************/
  197.  
  198. - (void)textStorage:(NSTextStorage *)str edited:(unsigned)editedMask range:(NSRange)newCharRange changeInLength:(int)delta invalidatedRange:(NSRange)invalidatedCharRange;
  199.     // Sent from processEditing in NSTextStorage. newCharRange is the range in the final string which was explicitly edited. invalidatedRange includes stuff which was changed as a result of attribute fixing. invalidatedRange is either equal to newCharRange or larger. Layout managers should not change the contents of the text storage during the execution of this message.
  200.  
  201. /*********************** Global layout manager options ***********************/
  202.  
  203. - (void)setBackgroundLayoutEnabled:(BOOL)flag;
  204. - (BOOL)backgroundLayoutEnabled;
  205.     // These methods allow you to set/query whether text gets laid out in the background when there's nothing else to do.
  206.  
  207. - (void)setShowsInvisibleCharacters:(BOOL)flag;
  208. - (BOOL)showsInvisibleCharacters;
  209.     // If YES, and the rulebooks and fonts in use support it, whitespace and other "invisible" unicodes will be shown with special glyphs (ie "." for space, the little CR icon for new lines, etc...)
  210.  
  211. - (void)setShowsControlCharacters:(BOOL)flag;
  212. - (BOOL)showsControlCharacters;
  213.     // If YES, and the rulebooks and fonts in use support it, control characters will be rendered visibly (usually like "^M", but possibly with special glyphs if the the font and rulebook supports it).
  214.  
  215. #if !defined(STRICT_40) && !defined(STRICT_41)
  216. - (void)setHyphenationFactor:(float)factor;
  217. - (float)hyphenationFactor;
  218.     // 0.0 - 1.0. Whenever (width of the real contents of the line) / (the line fragment width) is below this value, hyphenation will be attempted when laying out the line. By default, the value is 0, meaning hyphenation is off. 1.0 causes hyphenation to be attempted always. Note that hyphenation will slow down text layout and increase memory usage, so it should be used sparingly.
  219. #endif
  220.  
  221. /************************ Adding and removing glyphs ************************/
  222.  
  223. // These methods are primitive.  They do not cause the bookkeeping of filling holes to happen.  They do not cause invalidation of other stuff.
  224.  
  225. - (void)insertGlyph:(NSGlyph)glyph atGlyphIndex:(unsigned)glyphIndex characterIndex:(unsigned)charIndex;
  226.     // Inserts a single glyph into the glyph stream at glyphIndex.  The character index which this glyph corresponds to is given by charIndex.
  227.  
  228. - (void)replaceGlyphAtIndex:(unsigned)glyphIndex withGlyph:(NSGlyph)newGlyph;
  229.     // Replaces the glyph currently at glyphIndex with newGlyph.  The character index of the glyph is assumed to remain the same (although it can, of coiurse, be set explicitly if needed).
  230.  
  231. - (void)deleteGlyphsInRange:(NSRange)glyphRange;
  232.     // Removes all glyphs in the given range from the storage.
  233.  
  234. - (void)setCharacterIndex:(unsigned)charIndex forGlyphAtIndex:(unsigned)glyphIndex;
  235.     // Sets the index of the corresponding character for the glyph at the given glyphIndex.
  236.  
  237. /************************ Accessing glyphs ************************/
  238.  
  239. - (unsigned)numberOfGlyphs;
  240.     // If there are any holes in the glyph stream, this will cause all invalid character ranges to have glyphs generated for them.
  241.  
  242. - (NSGlyph)glyphAtIndex:(unsigned)glyphIndex;
  243. - (NSGlyph)glyphAtIndex:(unsigned)glyphIndex isValidIndex:(BOOL *)isValidIndex;
  244.     // If there are any holes in the glyph stream this will cause glyph generation for all holes sequentially encountered until the desired index is available.  The first variant raises a NSRangeError if the requested index is out of bounds, the second does not, but instead optionally returns a flag indicating whether the requested index exists.
  245.  
  246.  
  247. - (unsigned)getGlyphs:(NSGlyph *)glyphArray range:(NSRange)glyphRange;
  248.     // This causes glyph generation similarly to asking for a single glyph.  It formats a sequence of NSGlyphs (unsigned long ints).  It does not include glyphs that aren't shown in the result but does zero-terminate the array.  The memory passed in to the function should be large enough for at least glyphRange.length+1 elements.  The actual number of glyphs stuck into the array is returned (not counting the null-termination).
  249.     // RM!!! check out the private method "_packedGlyphs:range:length:" if you need to send glyphs to the window server.  It returns a (conceptually) autoreleased array of big-endian packeg glyphs.  Don't use this method to do that.
  250.  
  251. - (unsigned)characterIndexForGlyphAtIndex:(unsigned)glyphIndex;
  252.     // If there are any holes in the glyph stream this will cause glyph generation for all holes sequentially encountered until the desired index is available.
  253.  
  254. /************************ Set/Get glyph attributes ************************/
  255.  
  256. // This method is primitive.  It does not cause any invalidation of other stuff.  This method also will not cause glyph generation.  The glyph being set must already be there.
  257.  
  258. - (void)setIntAttribute:(int)attributeTag value:(int)val forGlyphAtIndex:(unsigned)glyphIndex;
  259.     // This method is used by the NSGlyphGenerator to set attributes.  It is not usually necessary for anyone but the glyph generator (and perhaps the typesetter) to call it.  It is provided as a public method so subclassers can extend it to accept other glyph attributes.  To add new glyph attributes to the text system you basically need to do two things.  You need to write a rulebook which will generate the attributes (in rulebooks attributes are identified by integer tags).  Then you need to subclass NSLayoutManager to provide someplace to store the new attribute and to override this method and -attribute:forGlyphAtIndex: to understand the integer tag which your new rulebook is generating.  NSLayoutManager's implementation understands the glyph attributes which it is prepared to remember.  Your override should pass any glyph attributes it does not understand up to the superclass's implementation.
  260.  
  261. // This method will cause glyph generation as necessary to answer the question.
  262.  
  263. - (int)intAttribute:(int)attributeTag forGlyphAtIndex:(unsigned)glyphIndex;
  264.     // This returns the value for the given glyph attribute at the glyph index specified.  Most apps will not have much use for this info but the typesetter and glyph generator might need to know about certain attributes.  You can override this method to know how to return any custom glyph attributes you want to support.
  265.  
  266. /************************ Set/Get layout attributes ************************/
  267.  
  268. // These methods are fairly primitive.  They do not cause any kind of invalidation to happen.  The glyphs being set must already exist.  This is not a hardship since the NSTypesetter will have had to ask for the actual glyphs already by the time it goes to set this, and asking for the glyphs causes the glyph to be generated if necessary.
  269.  
  270. - (void)setTextContainer:(NSTextContainer *)container forGlyphRange:(NSRange)glyphRange;
  271.     // Associates the given container with the given range of glyphs.  This method should be called by the typesetter first (ie before setting line fragment rect or any of the layout bits) for each range of glyphs it lays out.  This method will set several key layout atttributes (like not shown and draws outside line fragment) to their default values.
  272.  
  273. - (void)setLineFragmentRect:(NSRect)fragmentRect forGlyphRange:(NSRange)glyphRange usedRect:(NSRect)usedRect;
  274.     // Associates the given line fragment bounds with the given range of glyphs.
  275.  
  276. - (void)setExtraLineFragmentRect:(NSRect)fragmentRect usedRect:(NSRect)usedRect textContainer:(NSTextContainer *)container;
  277.     // Sets the bounds and container for the extra line fragment.  The extra line fragment is used when the text backing ends with a hard line break or when the text backing is totally empty to define the extra line which needs to be displayed.  If the text backing does not end with a hard line break this should be set to NSZeroRect and nil.
  278.  
  279. - (void)setDrawsOutsideLineFragment:(BOOL)flag forGlyphAtIndex:(unsigned)glyphIndex;
  280.     // Used to indicate that a particular glyph for some reason marks outside its line fragment bounding rect.  This can commonly happen if a fixed line height is used (consider a 12 point line height and a 24 point glyph).
  281.  
  282. - (void)setLocation:(NSPoint)location forStartOfGlyphRange:(NSRange)glyphRange;
  283.     // Sets the location to draw the first glyph of the given range at.  Setting the location for a glyph range implies that its first glyph is NOT nominally spaced with respect to the previous glyph.  When all is said and done all glyphs in the layoutManager should have been included in a range passed to this method.  But only glyphs which start a new nominal rtange should be at the start of such ranges.  Glyph locations are given relative the their line fragment bounding rect's origin.
  284.  
  285. - (void)setNotShownAttribute:(BOOL)flag forGlyphAtIndex:(unsigned)glyphIndex;
  286.     // Some glyphs are not shown.  The typesetter decides which ones and sets this attribute in layoutManager where the view can find it.
  287.  
  288. - (NSTextContainer *)textContainerForGlyphAtIndex:(unsigned)glyphIndex effectiveRange:(NSRange *)effectiveGlyphRange;
  289.     // Returns the container in which the given glyph is laid and (optionally) by reference the whole range of glyphs that are in that container.  This will cause glyph generation AND layout as needed.
  290.  
  291. - (NSRect)usedRectForTextContainer:(NSTextContainer *)container;
  292.     // Returns the container's currently used area.  This is the size that the view would need to be in order to display all the stuff that is currently laid into the container.  This causes no generation.
  293.  
  294. - (NSRect)lineFragmentRectForGlyphAtIndex:(unsigned)glyphIndex effectiveRange:(NSRange *)effectiveGlyphRange;
  295.     // Returns the rect for the line fragment in which the given glyph is laid and (optionally) by reference the whole range of glyphs that are in that fragment.  This will cause glyph generation AND layout as needed.
  296.  
  297. - (NSRect)lineFragmentUsedRectForGlyphAtIndex:(unsigned)glyphIndex effectiveRange:(NSRange *)effectiveGlyphRange;
  298.     // Returns the usage rect for the line fragment in which the given glyph is laid and (optionally) by reference the whole range of glyphs that are in that fragment.  This will cause glyph generation AND layout as needed.
  299.  
  300. - (NSRect)extraLineFragmentRect;
  301. - (NSRect)extraLineFragmentUsedRect;
  302. - (NSTextContainer *)extraLineFragmentTextContainer;
  303.     // Return info about the extra line fragment.
  304.  
  305. - (BOOL)drawsOutsideLineFragmentForGlyphAtIndex:(unsigned) glyphIndex;
  306.     // Returns whether the glyph will make marks outside its line fragment's bounds.
  307.  
  308. - (NSPoint)locationForGlyphAtIndex:(unsigned)glyphIndex;
  309.     // Returns the location that the given glyph will draw at.  If this glyph doesn't have an explicit location set for it (ie it is part of (but not first in) a sequence of nominally spaced characters), the location is calculated from the location of the last glyph with a location set.  Glyph locations are relative the their line fragment bounding rect's origin (see -lineFragmentForGlyphAtIndex:effectiveRange: below for finding line fragment bounding rects).  This will cause glyph generation AND layout as needed.
  310.  
  311. - (BOOL)notShownAttributeForGlyphAtIndex:(unsigned) glyphIndex;
  312.     // Some glyphs are not shown.  This will cause glyph generation and layout as needed..
  313.  
  314. /************************ More sophisticated queries ************************/
  315.  
  316. // These two methods can cause glyph generation.
  317.  
  318. - (NSRange)glyphRangeForCharacterRange:(NSRange)charRange actualCharacterRange:(NSRange *)actualCharRange;
  319.     // Returns the range of glyphs that are generated from the unichars in the given charRange.  actualCharRange, if not NULL, will be set to the actual range of characters that fully define the glyph range returned.  This range may be identical or slightly larger than the requested characterRange.  For instance, if the text storage contains the unichars "o" and (umlaut) and the glyph store contains the single precomposed glyph (o-umlaut), and if the charcterRange given encloses only the first or second unichar, the actualCharRange will be set to enclose both unichars.
  320.  
  321. - (NSRange)characterRangeForGlyphRange:(NSRange)glyphRange actualGlyphRange:(NSRange *)actualGlyphRange;
  322.     // Returns the range of characters that generated the glyphs in the given glyphRange.  actualGlyphRange, if not NULL, will be set to the full range of glyphs that the character range returned generated.  This range may be identical or slightly larger than the requested glyphRange.  For instance, if the text storage contains the unichar (o-umlaut) and the glyph store contains the two atomic glyphs "o" and (umlaut), and if the glyphRange given encloses only the first or second glyph, the actualGlyphRange will be set to enclose both glyphs.
  323.  
  324. // All of these methods can cause glyph generation AND layout.
  325.  
  326. - (NSRange)glyphRangeForTextContainer:(NSTextContainer *)container;
  327.     // Returns the range of characters which have been laid into the given container.  This is a less efficient method than the similar -textContainerForGlyphAtIndex:effectiveRange:.
  328.  
  329. - (NSRange)rangeOfNominallySpacedGlyphsContainingIndex:(unsigned)glyphIndex;
  330.     // Returns the range including the first glyph from glyphIndex on back that has a location set and up to, but not including the next glyph that has a location set.  This is a range of glyphs that can be shown with a single postscript show operation.
  331.  
  332. - (NSRect *)rectArrayForCharacterRange:(NSRange)charRange withinSelectedCharacterRange:(NSRange)selCharRange inTextContainer:(NSTextContainer *)container rectCount:(unsigned *)rectCount;
  333. - (NSRect *)rectArrayForGlyphRange:(NSRange)glyphRange withinSelectedGlyphRange:(NSRange)selGlyphRange inTextContainer:(NSTextContainer *)container rectCount:(unsigned *)rectCount;
  334.     // Returns an array of NSRects and the number of rects by reference which define the region in container that encloses the given range.  If a selected range is given in the second argument, the rectangles returned will be correct for drawing the selection.  Selection rectangles are generally more complicated than enclosing rectangles and supplying a selected range is the clue these methods use to determine whether to go to the trouble of doing this special work. 
  335.     // If the caller is interested in this more from an enclosing point of view rather than a selection point of view pass {NSNotFound, 0} as the selected range.  This method works hard to do the minimum amount of work required to answer the question.  The resulting array is owned by the layoutManager and will be reused when either of these two methods OR -boundingRectForGlyphRange:inTextContainer: is called.  Note that one of these methods may be called indirectly.  The upshot is that if you aren't going to use the rects right away, you should copy them to another location.
  336.  
  337. - (NSRect)boundingRectForGlyphRange:(NSRange)glyphRange inTextContainer:(NSTextContainer *)container;
  338.     // Returns the smallest bounding rect (in container coordinates) which completely encloses the glyphs in the given glyphRange that are in the given container.  If no container is given, then the container of the first glyph is assumed.  Basically, the range is intersected with the container's range before computing the bounding rect.  This method can be used to translate glyph ranges into display rectangles for invalidation.
  339.  
  340. - (NSRange)glyphRangeForBoundingRect:(NSRect)bounds inTextContainer:(NSTextContainer *)container;
  341. - (NSRange)glyphRangeForBoundingRectWithoutAdditionalLayout:(NSRect)bounds inTextContainer:(NSTextContainer *)container;
  342.     // Returns the minimum contiguous glyph range that would need to be displayed in order to draw all glyphs that fall (even partially) within the bounding rect given.  This range might include glyphs which do not fall into the rect at all.  At most this will return the glyph range for the whole container.  The "WithoutFillingHoles" variant will not generate glyphs or perform layout in attempting to answer, and, thus, will potentially not be totally correct.
  343.  
  344. - (unsigned)glyphIndexForPoint:(NSPoint)point inTextContainer:(NSTextContainer *)container fractionOfDistanceThroughGlyph:(float *)partialFraction;
  345.     // Returns the index of the glyph which under the given point which is expressed in the given container's coordinate system.  If no glyph is under the point the "nearest" glyph is returned where "nearest" is defined in such a way that selection works like it should.  See the implementation for details.  partialFraction, if provided, is set to the fraction of the distance between the location of the glyph returned and the location of the next glyph that the point is at.
  346.  
  347. - (void)getFirstUnlaidCharacterIndex:(unsigned *)charIndex glyphIndex:(unsigned *)glyphIndex;
  348.     // Returns (by reference) the character index or glyph index or both of the first unlaid character/glyph in the layout manager at this time.
  349.  
  350. /************************ Screen font usage control ************************/
  351.  
  352. - (BOOL)usesScreenFonts;
  353. - (void)setUsesScreenFonts:(BOOL)flag;
  354.     // Sets whether this layoutManager will use screen fonts when it is possible to do so.
  355.  
  356. - (NSFont *)substituteFontForFont:(NSFont *)originalFont;
  357.     // Returns a font to use in place of originalFont.  This method is used to substitute screen fonts for regular fonts.  If screen fonts are allowed AND no NSTextView managed by this layoutManager is scaled or rotated AND a screen font is available for originalFont, it is returned, otherwise originalFont is returned.  MF:??? This method will eventually need to know or be told whether use of screen fonts is appropriate in a given situation (ie screen font used might be enabled or disabled, we might be printing, etc...).  This method causes no generation.
  358.  
  359. @end
  360.  
  361. @interface NSLayoutManager (NSTextViewSupport)
  362.  
  363. /************************ Ruler stuff ************************/
  364.  
  365. - (NSArray *)rulerMarkersForTextView:(NSTextView *)view paragraphStyle:(NSParagraphStyle *)style ruler:(NSRulerView *)ruler;
  366. - (NSView *)rulerAccessoryViewForTextView:(NSTextView *)view paragraphStyle:(NSParagraphStyle *)style ruler:(NSRulerView *)ruler enabled:(BOOL)isEnabled;
  367.     // These return, respectively, an array of text ruler objects for the current selection and the accessory view that the text system uses for ruler.  If you have turned off automatic ruler updating through the use of setUsesRulers: so that you can do more complex things, but you still want to display the appropriate text ruler objects and/or accessory view, you can use these methods.
  368.  
  369. /************************ First responder support ************************/
  370.  
  371. - (BOOL)layoutManagerOwnsFirstResponderInWindow:(NSWindow *)window;
  372.     // Returns YES if the firstResponder of the given window is one of the NSTextViews attached to this NSLayoutManager.
  373.  
  374. - (NSTextView *)firstTextView;
  375.  
  376. - (NSTextView *)textViewForBeginningOfSelection;
  377.     // This method is special in that it won't cause layout if the beginning of the selected range is not yet laid out.  Other than that this method could be done through other API.
  378.  
  379. /************************ Drawing support ************************/
  380.  
  381. - (void)drawBackgroundForGlyphRange:(NSRange)glyphsToShow atPoint:(NSPoint)origin;
  382. - (void)drawGlyphsForGlyphRange:(NSRange)glyphsToShow atPoint:(NSPoint)origin;
  383.     // These methods are called by NSTextView to do drawing.  You can override these if you think you can draw the stuff any better (but not to change layout).  You can call them if you want, but focus must already be locked on the destination view or MF:???image?.  -drawBackgroundGorGlyphRange:atPoint: should draw the background color and selection and marked range aspects of the text display.  -drawGlyphsForGlyphRange:atPoint: should draw the actual glyphs.  The point in either method is the container origin in the currently focused view's coordinates for the container the glyphs lie in.
  384.  
  385. - (void)drawUnderlineForGlyphRange:(NSRange)glyphRange underlineType:(int)underlineVal baselineOffset:(float)baselineOffset lineFragmentRect:(NSRect)lineRect lineFragmentGlyphRange:(NSRange)lineGlyphRange containerOrigin:(NSPoint)containerOrigin;
  386. - (void)underlineGlyphRange:(NSRange)glyphRange underlineType:(int)underlineVal lineFragmentRect:(NSRect)lineRect lineFragmentGlyphRange:(NSRange)lineGlyphRange containerOrigin:(NSPoint)containerOrigin;
  387.     // The first of these methods actually draws an appropriate underline for the glyph range given.  The second method potentailly breaks the range it is given up into subranges and calls drawUnderline... for ranges that should actually have the underline drawn.  As examples of why there are two methods, consider two situations.  First, in all cases you don't want to underline the leading and trailing whitespace on a line.  The -underlineGlyphRange... method is passed glyph ranges that have underlining turned on, but it will then look for this leading and trailing white space and only pass the ranges that should actually be underlined to -drawUnderline...  Second, if the underlineType: indicates that only words, (ie no whitespace), should be underlined, then -underlineGlyphRange... will carve the range it is passed up into words and only pass word ranges to -drawUnderline.
  388.  
  389. @end
  390.  
  391. @interface NSObject (NSLayoutManagerDelegate)
  392.  
  393. - (void)layoutManagerDidInvalidateLayout:(NSLayoutManager *)sender;
  394.     // This is sent whenever layout or glyphs become invalidated in a layout manager which previously had all layout complete.
  395.  
  396. - (void)layoutManager:(NSLayoutManager *)layoutManager didCompleteLayoutForTextContainer:(NSTextContainer *)textContainer atEnd:(BOOL)layoutFinishedFlag;
  397.     // This is sent whenever a container has been filled.  This method can be useful for paginating.  The textContainer might be nil if we have completed all layout and not all of it fit into the existing containers.  atEnd indicates whether all layout is complete.
  398.  
  399. @end
  400.  
  401. #endif
  402.