home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-Developer.iso / NextLibrary / Frameworks / AppKit.framework / Versions / B / Headers / NSTextContainer.h < prev    next >
Text File  |  1996-10-17  |  6KB  |  98 lines

  1. /*
  2.         NSTextContainer.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 NSTextContainer defines a region in which to lay out text.  It's main responsibility is to calculate line fragments which fall within the region it represents.  Containers have a line fragment padding which is used by the typesetter to inset text from the edges of line fragments along the sweep direction.
  11. // The container can enforce any other geometric constraints as well.  When drawing the text that has been laid in a container, a NSTextView will clip to the interior of the container (it clips to the container's rectagular area only, however, not to the arbitrary shape the container may define for text flow).
  12.  
  13. #import <Foundation/Foundation.h>
  14.  
  15. @class NSLayoutManager;
  16. @class NSTextView;
  17.  
  18. typedef enum {
  19.     NSLineSweepLeft = 0,
  20.     NSLineSweepRight = 1,
  21.     NSLineSweepDown = 2,
  22.     NSLineSweepUp = 3,
  23. } NSLineSweepDirection;
  24.  
  25. typedef enum {
  26.     NSLineDoesntMove = 0, 
  27.     NSLineMovesLeft = 1,
  28.     NSLineMovesRight = 2,
  29.     NSLineMovesDown = 3,
  30.     NSLineMovesUp = 4,
  31. } NSLineMovementDirection;
  32.  
  33.  
  34. @interface NSTextContainer : NSObject {
  35.     
  36.   @private
  37.     NSLayoutManager *_layoutManager;
  38.     NSTextView *_textView;
  39.     NSSize _size;
  40.     float _lineFragmentPadding;
  41.     struct __tcFlags {
  42.         unsigned short widthTracksTextView:1;
  43.         unsigned short heightTracksTextView:1;
  44.         unsigned short observingFrameChanges:1;
  45.         unsigned short _reserved:13;
  46.     } _tcFlags;
  47. }
  48.  
  49. /**************************** Initialization ****************************/
  50.  
  51. - (id)initWithContainerSize:(NSSize)size;
  52.  
  53. /**************************** Layout and View ****************************/
  54.  
  55. - (NSLayoutManager *)layoutManager;
  56. - (void)setLayoutManager:(NSLayoutManager *)layoutManager;
  57.     // The set method generally should not be called directly, but you may want to override it.  Adding a container to a NSLayoutManager through the provided NSLayoutManager methods will cause the set method to be called appropriately.
  58.  
  59. - (void)replaceLayoutManager:(NSLayoutManager *)newLayoutManager;
  60.     // This method should be used instead of the primitive -setLayoutManager: if you need to replace a container's layoutManager with a new one leaving the rest of the web intact.  All the NSTextContainers on the old NSLayoutManager get transferred to the new one.  This method deals with all the work of making sure the containers don't get deallocated and removing the old layoutManager from the text storage and replacing it with the new one.
  61.  
  62. - (NSTextView *)textView;
  63. - (void)setTextView:(NSTextView *)textView;
  64.     // Set/get the view which the container is drawn in.  Having a view is optional.
  65.  
  66. - (void)setWidthTracksTextView:(BOOL)flag;
  67. - (BOOL)widthTracksTextView;
  68. - (void)setHeightTracksTextView:(BOOL)flag;
  69. - (BOOL)heightTracksTextView;
  70.     // If a container tracks the size of it's view in one or both of these dimensions then those dimensions will be kept in synch with with the view's frame (taking into account the views textContainerInset).
  71.  
  72. /************************* Container size and padding *************************/
  73.  
  74. - (void)setContainerSize:(NSSize)size;
  75. - (NSSize)containerSize;
  76.     // Sets/Returns the current size of the container.  This size has nothing to do with how much text is in the container and how much space it takes up (which the container is not in a position to know).  It is basically the maximum flowable area of the container.  The NSTextView's size will not generally have much connection to this size.  The NSTextView will generally want to be big enough to display all the text which has been laid in the container at the moment and no bigger.  The NSLayoutManager will generally be in charge of telling the view what size it should be.
  77.  
  78. - (void)setLineFragmentPadding:(float)pad;
  79. - (float)lineFragmentPadding;
  80.     // This value is used by the typesetter to inset the line fragment rects it gets along the sweep direction to give a little default pad to each fragment.
  81.  
  82. /**************************** Line fragments ****************************/
  83.  
  84. - (NSRect)lineFragmentRectForProposedRect:(NSRect)proposedRect sweepDirection:(NSLineSweepDirection)sweepDirection movementDirection:(NSLineMovementDirection)movementDirection remainingRect:(NSRect *)remainingRect;
  85.     // Returns the first and largest subrect of proposedRect which falls within the container's region.  All rects are given in the container's coordinate system.  sweepDirection determines what edge of the proposedRect to start from.  movementDirection determines in which direction (if any) the proposedRect can be translated if it is necessary to move the rect to find a non-empty fragment.  remainingRect is set to hold whatever portion of of the proposedRect (after any line movement translation) which is left after subtracting the returned fragment.  The proposed rect should fall within the frame area of the container.  remainingRect will only be non-empty if there are parts of the proposedRect left within the container's frame area ("after" the returned fragment rect in the sweep direction) that are not included in the returned rect.
  86.  
  87. - (BOOL)isSimpleRectangularTextContainer;
  88.     // Subclasses should override this method to return NO if the containers area is not truly rectangular with no holes or concavities.  NSLayoutManager uses this method to determine whether it can make certain optimizations when relaying text in the container.  NSTextContainer's implementation returns YES.
  89.  
  90. /**************************** Hit testing ****************************/
  91.  
  92. - (BOOL)containsPoint:(NSPoint)point;
  93.     // Returns YES if the point (given in the coordinate system of the container) falls within the region of the container.
  94.  
  95. @end
  96.  
  97. #endif
  98.