* GNUmakefile added NSAttributedString.m, NSAttributedString.h,

NSParagraphStyle.m, NSTextAttachment.h, NSTextContainer.h,
		NSTextStorage.h, NSLayoutManager.h and NSParagraphStyle.h.
	* Source added NSParagraphStyle.m.
	* Headers/Appkit added NSTextAttachment.h, NSTextContainer.h,
		NSTextStorage.h, NSLayoutManager.h and NSParagraphStyle.h files.
	* NSText.m and NSText.h. added numerous changes by Daniel B�hringer
	* NSTextView.m and NSTextView.h. added numerous changes by Daniel B�hringer


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@2944 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Felipe A. Rodriguez 1998-09-01 13:23:23 +00:00
parent 1ea46e22c7
commit 6352f5f571
12 changed files with 1635 additions and 147 deletions

View file

@ -1,3 +1,12 @@
Tues Sept 1 1998 Felipe A. Rodriguez <far@ix.netcom.com>
* GNUmakefile added NSAttributedString.m, NSAttributedString.h,
NSParagraphStyle.m, NSTextAttachment.h, NSTextContainer.h,
NSTextStorage.h, NSLayoutManager.h and NSParagraphStyle.h.
* Source added NSParagraphStyle.m.
* Headers/Appkit added NSTextAttachment.h, NSTextContainer.h,
NSTextStorage.h, NSLayoutManager.h and NSParagraphStyle.h files.
Sun Aug 30 1998 Felipe A. Rodriguez <far@ix.netcom.com>
* NSApplication.h added windows_need_update as autodisplay ivar.

View file

@ -0,0 +1,391 @@
/*
NSLayoutManager.h
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.
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.
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Daniel Bðhringer <boehring@biomed.ruhr-uni-bochum.de>
Date: August 1998
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#import <Foundation/Foundation.h>
#import <AppKit/NSFont.h>
@class NSTextStorage;
@class NSTypesetter;
@class NSGlyphGenerator;
@class NSTextContainer;
@class NSTextView;
@class NSWindow;
@class NSColor;
@class NSRulerView;
@class NSParagraphStyle;
@class NSRulerMarker;
@class NSBox;
@class NSTextField;
@class NSMatrix;
@class NSTabWell;
@class NSStorage;
@class NSRunStorage;
@class NSSortedArray;
@class NSView;
@class NSEvent;
// These glyph attributes are used only inside the glyph generation machinery, but must be shared between componenets.
enum _NSGlyphAttribute {
NSGlyphAttributeSoft = 0,
NSGlyphAttributeElastic = 1,
NSGlyphAttributeInscribe = 5,
};
// The inscribe attribute of a glyph determines how it is laid out relative to the previous glyph.
typedef enum {
NSGlyphInscribeBase = 0,
NSGlyphInscribeBelow = 1,
NSGlyphInscribeAbove = 2,
NSGlyphInscribeOverstrike = 3,
NSGlyphInscribeOverBelow = 4
} NSGlyphInscription;
@interface NSLayoutManager : NSObject
{ NSTextStorage *textStorage;
NSGlyphGenerator *glyphGenerator;
NSTypesetter *typesetter;
NSMutableArray *textContainers;
NSStorage *containerUsedRects;
NSStorage *glyphs;
NSRunStorage *containerRuns;
NSRunStorage *fragmentRuns;
NSRunStorage *glyphLocations;
NSRunStorage *glyphRotationRuns;
NSRect extraLineFragmentRect;
NSRect extraLineFragmentUsedRect;
NSTextContainer *extraLineFragmentContainer;
NSSortedArray *glyphHoles;
NSSortedArray *layoutHoles;
id delegate;
// Enable/disable stacks
unsigned short textViewResizeDisableStack;
unsigned short displayInvalidationDisableStack;
NSRange deferredDisplayCharRange;
// Cache for first text view (that is text view of the first text container which has one) (Cost: 4 bytes)
NSTextView *firstTextView;
// Cache for rectangle arrays (Cost: 8 bytes + malloced 16 * <max number of rects returned in an array> bytes)
NSRect *cachedRectArray;
unsigned cachedRectArrayCapacity;
// Cache for glyph strings (used when drawing) (Cost: 8 bytes + malloced glyph buffer size)
char *glyphBuffer;
unsigned glyphBufferSize;
// Cache for faster glyph location lookup (Cost: 20 bytes)
NSRange cachedLocationNominalGlyphRange;
unsigned cachedLocationGlyphIndex;
NSPoint cachedLocation;
// Cache for faster glyph location lookup (Cost: 12 bytes)
NSRange cachedFontCharRange;
NSFont *cachedFont;
// Cache for first unlaid glypha and character (Cost: 8 bytes)
unsigned firstUnlaidGlyphIndex;
unsigned firstUnlaidCharIndex;
// Outlets for ruler accessory view.
NSBox *rulerAccView;
NSMatrix *rulerAccViewAlignmentButtons;
NSTextField *rulerAccViewLeadingField;
NSTabWell *rulerAccViewLeftTabWell;
NSTabWell *rulerAccViewRightTabWell;
NSTabWell *rulerAccViewCenterTabWell;
NSTabWell *rulerAccViewDecimalTabWell;
NSMatrix *rulerAccViewIncrementLineHeightButtons;
NSMatrix *rulerAccViewFixedLineHeightButtons;
NSRange newlyFilledGlyphRange;
}
/**************************** Initialization ****************************/
- (id)init;
// Designated Initializer. Sets up this instance. Finds the shared NSGlyphGenerator and the shared default NSTypesetter. The NSLayoutManager starts off without a NSTextStorage
/*************************** Helper objects ***************************/
- (NSTextStorage *)textStorage;
- (void)setTextStorage:(NSTextStorage *)textStorage;
// 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.
- (void)replaceTextStorage:(NSTextStorage *)newTextStorage;
// 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.
- (id)delegate;
- (void)setDelegate:(id)delegate;
// Sets or gets the NSLayoutManager's delegate.
/**************************** Containers ****************************/
- (NSArray *)textContainers;
-(void)addTextContainer:(NSTextContainer *)container;
// 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).
- (void)insertTextContainer:(NSTextContainer *)container atIndex:(unsigned)index;
// 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.
- (void)removeTextContainerAtIndex:(unsigned)index;
// 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.
- (void)textContainerChangedGeometry:(NSTextContainer *)container;
// Invalidates layout of all glyphs in container and all subsequent containers.
- (void)textContainerChangedTextView:(NSTextContainer *)container;
// Called by NSTextContainer whenever its textView changes. Used to keep notifications in synch.
/************************** Invalidation primitives **************************/
- (void)invalidateGlyphsForCharacterRange:(NSRange)charRange changeInLength:(int)delta actualCharacterRange:(NSRange *)actualCharRange;
// 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.
- (void)invalidateLayoutForCharacterRange:(NSRange)charRange isSoft:(BOOL)flag actualCharacterRange:(NSRange *)actualCharRange;
// 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.
- (void)invalidateDisplayForGlyphRange:(NSRange)glyphRange;
#ifndef STRICT_40
- (void)invalidateDisplayForCharacterRange:(NSRange)charRange;
#endif
// 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.
/******************* Invalidation sent by NSTextStorage *******************/
- (void)textStorage:(NSTextStorage *)str edited:(unsigned)editedMask range:(NSRange)newCharRange changeInLength:(int)delta invalidatedRange:(NSRange)invalidatedCharRange;
// 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.
/*********************** Global layout manager options ***********************/
- (void)setBackgroundLayoutEnabled:(BOOL)flag;
- (BOOL)backgroundLayoutEnabled;
// These methods allow you to set/query whether text gets laid out in the background when there's nothing else to do.
- (void)setShowsInvisibleCharacters:(BOOL)flag;
- (BOOL)showsInvisibleCharacters;
// 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...)
- (void)setShowsControlCharacters:(BOOL)flag;
- (BOOL)showsControlCharacters;
// 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).
/************************ Adding and removing glyphs ************************/
// These methods are primitive. They do not cause the bookkeeping of filling holes to happen. They do not cause invalidation of other stuff.
- (void)insertGlyph:(NSGlyph)glyph atGlyphIndex:(unsigned)glyphIndex characterIndex:(unsigned)charIndex;
// Inserts a single glyph into the glyph stream at glyphIndex. The character index which this glyph corresponds to is given by charIndex.
- (void)replaceGlyphAtIndex:(unsigned)glyphIndex withGlyph:(NSGlyph)newGlyph;
// 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).
- (void)deleteGlyphsInRange:(NSRange)glyphRange;
// Removes all glyphs in the given range from the storage.
- (void)setCharacterIndex:(unsigned)charIndex forGlyphAtIndex:(unsigned)glyphIndex;
// Sets the index of the corresponding character for the glyph at the given glyphIndex.
/************************ Accessing glyphs ************************/
- (unsigned)numberOfGlyphs;
// If there are any holes in the glyph stream, this will cause all invalid character ranges to have glyphs generated for them.
- (NSGlyph)glyphAtIndex:(unsigned)glyphIndex;
- (NSGlyph)glyphAtIndex:(unsigned)glyphIndex isValidIndex:(BOOL *)isValidIndex;
// 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.
- (unsigned)getGlyphs:(NSGlyph *)glyphArray range:(NSRange)glyphRange;
// 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).
// 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.
- (unsigned)characterIndexForGlyphAtIndex:(unsigned)glyphIndex;
// 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.
/************************ Set/Get glyph attributes ************************/
// 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.
- (void)setIntAttribute:(int)attributeTag value:(int)val forGlyphAtIndex:(unsigned)glyphIndex;
// 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.
// This method will cause glyph generation as necessary to answer the question.
- (int)intAttribute:(int)attributeTag forGlyphAtIndex:(unsigned)glyphIndex;
// 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.
/************************ Set/Get layout attributes ************************/
// 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.
- (void)setTextContainer:(NSTextContainer *)container forGlyphRange:(NSRange)glyphRange;
// 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.
- (void)setLineFragmentRect:(NSRect)fragmentRect forGlyphRange:(NSRange)glyphRange usedRect:(NSRect)usedRect;
// Associates the given line fragment bounds with the given range of glyphs.
- (void)setExtraLineFragmentRect:(NSRect)fragmentRect usedRect:(NSRect)usedRect textContainer:(NSTextContainer *)container;
// 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.
- (void)setDrawsOutsideLineFragment:(BOOL)flag forGlyphAtIndex:(unsigned)glyphIndex;
// 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).
- (void)setLocation:(NSPoint)location forStartOfGlyphRange:(NSRange)glyphRange;
// 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.
- (void)setNotShownAttribute:(BOOL)flag forGlyphAtIndex:(unsigned)glyphIndex;
// Some glyphs are not shown. The typesetter decides which ones and sets this attribute in layoutManager where the view can find it.
- (NSTextContainer *)textContainerForGlyphAtIndex:(unsigned)glyphIndex effectiveRange:(NSRange *)effectiveGlyphRange;
// 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.
- (NSRect)usedRectForTextContainer:(NSTextContainer *)container;
// 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.
- (NSRect)lineFragmentRectForGlyphAtIndex:(unsigned)glyphIndex effectiveRange:(NSRange *)effectiveGlyphRange;
// 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.
- (NSRect)lineFragmentUsedRectForGlyphAtIndex:(unsigned)glyphIndex effectiveRange:(NSRange *)effectiveGlyphRange;
// 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.
- (NSRect)extraLineFragmentRect;
- (NSRect)extraLineFragmentUsedRect;
- (NSTextContainer *)extraLineFragmentTextContainer;
// Return info about the extra line fragment.
- (BOOL)drawsOutsideLineFragmentForGlyphAtIndex:(unsigned) glyphIndex;
// Returns whether the glyph will make marks outside its line fragment's bounds.
- (NSPoint)locationForGlyphAtIndex:(unsigned)glyphIndex;
// 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.
- (BOOL)notShownAttributeForGlyphAtIndex:(unsigned) glyphIndex;
// Some glyphs are not shown. This will cause glyph generation and layout as needed..
/************************ More sophisticated queries ************************/
// These two methods can cause glyph generation.
- (NSRange)glyphRangeForCharacterRange:(NSRange)charRange actualCharacterRange:(NSRange *)actualCharRange;
// 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.
- (NSRange)characterRangeForGlyphRange:(NSRange)glyphRange actualGlyphRange:(NSRange *)actualGlyphRange;
// 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.
// All of these methods can cause glyph generation AND layout.
- (NSRange)glyphRangeForTextContainer:(NSTextContainer *)container;
// Returns the range of characters which have been laid into the given container. This is a less efficient method than the similar -textContainerForGlyphAtIndex:effectiveRange:.
- (NSRange)rangeOfNominallySpacedGlyphsContainingIndex:(unsigned)glyphIndex;
// 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.
- (NSRect *)rectArrayForCharacterRange:(NSRange)charRange withinSelectedCharacterRange:(NSRange)selCharRange inTextContainer:(NSTextContainer *)container rectCount:(unsigned *)rectCount;
- (NSRect *)rectArrayForGlyphRange:(NSRange)glyphRange withinSelectedGlyphRange:(NSRange)selGlyphRange inTextContainer:(NSTextContainer *)container rectCount:(unsigned *)rectCount;
// 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.
// 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.
- (NSRect)boundingRectForGlyphRange:(NSRange)glyphRange inTextContainer:(NSTextContainer *)container;
// 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.
- (NSRange)glyphRangeForBoundingRect:(NSRect)bounds inTextContainer:(NSTextContainer *)container;
- (NSRange)glyphRangeForBoundingRectWithoutAdditionalLayout:(NSRect)bounds inTextContainer:(NSTextContainer *)container;
// 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.
- (unsigned)glyphIndexForPoint:(NSPoint)point inTextContainer:(NSTextContainer *)container fractionOfDistanceThroughGlyph:(float *)partialFraction;
// 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.
- (void)getFirstUnlaidCharacterIndex:(unsigned *)charIndex glyphIndex:(unsigned *)glyphIndex;
// Returns (by reference) the character index or glyph index or both of the first unlaid character/glyph in the layout manager at this time.
/************************ Screen font usage control ************************/
- (BOOL)usesScreenFonts;
- (void)setUsesScreenFonts:(BOOL)flag;
// Sets whether this layoutManager will use screen fonts when it is possible to do so.
- (NSFont *)substituteFontForFont:(NSFont *)originalFont;
// 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.
@end
@interface NSLayoutManager (NSTextViewSupport)
/************************ Ruler stuff ************************/
- (NSArray *)rulerMarkersForTextView:(NSTextView *)view paragraphStyle:(NSParagraphStyle *)style ruler:(NSRulerView *)ruler;
- (NSView *)rulerAccessoryViewForTextView:(NSTextView *)view paragraphStyle:(NSParagraphStyle *)style ruler:(NSRulerView *)ruler enabled:(BOOL)isEnabled;
// 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.
/************************ First responder support ************************/
- (BOOL)layoutManagerOwnsFirstResponderInWindow:(NSWindow *)window;
// Returns YES if the firstResponder of the given window is one of the NSTextViews attached to this NSLayoutManager.
- (NSTextView *)firstTextView;
- (NSTextView *)textViewForBeginningOfSelection;
// 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.
/************************ Drawing support ************************/
- (void)drawBackgroundForGlyphRange:(NSRange)glyphsToShow atPoint:(NSPoint)origin;
- (void)drawGlyphsForGlyphRange:(NSRange)glyphsToShow atPoint:(NSPoint)origin;
// 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.
- (void)drawUnderlineForGlyphRange:(NSRange)glyphRange underlineType:(int)underlineVal baselineOffset:(float)baselineOffset lineFragmentRect:(NSRect)lineRect lineFragmentGlyphRange:(NSRange)lineGlyphRange containerOrigin:(NSPoint)containerOrigin;
- (void)underlineGlyphRange:(NSRange)glyphRange underlineType:(int)underlineVal lineFragmentRect:(NSRect)lineRect lineFragmentGlyphRange:(NSRange)lineGlyphRange containerOrigin:(NSPoint)containerOrigin;
// 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.
@end
@interface NSObject (NSLayoutManagerDelegate)
- (void)layoutManagerDidInvalidateLayout:(NSLayoutManager *)sender;
// This is sent whenever layout or glyphs become invalidated in a layout manager which previously had all layout complete.
- (void)layoutManager:(NSLayoutManager *)layoutManager didCompleteLayoutForTextContainer:(NSTextContainer *)textContainer atEnd:(BOOL)layoutFinishedFlag;
// 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.
@end

View file

@ -0,0 +1,107 @@
/*
NSParagraphStyle.h
NSParagraphStyle and NSMutableParagraphStyle hold paragraph style
information NSTextTab holds information about a single tab stop
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Daniel Bðhringer <boehring@biomed.ruhr-uni-bochum.de>
Date: August 1998
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import <Foundation/Foundation.h>
#import "NSText.h"
typedef enum _NSTextTabType {
NSLeftTabStopType = 0,
NSRightTabStopType,
NSCenterTabStopType,
NSDecimalTabStopType
} NSTextTabType;
typedef enum _NSLineBreakMode { /* What to do with long lines */
NSLineBreakByWordWrapping = 0, /* Wrap at word boundaries, default */
NSLineBreakByCharWrapping, /* Wrap at character boundaries */
NSLineBreakByClipping, /* Simply clip */
NSLineBreakByTruncatingHead, /* Truncate at head of line: "...wxyz" */
NSLineBreakByTruncatingTail, /* Truncate at tail of line: "abcd..." */
NSLineBreakByTruncatingMiddle /* Truncate middle of line: "ab...yz" */
} NSLineBreakMode;
@interface NSTextTab : NSObject <NSCopying, NSCoding>
{ NSTextTabType tabStopType;
float location;
}
- initWithType:(NSTextTabType)type location:(float)loc;
-(float) location;
-(NSTextTabType) tabStopType;
@end
@interface NSParagraphStyle : NSObject <NSCopying, NSMutableCopying, NSCoding>
{ float lineSpacing;
float paragraphSpacing;
float headIndent;
float tailIndent;
float firstLineHeadIndent;
float minimumLineHeight,maximumLineHeight;
NSArray *tabStops;
NSTextAlignment alignment;
NSLineBreakMode lineBreakMode;
unsigned int refCount;
}
+ (NSParagraphStyle *)defaultParagraphStyle;
- (float)lineSpacing; /* "Leading": distance between the bottom of one line fragment and top of next (applied between lines in the same container). Can't be negative. This value is included in the line fragment heights in layout manager. */
- (float)paragraphSpacing; /* Distance between the bottom of this paragraph and top of next. */
- (NSTextAlignment)alignment;
/* The following values are relative to the appropriate margin (depending on the paragraph direction) */
- (float)headIndent; /* Distance from margin to front edge of paragraph */
- (float)tailIndent; /* Distance from margin to back edge of paragraph; if negative or 0, from other margin */
- (float)firstLineHeadIndent; /* Distance from margin to edge appropriate for text direction */
- (NSArray *)tabStops; /* Distance from margin to tab stops */
- (float)minimumLineHeight; /* Line height is the distance from bottom of descenders to top of ascenders; basically the line fragment height. Does not include lineSpacing (which is added after this computation). */
- (float)maximumLineHeight; /* 0 implies no maximum. */
- (NSLineBreakMode)lineBreakMode;
@end
@interface NSMutableParagraphStyle : NSParagraphStyle
- (void)setLineSpacing:(float)aFloat;
- (void)setParagraphSpacing:(float)aFloat;
- (void)setAlignment:(NSTextAlignment)alignment;
- (void)setFirstLineHeadIndent:(float)aFloat;
- (void)setHeadIndent:(float)aFloat;
- (void)setTailIndent:(float)aFloat;
- (void)setLineBreakMode:(NSLineBreakMode)mode;
- (void)setMinimumLineHeight:(float)aFloat;
- (void)setMaximumLineHeight:(float)aFloat;
- (void)addTabStop:(NSTextTab *)anObject;
- (void)removeTabStop:(NSTextTab *)anObject;
- (void)setTabStops:(NSArray *)array;
- (void)setParagraphStyle:(NSParagraphStyle *)obj;
@end

View file

@ -71,12 +71,11 @@ typedef enum _NSSelectionGranularity
NSSelectByParagraph = 2,
} NSSelectionGranularity;
#if GNUSTEP
typedef enum _NSSelectionAffinity
{ NSSelectionAffinityUpstream = 0,
NSSelectionAffinityDownstream = 1,
} NSSelectionAffinity;
#endif
@interface NSText : NSView <NSChangeSpelling,NSIgnoreMisspelledWords,NSCoding>
{
@ -108,21 +107,31 @@ typedef enum _NSSelectionAffinity
NSCharacterSet *selectionParagraphGranularitySet;
}
// GNU utility methods
// return value is guaranteed to be a NSAttributedString even if data is only NSString
+(NSAttributedString*) attributedStringForData:(NSData*) aData;
+(NSData*) dataForAttributedString:(NSAttributedString*) aString;
+(NSString*) newlineString; // GNU extension (override it if you want other characters treated as newline characters)
//
// Getting and Setting Contents
//
- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)aString;
- (void)replaceCharactersInRange:(NSRange)range withRTF:(NSData *)rtfData;
- (void)replaceCharactersInRange:(NSRange)range withRTFD:(NSData *)rtfdData;
- (void)replaceRange:(NSRange)range withRTF:(NSData *)rtfData;
- (void)replaceRange:(NSRange)range withRTFD:(NSData *)rtfdData;
- (NSData *)RTFDFromRange:(NSRange)range;
- (NSData *)RTFFromRange:(NSRange)range;
- (void)setText:(NSString *)string;
- (void)setText:(NSString *)string range:(NSRange)range;
- (NSString *)text;
- (NSString *)string;
- (void)setString:(NSString *)string; // old fashioned
-(void) replaceRange:(NSRange)range withAttributedString:(NSAttributedString*)attrString; // GNU extension
-(void) replaceRange:(NSRange)range withString:(NSString*) aString;
-(void) replaceRange:(NSRange)range withRTF:(NSData *)rtfData;
-(void) replaceRange:(NSRange)range withRTFD:(NSData *)rtfdData;
-(NSData*) RTFDFromRange:(NSRange)range;
-(NSData*) RTFFromRange:(NSRange)range;
-(void) setString:(NSString *)string;
-(void) setText:(NSString *)string; // old fashioned
-(void) setText:(NSString*) aString range:(NSRange) aRange; // old fashioned
-(NSString*) string;
-(NSString*) text; // old fashioned
-(unsigned) textLength; // GNU extension
//
// Managing Global Characteristics
@ -147,6 +156,7 @@ typedef enum _NSSelectionAffinity
- (void)changeFont:(id)sender;
- (NSFont *)font;
- (void)setBackgroundColor:(NSColor *)color;
-(void) setTextColor:(NSColor *)color range:(NSRange)range;
- (void)setColor:(NSColor *)color ofRange:(NSRange)range;
- (void)setFont:(NSFont *)obj;
- (void)setFont:(NSFont *)font ofRange:(NSRange)range;
@ -203,8 +213,8 @@ typedef enum _NSSelectionAffinity
//
// Spelling
//
- (void)checkSpelling:(id)sender;
- (void)showGuessPanel:(id)sender;
-(void) checkSpelling:(id)sender;
-(void) showGuessPanel:(id)sender;
//
// Scrolling
@ -214,8 +224,8 @@ typedef enum _NSSelectionAffinity
//
// Reading and Writing RTFD Files
//
- (BOOL)readRTFDFromFile:(NSString *)path;
- (BOOL)writeRTFDToFile:(NSString *)path atomically:(BOOL)flag;
-(BOOL) readRTFDFromFile:(NSString *)path;
-(BOOL) writeRTFDToFile:(NSString *)path atomically:(BOOL)flag;
//
// Managing the Field Editor
@ -229,14 +239,6 @@ typedef enum _NSSelectionAffinity
- (id)delegate;
- (void)setDelegate:(id)anObject;
//
// Implemented by the Delegate
//
- (void)textDidBeginEditing:(NSNotification *)aNotification;
- (void)textDidChange:(NSNotification *)aNotification;
- (void)textDidEndEditing:(NSNotification *)aNotification;
- (BOOL)textShouldBeginEditing:(NSText *)textObject;
- (BOOL)textShouldEndEditing:(NSText *)textObject;
//
// NSCoding protocol
@ -254,6 +256,50 @@ typedef enum _NSSelectionAffinity
//
- (void)ignoreSpelling:(id)sender;
//
// these NSTextView methods are here only informally
//
-(int) spellCheckerDocumentTag;
-(void) insertText:(NSString *)insertString;
-(NSMutableDictionary*) typingAttributes;
-(void) setTypingAttributes:(NSDictionary *)attrs;
-(BOOL) shouldDrawInsertionPoint;
-(void) drawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)flag;
-(NSArray*) acceptableDragTypes;
-(void) updateDragTypeRegistration;
-(NSRange) selectionRangeForProposedRange:(NSRange)proposedCharRange granularity:(NSSelectionGranularity)granularity;
//
// these NSLayoutManager- like methods are here only informally
//
-(unsigned) characterIndexForPoint:(NSPoint)point;
-(NSRect) rectForCharacterIndex:(unsigned) index;
-(NSRect) boundingRectForLineRange:(NSRange)lineRange;
-(NSRange) characterRangeForBoundingRect:(NSRect)bounds;
//
// these are implementation specific
//
-(int) rebuildPlainLineLayoutInformationStartingAtLine:(int) aLine; // returns count of lines actually updated (e.g. drawing optimization)
-(int) rebuildRichLineLayoutInformationStartingAtLine:(int) aLine;
-(int) lineLayoutIndexForCharacterIndex:(unsigned) anIndex; // is identical to the real line number (not just counted return characters)
-(void) redisplayForLineRange:(NSRange) redrawLineRange;
-(void) drawRichLinesInLineRange:(NSRange) aRange; // private (use redisplayForLineRange:)
-(void) drawPlainLinesInLineRange:(NSRange) aRange; // private (use redisplayForLineRange:)
//
// various GNU extensions
//
-(void) setSelectionWordGranularitySet:(NSCharacterSet*) aSet;
-(void) setSelectionParagraphGranularitySet:(NSCharacterSet*) aSet;
@end
/* Notifications */
@ -261,4 +307,25 @@ extern NSString *NSTextDidBeginEditingNotification;
extern NSString *NSTextDidEndEditingNotification;
extern NSString *NSTextDidChangeNotification;
@interface NSObject(NSTextDelegate)
- (BOOL)textShouldBeginEditing:(NSText *)textObject; /* YES means do it */
- (BOOL)textShouldEndEditing:(NSText *)textObject; /* YES means do it */
- (void)textDidBeginEditing:(NSNotification *)notification;
- (void)textDidEndEditing:(NSNotification *)notification;
- (void)textDidChange:(NSNotification *)notification; /* Any keyDown or paste which changes the contents causes this */
@end
#endif // _GNUstep_H_NSText
#if 0
NSFontAttributeName; /* NSFont, default Helvetica 12 */
-> NSParagraphStyleAttributeName; /* NSParagraphStyle, default defaultParagraphStyle */
NSForegroundColorAttributeName; /* NSColor, default blackColor */
NSUnderlineStyleAttributeName; /* int, default 0: no underline */
NSSuperscriptAttributeName; /* int, default 0 */
NSBackgroundColorAttributeName; /* NSColor, default nil: no background */
-> NSAttachmentAttributeName; /* NSTextAttachment, default nil */
NSLigatureAttributeName; /* int, default 1: default ligatures, 0: no ligatures, 2: all ligatures */
NSBaselineOffsetAttributeName; /* float, in points; offset from baseline, default 0 */
NSKernAttributeName; /* float, amount to modify default kerning, if 0, kerning off */
#endif

View file

@ -0,0 +1,115 @@
/*
NSTextAttachment.h
Classes to represent text attachments.
NSTextAttachment is used to represent text attachments. When inline,
text attachments appear as the value of the NSAttachmentAttributeName
attached to the special character NSAttachmentCharacter.
NSTextAttachment uses an object obeying the NSTextAttachmentCell
protocol to get input from the user and to display an image.
NSTextAttachmentCell is a simple subclass of NSCell which provides
the NSTextAttachment protocol.
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Daniel Bðhringer <boehring@biomed.ruhr-uni-bochum.de>
Date: August 1998
Source by Daniel Bðhringer integrated into GNUstep gui
by Felipe A. Rodriguez <far@ix.netcom.com>
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef STRICT_OPENSTEP
#import <Foundation/Foundation.h>
#import <AppKit/NSCell.h>
#import <AppKit/NSAttributedString.h>
@class NSFileWrapper;
@class NSTextAttachment;
enum {
NSAttachmentCharacter = 0xfffc /* To denote attachments. */
};
/* These are the only methods required of cells in text attachments... The default NSCell class implements most of these; the NSTextAttachmentCell class is a subclass which implements all and provides some additional functionality.
*/
@protocol NSTextAttachmentCell <NSObject>
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
- (BOOL)wantsToTrackMouse;
- (void)highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView:(NSView *)controlView;
- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)flag;
- (NSSize)cellSize;
- (NSPoint)cellBaselineOffset;
- (void)setAttachment:(NSTextAttachment *)anObject;
- (NSTextAttachment *)attachment;
@end
/* Simple class to provide basic attachment cell functionality. By default this class causes NSTextView to send out delegate messages when the attachment is clicked on or dragged.
*/
@interface NSTextAttachmentCell : NSCell <NSTextAttachmentCell> {
NSTextAttachment *_attachment;
}
@end
@interface NSTextAttachment : NSObject <NSCoding> {
NSFileWrapper *_fileWrapper;
id <NSTextAttachmentCell>_cell;
struct {
unsigned int cellWasExplicitlySet:1;
unsigned int :31;
} _flags;
}
/* Designated initializer.
*/
- (id)initWithFileWrapper:(NSFileWrapper *)fileWrapper;
/* The fileWrapper is the meat of most types of attachment. It can be set or queried with these methods. An NSTextAttachment usually has a fileWrapper. setFileWrapper does not update the attachment's cell in any way.
*/
- (void)setFileWrapper:(NSFileWrapper *)fileWrapper;
- (NSFileWrapper *)fileWrapper;
/* The cell which handles user interaction. By default an instance of NSTextAttachmentCell is used.
*/
- (id <NSTextAttachmentCell>)attachmentCell;
- (void)setAttachmentCell:(id <NSTextAttachmentCell>)cell;
@end
/* Convenience for creating an attributed string with an attachment.
*/
@interface NSAttributedString (NSAttributedStringAttachmentConveniences)
+ (NSAttributedString *)attributedStringWithAttachment:(NSTextAttachment *)attachment;
@end
@interface NSMutableAttributedString (NSMutableAttributedStringAttachmentConveniences)
- (void)updateAttachmentsFromPath:(NSString *)path;
@end
#endif

View file

@ -0,0 +1,118 @@
/*
NSTextContainer.h
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.
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).
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Daniel Bðhringer <boehring@biomed.ruhr-uni-bochum.de>
Date: August 1998
Source by Daniel Bðhringer integrated into GNUstep gui
by Felipe A. Rodriguez <far@ix.netcom.com>
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#import <Foundation/Foundation.h>
@class NSLayoutManager;
@class NSTextView;
typedef enum {
NSLineSweepLeft = 0,
NSLineSweepRight = 1,
NSLineSweepDown = 2,
NSLineSweepUp = 3,
} NSLineSweepDirection;
typedef enum {
NSLineDoesntMove = 0,
NSLineMovesLeft = 1,
NSLineMovesRight = 2,
NSLineMovesDown = 3,
NSLineMovesUp = 4,
} NSLineMovementDirection;
@interface NSTextContainer : NSObject
{ NSLayoutManager *layoutManager;
NSTextView *textView;
NSSize size;
float lineFragmentPadding;
BOOL widthTracksTextView;
BOOL heightTracksTextView;
BOOL observingFrameChanges;
}
/**************************** Initialization ****************************/
- (id)initWithContainerSize:(NSSize)size;
/**************************** Layout and View ****************************/
- (NSLayoutManager *)layoutManager;
- (void)setLayoutManager:(NSLayoutManager *)layoutManager;
// 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.
- (void)replaceLayoutManager:(NSLayoutManager *)newLayoutManager;
// 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.
- (NSTextView *)textView;
- (void)setTextView:(NSTextView *)textView;
// Set/get the view which the container is drawn in. Having a view is optional.
- (void)setWidthTracksTextView:(BOOL)flag;
- (BOOL)widthTracksTextView;
- (void)setHeightTracksTextView:(BOOL)flag;
- (BOOL)heightTracksTextView;
// 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).
/************************* Container size and padding *************************/
- (void)setContainerSize:(NSSize)size;
- (NSSize)containerSize;
// 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.
- (void)setLineFragmentPadding:(float)pad;
- (float)lineFragmentPadding;
// 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.
/**************************** Line fragments ****************************/
- (NSRect)lineFragmentRectForProposedRect:(NSRect)proposedRect sweepDirection:(NSLineSweepDirection)sweepDirection movementDirection:(NSLineMovementDirection)movementDirection remainingRect:(NSRect *)remainingRect;
// 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.
- (BOOL)isSimpleRectangularTextContainer;
// 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.
/**************************** Hit testing ****************************/
- (BOOL)containsPoint:(NSPoint)point;
// Returns YES if the point (given in the coordinate system of the container) falls within the region of the container.
@end

View file

@ -0,0 +1,104 @@
/*
NSTextStorage.h
NSTextStorage is a semi-abstract subclass of NSMutableAttributedString. It
implements change management (beginEditing/endEditing), verification of
attributes, delegate handling, and layout management notification. The one
aspect it does not implement is the actual attributed string storage ---
this is left up to the subclassers, which need to override the two
NSMutableAttributedString primitives:
- (void)replaceCharactersInRange:(NSRange)range
withString:(NSString *)str;
- (void)setAttributes:(NSDictionary *)attrs
range:(NSRange)range;
These primitives should perform the change then call
edited:range:changeInLength: to get everything else to happen.
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Daniel Bðhringer <boehring@biomed.ruhr-uni-bochum.de>
Date: August 1998
Source by Daniel Bðhringer integrated into GNUstep gui
by Felipe A. Rodriguez <far@ix.netcom.com>
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#import <Foundation/Foundation.h>
#import <AppKit/NSAttributedString.h>
@class NSLayoutManager;
/* These values are or'ed together in notifications to indicate what got changed.
*/
enum
{ NSTextStorageEditedAttributes = 1,
NSTextStorageEditedCharacters = 2
};
@interface NSTextStorage : NSMutableAttributedString {
NSRange editedRange;
int editedDelta;
NSMutableArray *layoutManagers;
id delegate;
}
// These methods manage the list of layout managers.
- (void)addLayoutManager:(NSLayoutManager *)obj; /* Retains & calls setTextStorage: on the item */
- (void)removeLayoutManager:(NSLayoutManager *)obj;
- (NSArray *)layoutManagers;
/* If there are no outstanding beginEditing calls, this method calls processEditing to cause post-editing stuff to happen. This method has to be called by the primitives after changes are made. The range argument to edited:... is the range in the original string (before the edit).
*/
- (void)edited:(unsigned)editedMask range:(NSRange)range changeInLength:(int)delta;
/* This is called from edited:range:changeInLength: or endEditing. This method sends out NSTextStorageWillProcessEditing, then fixes the attributes, then sends out NSTextStorageDidProcessEditing, and finally notifies the layout managers of change with the textStorage:edited:range:changeInLength:invalidatedRange: method.
*/
- (void)processEditing;
/* These methods return information about the editing status. Especially useful when there are outstanding beginEditing calls or during processEditing... editedRange.location will be NSNotFound if nothing has been edited.
*/
- (unsigned)editedMask;
- (NSRange)editedRange;
- (int)changeInLength;
/* Set/get the delegate
*/
- (void)setDelegate:(id)delegate;
- (id)delegate;
@end
/**** NSTextStorage delegate methods ****/
@interface NSObject (NSTextStorageDelegate)
/* These methods are sent during processEditing:. The receiver can use the callback methods editedMask, editedRange, and changeInLength to see what has changed. Although these methods can change the contents of the text storage, it's best if only the delegate did this.
*/
- (void)textStorageWillProcessEditing:(NSNotification *)notification; /* Delegate can change the characters or attributes */
- (void)textStorageDidProcessEditing:(NSNotification *)notification; /* Delegate can change the attributes */
@end
/**** Notifications ****/
extern NSString *NSTextStorageWillProcessEditingNotification;
extern NSString *NSTextStorageDidProcessEditingNotification;

View file

@ -1,6 +1,9 @@
/*
NSTextView.h
NSTextView is an NSText subclass that displays the glyphs laid
out in one NSTextContainer.
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Daniel Bðhringer <boehring@biomed.ruhr-uni-bochum.de>
@ -29,36 +32,232 @@
#define _GNUstep_H_NSTextView
#include <AppKit/NSText.h>
#include <AppKit/NSTextAttachment.h>
@class NSTextContainer;
@class NSTextStorage;
@class NSLayoutManager;
@class NSRulerView;
@class NSRulerMarker;
//@interface NSTextView : NSText <NSTextInput>
@interface NSTextView : NSText
{
NSDictionary *typingAttributes;
int spellCheckerDocumentTag;
{ NSTextContainer *textContainer;
NSColor *insertionPointColor;
BOOL smartInsertDeleteEnabled;
NSSelectionAffinity selectionAffinity;
NSSelectionGranularity selectionGranularity;
NSSize textContainerInset;
NSPoint textContainerOrigin;
NSLayoutManager *layoutManager;
NSTextStorage *textStorage;
}
- (void)insertText:(NSString *)insertString;
/**************************** Initializing ****************************/
- (NSDictionary*)typingAttributes;
- (void)setTypingAttributes:(NSDictionary *)attrs;
+(void) registerForServices;
// This is sent each time a view is initialized. If you subclass you should ensure that you only register once.
- initWithFrame:(NSRect)frameRect textContainer:(NSTextContainer *)container;
// Designated Initializer. container may be nil.
- initWithFrame:(NSRect)frameRect;
// This variant will create the text network (textStorage, layoutManager, and a container).
/***************** Get/Set the container and other stuff *****************/
-(NSTextContainer*) textContainer;
-(void)setTextContainer:(NSTextContainer*) container;
// The set method should not be called directly, but you might want to override it. Gets or sets the text container for this view. Setting the text container marks the view as needing display. The text container calls the set method from its setTextView: method.
- (void)replaceTextContainer:(NSTextContainer *)newContainer;
// This method should be used instead of the primitive -setTextContainer: if you need to replace a view's text container with a new one leaving the rest of the web intact. This method deals with all the work of making sure the view doesn't get deallocated and removing the old container from the layoutManager and replacing it with the new one.
- (void)setTextContainerInset:(NSSize)inset;
- (NSSize)textContainerInset;
// The textContianerInset determines the padding that the view provides around the container. The container's origin will be inset by this amount from the bounds point {0,0} and padding will be left to the right and below the container of the same amount. This inset affects the view sizing in response to new layout and is used by the rectangular text containers when they track the view's frame dimensions.
- (NSPoint)textContainerOrigin;
- (void)invalidateTextContainerOrigin;
// The container's origin in the view is determined from the current usage of the container, the container inset, and the view size. textContainerOrigin returns this point. invalidateTextContainerOrigin is sent automatically whenever something changes that causes the origin to possibly move. You usually do not need to call invalidate yourself.
- (NSLayoutManager *)layoutManager;
- (NSTextStorage *)textStorage;
// Convenience methods
/************************* Key binding entry-point *************************/
- (void)insertText:(NSString *)insertString;
// This method is the funnel point for text insertion after keys pass through the key binder.
/*************************** Sizing methods ***************************/
- (void)setConstrainedFrameSize:(NSSize)desiredSize;
// Sets the frame size of the view to desiredSize constrained within min and max size.
/***************** New miscellaneous API above and beyond NSText *****************/
- (void)setAlignment:(NSTextAlignment)alignment range:(NSRange)range;
// These complete the set of range: type set methods. to be equivalent to the set of non-range taking varieties.
- (void)pasteAsPlainText:(id)sender;
- (void)pasteAsRichText:(id)sender;
// These methods are like paste: (from NSResponder) but they restrict the acceptable type of the pasted data. They are suitable as menu actions for appropriate "Paste As" submenu commands.
/*************************** New Font menu commands ***************************/
- (void)turnOffKerning:(id)sender;
- (void)tightenKerning:(id)sender;
- (void)loosenKerning:(id)sender;
- (void)useStandardKerning:(id)sender;
- (void)turnOffLigatures:(id)sender;
- (void)useStandardLigatures:(id)sender;
- (void)useAllLigatures:(id)sender;
- (void)raiseBaseline:(id)sender;
- (void)lowerBaseline:(id)sender;
/*************************** Ruler support ***************************/
- (void)rulerView:(NSRulerView *)ruler didMoveMarker:(NSRulerMarker *)marker;
- (void)rulerView:(NSRulerView *)ruler didRemoveMarker:(NSRulerMarker *)marker;
- (void)rulerView:(NSRulerView *)ruler didAddMarker:(NSRulerMarker *)marker;
- (BOOL)rulerView:(NSRulerView *)ruler shouldMoveMarker:(NSRulerMarker *)marker;
- (BOOL)rulerView:(NSRulerView *)ruler shouldAddMarker:(NSRulerMarker *)marker;
- (float)rulerView:(NSRulerView *)ruler willMoveMarker:(NSRulerMarker *)marker toLocation:(float)location;
- (BOOL)rulerView:(NSRulerView *)ruler shouldRemoveMarker:(NSRulerMarker *)marker;
- (float)rulerView:(NSRulerView *)ruler willAddMarker:(NSRulerMarker *)marker atLocation:(float)location;
- (void)rulerView:(NSRulerView *)ruler handleMouseDown:(NSEvent *)event;
/*************************** Fine display control ***************************/
- (void)setNeedsDisplayInRect:(NSRect)rect avoidAdditionalLayout:(BOOL)flag;
- (BOOL)shouldDrawInsertionPoint;
- (void)drawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)flag;
/*************************** Especially for subclassers ***************************/
- (void)updateRuler;
- (void)updateFontPanel;
- (NSArray *)acceptableDragTypes;
- (void)updateDragTypeRegistration;
- (NSRange) selectionRangeForProposedRange:(NSRange)proposedCharRange
granularity:(NSSelectionGranularity)granularity;
- (NSRange)selectionRangeForProposedRange:(NSRange)proposedCharRange granularity:(NSSelectionGranularity)granularity;
- (int)spellCheckerDocumentTag;
//
// Managing the Selection NSText method
//
- (void)setSelectedRange:(NSRange)range;
//
// NSIgnoreMisspelledWords protocol
//
- (void)ignoreSpelling:(id)sender;
@end
@interface NSTextView (NSSharing)
// The methods in this category deal with settings that need to be shared by all the NSTextViews of a single NSLayoutManager. Many of these methods are overrides of NSText or NSResponder methods.
/*************************** Selected/Marked range ***************************/
- (void)setSelectedRange:(NSRange)charRange affinity:(NSSelectionAffinity)affinity stillSelecting:(BOOL)stillSelectingFlag;
- (NSSelectionAffinity)selectionAffinity;
- (NSSelectionGranularity)selectionGranularity;
- (void)setSelectionGranularity:(NSSelectionGranularity)granularity;
- (void)setSelectedTextAttributes:(NSDictionary *)attributeDictionary;
- (NSDictionary *)selectedTextAttributes;
- (void)setInsertionPointColor:(NSColor *)color;
- (NSColor *)insertionPointColor;
- (void)updateInsertionPointStateAndRestartTimer:(BOOL)restartFlag;
- (NSRange)markedRange;
- (void)setMarkedTextAttributes:(NSDictionary *)attributeDictionary;
- (NSDictionary *)markedTextAttributes;
/*************************** Other NSTextView methods ***************************/
- (void)setRulerVisible:(BOOL)flag;
- (BOOL)usesRuler;
- (void)setUsesRuler:(BOOL)flag;
- (int)spellCheckerDocumentTag;
- (NSDictionary *)typingAttributes;
- (void)setTypingAttributes:(NSDictionary *)attrs;
- (BOOL)shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString;
- (void)didChangeText;
- (NSRange)rangeForUserTextChange;
- (NSRange)rangeForUserCharacterAttributeChange;
- (NSRange)rangeForUserParagraphAttributeChange;
/*************************** NSText methods ***************************/
//- (BOOL)isSelectable;
//- (void)setSelectable:(BOOL)flag;
//- (BOOL)isEditable;
//- (void)setEditable:(BOOL)flag;
//- (BOOL)isRichText;
//- (void)setRichText:(BOOL)flag;
//- (BOOL)importsGraphics;
//- (void)setImportsGraphics:(BOOL)flag;
//- (id)delegate;
//- (void)setDelegate:(id)anObject;
//- (BOOL)isFieldEditor;
//- (void)setFieldEditor:(BOOL)flag;
//- (BOOL)usesFontPanel;
//- (void)setUsesFontPanel:(BOOL)flag;
//- (BOOL)isRulerVisible;
//- (void)setBackgroundColor:(NSColor *)color;
//- (NSColor *)backgroundColor;
//- (void)setDrawsBackground:(BOOL)flag;
//- (BOOL)drawsBackground;
//- (NSRange)selectedRange;
//- (void)setSelectedRange:(NSRange)charRange;
/*************************** NSResponder methods ***************************/
- (BOOL)resignFirstResponder;
- (BOOL)becomeFirstResponder;
/*************************** Smart copy/paste/delete support ***************************/
- (BOOL)smartInsertDeleteEnabled;
- (void)setSmartInsertDeleteEnabled:(BOOL)flag;
- (NSRange)smartDeleteRangeForProposedRange:(NSRange)proposedCharRange;
- (void)smartInsertForString:(NSString *)pasteString replacingRange:(NSRange)charRangeToReplace beforeString:(NSString **)beforeString afterString:(NSString **)afterString;
@end
// Note that all delegation messages come from the first textView
@interface NSObject (NSTextViewDelegate)
- (void)textView:(NSTextView *)textView clickedOnCell:(id <NSTextAttachmentCell>)cell inRect:(NSRect)cellFrame; // Delegate only.
- (void)textView:(NSTextView *)textView doubleClickedOnCell:(id <NSTextAttachmentCell>)cell inRect:(NSRect)cellFrame;
// Delegate only.
- (void)textView:(NSTextView *)view draggedCell:(id <NSTextAttachmentCell>)cell inRect:(NSRect)rect event:(NSEvent *)event; // Delegate only
- (NSRange)textView:(NSTextView *)textView willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange toCharacterRange:(NSRange)newSelectedCharRange;
// Delegate only.
- (void)textViewDidChangeSelection:(NSNotification *)notification;
- (BOOL)textView:(NSTextView *)textView shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString;
// Delegate only. If characters are changing, replacementString is what will replace the affectedCharRange. If attributes only are changing, replacementString will be nil.
- (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector;
@end
extern NSString *NSTextViewWillChangeNotifyingTextViewNotification;
// NSOldNotifyingTextView -> the old view, NSNewNotifyingTextView -> the new view. The text view delegate is not automatically registered to receive this notification because the text machinery will automatically switch over the delegate to observe the new first text view as the first text view changes.
extern NSString *NSTextViewDidChangeSelectionNotification;
// NSOldSelectedCharacterRange -> NSValue with old range.
#endif /* _GNUstep_H_NSTextView */

View file

@ -39,6 +39,7 @@ LIBRARY_NAME=libgnustep-gui
libgnustep-gui_OBJC_FILES = libgnustep-gui.m \
NSActionCell.m \
NSApplication.m \
NSAttributedString.m \
NSBitmapImageRep.m \
NSBox.m \
NSBrowser.m \
@ -79,6 +80,7 @@ NSMenuItem.m \
NSOpenPanel.m \
NSPageLayout.m \
NSPanel.m \
NSParagraphStyle.m \
NSPrinter.m \
NSPrintInfo.m \
NSPrintOperation.m \
@ -120,6 +122,7 @@ libgnustep-gui_HEADER_FILES = \
AppKit/AppKit.h \
AppKit/NSActionCell.h \
AppKit/NSApplication.h \
AppKit/NSAttributedString.h \
AppKit/NSBitmapImageRep.h \
AppKit/NSBox.h \
AppKit/NSBrowser.h \
@ -155,6 +158,7 @@ AppKit/NSHelpPanel.h \
AppKit/NSImage.h \
AppKit/NSImageRep.h \
AppKit/NSImageView.h \
AppKit/NSLayoutManager.h \
AppKit/NSMatrix.h \
AppKit/NSMenu.h \
AppKit/NSMenuItem.h \
@ -162,6 +166,7 @@ AppKit/NSNibLoading.h \
AppKit/NSOpenPanel.h \
AppKit/NSPageLayout.h \
AppKit/NSPanel.h \
AppKit/NSParagraphStyle.h \
AppKit/NSPasteboard.h \
AppKit/NSPopUpButton.h \
AppKit/NSPrintInfo.h \
@ -180,10 +185,14 @@ AppKit/NSSpellChecker.h \
AppKit/NSSpellProtocol.h \
AppKit/NSSpellServer.h \
AppKit/NSSplitView.h \
AppKit/NSTextStorage.h \
AppKit/NSStringDrawing.h \
AppKit/NSText.h \
AppKit/NSTextAttachment.h \
AppKit/NSTextContainer.h \
AppKit/NSTextField.h \
AppKit/NSTextFieldCell.h \
AppKit/NSTextStorage.h \
AppKit/NSTextView.h \
AppKit/NSView.h \
AppKit/NSWindow.h \

View file

@ -0,0 +1,45 @@
/*
NSAttributedString.m
Category which adds measure capabilities to NSString.
Copyright (C) 1997 Free Software Foundation, Inc.
Author: Felipe A. Rodriguez <far@ix.netcom.com>
Date: Aug 1998
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <AppKit/NSAttributedString.h>
#include <AppKit/AppKit.h>
@implementation NSString(NSAttributedString)
- (NSSize)sizeWithAttributes:(NSDictionary *)attrs
{
NSFont *font;
// if font is not
if(!(font = [attrs objectForKey:NSFontAttributeName])) // specified, use
font = [NSFont userFontOfSize:12]; // the default
return NSMakeSize([font widthOfString:self], [font pointSize]);
}
@end

130
Source/NSParagraphStyle.m Normal file
View file

@ -0,0 +1,130 @@
/*
NSParagraphStyle.m
NSParagraphStyle and NSMutableParagraphStyle hold paragraph style
information NSTextTab holds information about a single tab stop
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Daniel Bðhringer <boehring@biomed.ruhr-uni-bochum.de>
Date: August 1998
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import <Foundation/Foundation.h>
#include <AppKit/NSParagraphStyle.h>
@implementation NSTextTab
- initWithType:(NSTextTabType)type location:(float)loc
{ self=[super init];
tabStopType=type; location=loc;
return self;
}
-(float) location {return location;}
-(NSTextTabType) tabStopType {return tabStopType;}
@end
@implementation NSParagraphStyle
+ (NSParagraphStyle *)defaultParagraphStyle
{
}
/* "Leading": distance between the bottom of one line fragment and top of next (applied between lines in the same container). Can't be negative. This value is included in the line fragment heights in layout manager. */
-(float)lineSpacing
{
}
/* Distance between the bottom of this paragraph and top of next. */
-(float) paragraphSpacing
{
}
-(NSTextAlignment) alignment
{
}
/* The following values are relative to the appropriate margin (depending on the paragraph direction) */
/* Distance from margin to front edge of paragraph */
-(float) headIndent
{
}
/* Distance from margin to back edge of paragraph; if negative or 0, from other margin */
-(float) tailIndent
{
}
/* Distance from margin to edge appropriate for text direction */
-(float) firstLineHeadIndent
{
}
/* Distance from margin to tab stops */
-(NSArray *) tabStops
{
}
/* Line height is the distance from bottom of descenders to top of ascenders; basically the line fragment height. Does not include lineSpacing (which is added after this computation). */
-(float) minimumLineHeight
{
}
/* 0 implies no maximum. */
-(float) maximumLineHeight
{
}
-(NSLineBreakMode) lineBreakMode
{
}
//@end
///@implementation NSParagraphStyle
- (void)setLineSpacing:(float)aFloat
{}
- (void)setParagraphSpacing:(float)aFloat
{}
- (void)setAlignment:(NSTextAlignment)alignment
{}
- (void)setFirstLineHeadIndent:(float)aFloat
{}
- (void)setHeadIndent:(float)aFloat
{}
- (void)setTailIndent:(float)aFloat
{}
- (void)setLineBreakMode:(NSLineBreakMode)mode
{}
- (void)setMinimumLineHeight:(float)aFloat
{}
- (void)setMaximumLineHeight:(float)aFloat
{}
- (void)addTabStop:(NSTextTab *)anObject
{}
- (void)removeTabStop:(NSTextTab *)anObject
{}
- (void)setTabStops:(NSArray *)array
{}
- (void)setParagraphStyle:(NSParagraphStyle *)obj
{}
@end

View file

@ -30,124 +30,318 @@
#include <AppKit/NSSpellChecker.h>
#include <AppKit/NSFontPanel.h>
#include <AppKit/NSControl.h>
#include <AppKit/NSLayoutManager.h>
#include <AppKit/NSTextStorage.h>
#define ASSIGN(variable, value) [value retain]; \
[variable release]; \
variable = value;
// classes needed are: NSRulerView NSTextContainer NSLayoutManager
@implementation NSTextView
- (void)insertText:(NSString *)insertString
/**************************** Initializing ****************************/
+(void) initialize
{ [super initialize];
if([self class] == [NSTextView class]) [self registerForServices];
}
//Registers send and return types for the Services facility. This method is invoked automatically; you should never need to invoke it directly.
+(void) registerForServices
{
// do we yet have services in gnustep?
}
// container may be nil
- initWithFrame:(NSRect)frameRect textContainer:(NSTextContainer *)container
{ if(container) [self setTextContainer: container];
else // set up a new container
{
}
self=[super initWithFrame:frameRect];
return self;
}
// This variant will create the text network (textStorage, layoutManager, and a container).
- initWithFrame:(NSRect)frameRect
{ return [self initWithFrame:frameRect textContainer:nil];
}
/***************** Get/Set the container and other stuff *****************/
-(NSTextContainer*) textContainer
{ return textContainer;
}
// The set method should not be called directly, but you might want to override it. Gets or sets the text container for this view. Setting the text container marks the view as needing display. The text container calls the set method from its setTextView: method.
-(void) setTextContainer:(NSTextContainer *)container
{ if(textContainer) [textContainer autorelease];
textContainer=[container retain];
}
// This method should be used instead of the primitive -setTextContainer: if you need to replace a view's text container with a new one leaving the rest of the web intact. This method deals with all the work of making sure the view doesn't get deallocated and removing the old container from the layoutManager and replacing it with the new one.
-(void) replaceTextContainer:(NSTextContainer *)newContainer
{ [self setTextContainer:newContainer];
// now do something to retain the web
}
// The textContianerInset determines the padding that the view provides around the container. The container's origin will be inset by this amount from the bounds point {0,0} and padding will be left to the right and below the container of the same amount. This inset affects the view sizing in response to new layout and is used by the rectangular text containers when they track the view's frame dimensions.
-(void)setTextContainerInset:(NSSize)inset
{
}
- (NSArray*)acceptableDragTypes
-(NSSize) textContainerInset {return textContainerInset;}
-(NSPoint) textContainerOrigin {return textContainerOrigin;}
// The container's origin in the view is determined from the current usage of the container, the container inset, and the view size. textContainerOrigin returns this point. invalidateTextContainerOrigin is sent automatically whenever something changes that causes the origin to possibly move. You usually do not need to call invalidate yourself.
-(void)invalidateTextContainerOrigin
{
NSMutableArray *ret = [NSMutableArray arrayWithObjects:NSStringPboardType,
NSColorPboardType, nil];
}
if([self isRichText])
[ret addObject:NSRTFPboardType];
if([self importsGraphics])
[ret addObject:NSRTFDPboardType];
-(NSLayoutManager*) layoutManager {return layoutManager;}
-(NSTextStorage*) textStorage {return textStorage;}
/************************* Key binding entry-point *************************/
// This method is the funnel point for text insertion after keys pass through the key binder.
-(void) insertText:(NSString*) insertString
{
}
/*************************** Sizing methods ***************************/
// Sets the frame size of the view to desiredSize constrained within min and max size.
- (void)setConstrainedFrameSize:(NSSize)desiredSize
{
}
/***************** New miscellaneous API above and beyond NSText *****************/
- (void)setAlignment:(NSTextAlignment)alignment range:(NSRange)range
{
}
-(void) pasteAsPlainText:sender
{
}
-(void) pasteAsRichText:sender
{
}
/*************************** New Font menu commands ***************************/
-(void) turnOffKerning:(id)sender
{
}
-(void) tightenKerning:(id)sender
{
}
-(void) loosenKerning:(id)sender
{
}
-(void) useStandardKerning:(id)sender
{
}
-(void) turnOffLigatures:(id)sender
{
}
-(void) useStandardLigatures:(id)sender
{
}
-(void) useAllLigatures:(id)sender
{
}
-(void) raiseBaseline:(id)sender
{
}
-(void) lowerBaseline:(id)sender
{}
/*************************** Ruler support ***************************/
-(void) rulerView:(NSRulerView *)ruler didMoveMarker:(NSRulerMarker *)marker
{
}
-(void) rulerView:(NSRulerView *)ruler didRemoveMarker:(NSRulerMarker *)marker
{
}
-(void) rulerView:(NSRulerView *)ruler didAddMarker:(NSRulerMarker *)marker
{
}
-(BOOL) rulerView:(NSRulerView *)ruler shouldMoveMarker:(NSRulerMarker *)marker
{
}
-(BOOL) rulerView:(NSRulerView *)ruler shouldAddMarker:(NSRulerMarker *)marker
{
}
-(float) rulerView:(NSRulerView *)ruler willMoveMarker:(NSRulerMarker *)marker toLocation:(float)location
{
}
-(BOOL) rulerView:(NSRulerView *)ruler shouldRemoveMarker:(NSRulerMarker *)marker
{
}
-(float) rulerView:(NSRulerView *)ruler willAddMarker:(NSRulerMarker *)marker atLocation:(float)location
{
}
-(void) rulerView:(NSRulerView *)ruler handleMouseDown:(NSEvent *)event
{
}
/*************************** Fine display control ***************************/
-(void) setNeedsDisplayInRect:(NSRect)rect avoidAdditionalLayout:(BOOL)fla
{
}
-(BOOL)shouldDrawInsertionPoint
{
}
-(void) drawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)flag
{
}
/*************************** Especially for subclassers ***************************/
-(void) updateRuler
{
}
-(void) updateFontPanel
{
}
-(NSArray*)acceptableDragTypes
{ NSMutableArray *ret=[NSMutableArray arrayWithObject:NSStringPboardType];
if([self isRichText]) [ret addObject:NSRTFPboardType];
if([self importsGraphics]) [ret addObject:NSRTFDPboardType];
return ret;
}
- (void)updateDragTypeRegistration
{
[self registerForDraggedTypes:[self acceptableDragTypes]];
}
- (NSRange) selectionRangeForProposedRange:(NSRange)proposedCharRange
granularity:(NSSelectionGranularity)granularity
- (NSRange)selectionRangeForProposedRange:(NSRange)proposedCharRange granularity:(NSSelectionGranularity)granularity
{}
@end
@implementation NSTextView (NSSharing)
// The methods in this category deal with settings that need to be shared by all the NSTextViews of a single NSLayoutManager. Many of these methods are overrides of NSText or NSResponder methods.
/*************************** Selected/Marked range ***************************/
-(void) setSelectedRange:(NSRange)charRange affinity:(NSSelectionAffinity)affinity stillSelecting:(BOOL)stillSelectingFlag
{
switch(granularity)
{
case NSSelectByCharacter:
return proposedCharRange;
case NSSelectByWord:
{ //selectionWordGranularitySet
}
break;
case NSSelectByParagraph:
{ //selectionParagraphGranularitySet
}
break;
}
return proposedCharRange;
}
-(NSSelectionAffinity) selectionAffinity {return selectionAffinity;}
-(NSSelectionGranularity) selectionGranularity {return selectionGranularity;}
-(void) setSelectionGranularity:(NSSelectionGranularity)granularity
{ selectionGranularity= granularity;
}
//
// Managing the Selection
//
- (void)setSelectedRange:(NSRange)range
-(void) setSelectedTextAttributes:(NSDictionary *)attributeDictionary
{
}
-(NSDictionary*) selectedTextAttributes
{
selected_range = range;
if([self usesFontPanel]) // update fontPanel
{
BOOL isMultiple=NO;
NSFont *currentFont;
if([self isRichText])
{
// if(are multiple fonts in selection) isMultiple=YES;
// else currentFont=[rtfContent attribute:NSFontAttributeName
// atIndex:range.location longestEffectiveRange:NULL
// inRange:range]
}
// else
// currentFont = [[self defaultTypingAttributes]
// objectForKey:NSFontAttributeName];
[[NSFontPanel sharedFontPanel] setPanelFont:currentFont
isMultiple:isMultiple];
}
if(range.length) // display
{
// disable caret timed entry
}
else
{
// enable caret timed entry
}
[self scrollRangeToVisible:range];
}
- (void)setTypingAttributes:(NSDictionary*) dict
-(void) setInsertionPointColor:(NSColor *)color
{ if(insertionPointColor) [insertionPointColor autorelease];
insertionPointColor=[color retain];
}
- (NSColor *)insertionPointColor {return insertionPointColor;}
-(void) updateInsertionPointStateAndRestartTimer:(BOOL)restartFlag
{
ASSIGN(typingAttributes, dict);
}
- (NSDictionary*)typingAttributes
-(NSRange)markedRange
{
if(typingAttributes)
return typingAttributes;
else
// return [self defaultTypingAttributes];
return nil;
}
- (int) spellCheckerDocumentTag
-(void) setMarkedTextAttributes:(NSDictionary*)attributeDictionary
{
}
-(NSDictionary*) markedTextAttributes
{
if(!spellCheckerDocumentTag)
spellCheckerDocumentTag = [NSSpellChecker uniqueSpellDocumentTag];
return spellCheckerDocumentTag;
}
//
// NSIgnoreMisspelledWords protocol
//
- (void)ignoreSpelling:(id)sender
/*************************** Other NSTextView methods ***************************/
-(void) setRulerVisible:(BOOL)flag
{
}
-(BOOL) usesRuler
{
}
-(void) setUsesRuler:(BOOL)flag
{
}
-(int) spellCheckerDocumentTag
{
}
-(NSDictionary*) typingAttributes
{
}
-(void) setTypingAttributes:(NSDictionary *)attrs
{
}
//Initiates a series of delegate messages (and general notifications) to determine whether modifications can be made to the receiver's text. If characters in the text string are being changed, replacementString contains the characters that will replace the characters in affectedCharRange. If only text attributes are being changed, replacementString is nil. This method checks with the delegate as needed using textShouldBeginEditing: and textView:shouldChangeTextInRange:replacementString:, returning YES to allow the change, and NO to prohibit it.
//This method must be invoked at the start of any sequence of user-initiated editing changes. If your subclass of NSTextView implements new methods that modify the text, make sure to invoke this method to determine whether the change should be made. If the change is allowed, complete the change by invoking the didChangeText method. See ªNotifying About Changes to the Textº in the class description for more information. If you can't determine the affected range or replacement string before beginning changes, pass (NSNotFound, 0) and nil for these values.
-(BOOL) shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString
{
}
-(void)didChangeText
{}
-(NSRange)rangeForUserTextChange
{
}
-(NSRange) rangeForUserCharacterAttributeChange
{
}
-(NSRange) rangeForUserParagraphAttributeChange
{
}
/*************************** NSResponder methods ***************************/
-(BOOL) resignFirstResponder
{ return YES;
}
-(BOOL) becomeFirstResponder
{ return YES;
}
/*************************** Smart copy/paste/delete support ***************************/
-(BOOL)smartInsertDeleteEnabled {return smartInsertDeleteEnabled;}
-(void) setSmartInsertDeleteEnabled:(BOOL)flag
{
}
-(NSRange) smartDeleteRangeForProposedRange:(NSRange)proposedCharRange
{
}
-(void) smartInsertForString:(NSString *)pasteString replacingRange:(NSRange)charRangeToReplace beforeString:(NSString **)beforeString afterString:(NSString **)afterString
{
[[NSSpellChecker sharedSpellChecker]
ignoreWord:[[sender selectedCell] stringValue]
inSpellDocumentWithTag:[self spellCheckerDocumentTag]];
}
@end