diff --git a/ChangeLog b/ChangeLog index 25b62ce77..f7ab3d4f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +1999-07-15 Michael Hanni + + * Source/NSLayoutManager.m: new file from + jagapen@whitewater.chem.wisc.edu + * Source/NSTextView.m: initWithFrame: now creates a proper NSText + network. + Thu Jul 15 18:00:00 1999 Richard Frith-Macdonald * Source/NSView.m: Make sure cursor and tracking rects are converted diff --git a/Headers/gnustep/gui/NSLayoutManager.h b/Headers/gnustep/gui/NSLayoutManager.h index 680544dd1..5824803c7 100644 --- a/Headers/gnustep/gui/NSLayoutManager.h +++ b/Headers/gnustep/gui/NSLayoutManager.h @@ -37,10 +37,11 @@ #import #import -@class NSTextStorage; +#import +#import + @class NSTypesetter; @class NSGlyphGenerator; -@class NSTextContainer; @class NSTextView; @class NSWindow; @class NSColor; @@ -77,69 +78,77 @@ typedef enum { } NSGlyphInscription; @interface NSLayoutManager : NSObject -{ NSTextStorage *textStorage; - NSGlyphGenerator *glyphGenerator; - NSTypesetter *typesetter; +{ + NSTextStorage *_textStorage; + NSGlyphGenerator *_glyphGenerator; + NSTypesetter *_typesetter; - NSMutableArray *textContainers; - NSStorage *containerUsedRects; + NSMutableArray *_textContainers; + NSStorage *_containerUsedRects; - NSStorage *glyphs; - NSRunStorage *containerRuns; - NSRunStorage *fragmentRuns; - NSRunStorage *glyphLocations; - NSRunStorage *glyphRotationRuns; + NSStorage *_glyphs; + NSRunStorage *_containerRuns; + NSRunStorage *_fragmentRuns; + NSRunStorage *_glyphLocations; + NSRunStorage *_glyphRotationRuns; - NSRect extraLineFragmentRect; - NSRect extraLineFragmentUsedRect; - NSTextContainer *extraLineFragmentContainer; + NSRect _extraLineFragmentRect; + NSRect _extraLineFragmentUsedRect; + NSTextContainer *_extraLineFragmentContainer; - NSSortedArray *glyphHoles; - NSSortedArray *layoutHoles; + NSSortedArray *_glyphHoles; + NSSortedArray *_layoutHoles; - id delegate; + id _delegate; // Enable/disable stacks - unsigned short textViewResizeDisableStack; - unsigned short displayInvalidationDisableStack; - NSRange deferredDisplayCharRange; + 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; + NSTextView *_firstTextView; // Cache for rectangle arrays (Cost: 8 bytes + malloced 16 * bytes) - NSRect *cachedRectArray; - unsigned cachedRectArrayCapacity; + NSRect *_cachedRectArray; + unsigned _cachedRectArrayCapacity; // Cache for glyph strings (used when drawing) (Cost: 8 bytes + malloced glyph buffer size) - char *glyphBuffer; - unsigned glyphBufferSize; + char *_glyphBuffer; + unsigned _glyphBufferSize; // Cache for faster glyph location lookup (Cost: 20 bytes) - NSRange cachedLocationNominalGlyphRange; - unsigned cachedLocationGlyphIndex; - NSPoint cachedLocation; + NSRange _cachedLocationNominalGlyphRange; + unsigned _cachedLocationGlyphIndex; + NSPoint _cachedLocation; // Cache for faster glyph location lookup (Cost: 12 bytes) - NSRange cachedFontCharRange; - NSFont *cachedFont; + NSRange _cachedFontCharRange; + NSFont *_cachedFont; // Cache for first unlaid glypha and character (Cost: 8 bytes) - unsigned firstUnlaidGlyphIndex; - unsigned firstUnlaidCharIndex; + 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; + NSBox *_rulerAccView; + NSMatrix *_rulerAccViewAlignmentButtons; + NSTextField *_rulerAccViewLeadingField; + NSTabWell *_rulerAccViewLeftTabWell; + NSTabWell *_rulerAccViewRightTabWell; + NSTabWell *_rulerAccViewCenterTabWell; + NSTabWell *_rulerAccViewDecimalTabWell; + NSMatrix *_rulerAccViewIncrementLineHeightButtons; + NSMatrix *_rulerAccViewFixedLineHeightButtons; - NSRange newlyFilledGlyphRange; + NSRange _newlyFilledGlyphRange; + +// Michael additions. + BOOL _backgroundLayout; + BOOL _showsInvisibleChars; + BOOL _showsControlChars; + float _hyphenationFactor; + BOOL _usesScreenFonts; } /**************************** Initialization ****************************/ diff --git a/Headers/gnustep/gui/NSTextContainer.h b/Headers/gnustep/gui/NSTextContainer.h index 7971e76fd..fb40f08f7 100644 --- a/Headers/gnustep/gui/NSTextContainer.h +++ b/Headers/gnustep/gui/NSTextContainer.h @@ -34,6 +34,7 @@ #endif #import +#import typedef enum { NSLineSweepLeft, diff --git a/Images/common_Folder.tiff b/Images/common_Folder.tiff index 91d6ce82d..44cf8134f 100644 Binary files a/Images/common_Folder.tiff and b/Images/common_Folder.tiff differ diff --git a/Source/GNUmakefile b/Source/GNUmakefile index 005b1154a..740e108fa 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -77,6 +77,7 @@ NSImageCell.m \ NSImageRep.m \ NSImageView.m \ NSInterfaceStyle.m \ +NSLayoutManager.m \ NSMatrix.m \ NSMenu.m \ NSMenuView.m \ diff --git a/Source/NSLayoutManager.m b/Source/NSLayoutManager.m new file mode 100644 index 000000000..b6cf93a02 --- /dev/null +++ b/Source/NSLayoutManager.m @@ -0,0 +1,519 @@ +/* + NSLayoutManager.m + + The text layout manager class + + Copyright (C) 1999 Free Software Foundation, Inc. + + Author: Jonathan Gapen + Date: July 1999 + + 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 + +@implementation NSLayoutManager + +- (id) init +{ + [super init]; + _backgroundLayout = YES; + _delegate = nil; + _textContainers = [[NSMutableArray alloc] initWithCapacity: 2]; + return self; +} + +// +// Setting the text storage +// +- (void)setTextStorage: (NSTextStorage *)aTextStorage +{ + ASSIGN(_textStorage, aTextStorage); +} + +- (NSTextStorage *)textStorage +{ + return _textStorage; +} + +- (void)replaceTextStorage: (NSTextStorage *)newTextStorage +{ + NSArray *layoutManagers = [_textStorage layoutManagers]; + NSEnumerator *enumerator = [layoutManagers objectEnumerator]; + NSLayoutManager *object; + + // Remove layout managers from old NSTextStorage object and add them to the + // new one. NSTextStorage's addLayoutManager invokes NSLayoutManager's + // setTextStorage method automatically, and that includes self. + + while( (object = (NSLayoutManager *)[enumerator nextObject]) ) + { + [_textStorage removeLayoutManager: object]; + [newTextStorage addLayoutManager: object]; + } +} + +// +// Setting text containers +// +- (NSArray *)textContainers +{ + return _textContainers; +} + +- (void)addTextContainer: (NSTextContainer *)obj +{ + if( [_textContainers indexOfObjectIdenticalTo: obj] == NSNotFound ) + { + [_textContainers addObject: obj]; + [obj setLayoutManager: self]; + } +} + +- (void)insertTextContainer: (NSTextContainer *)aTextContainer + atIndex: (unsigned)index +{ + [_textContainers insertObject: aTextContainer atIndex: index]; +} + +- (void)removeTextContainerAtIndex: (unsigned)index +{ + [_textContainers removeObjectAtIndex: index]; +} + +// +// Invalidating glyphs and layout +// +- (void)invalidateGlyphsForCharacterRange: (NSRange)aRange + changeInLength: (int)lengthChange + actualCharacterRange: (NSRange *)actualRange +{ +} + +- (void)invalidateLayoutForCharacterRange: (NSRange)aRange + isSoft: (BOOL)flag + actualCharacterRange: (NSRange *)actualRange +{ +} + +- (void)invalidateDisplayForCharacterRange: (NSRange)aRange +{ +} + +- (void)invalidateDisplayForGlyphRange: (NSRange)aRange +{ +} + +- (void)textContainerChangedGeometry: (NSTextContainer *)aContainer +{ +} + +- (void)textContainerChangedTextView: (NSTextContainer *)aContainer +{ +} + +- (void)textStorage: (NSTextStorage *)aTextStorage + edited: (unsigned)mask + range: (NSRange)range + changeInLength: (int)lengthChange + invalidatedRange: (NSRange)invalidatedRange +{ +} + +// +// Turning on/off background layout +// + +- (void)setBackgroundLayoutEnabled: (BOOL)flag +{ + _backgroundLayout = flag; +} + +- (BOOL)backgroundLayoutEnabled +{ + return _backgroundLayout; +} + +// +// Accessing glyphs +// +- (void)insertGlyph: (NSGlyph)aGlyph + atGlyphIndex: (unsigned)glyphIndex + characterIndex: (unsigned)charIndex +{ +} + +- (NSGlyph)glyphAtIndex: (unsigned)index +{ + return NSNullGlyph; +} + +- (NSGlyph)glyphAtIndex: (unsigned)index + isValidIndex: (BOOL *)flag +{ + *flag = NO; + return NSNullGlyph; +} + +- (void)replaceGlyphAtIndex: (unsigned)index + withGlyph: (NSGlyph)newGlyph +{ +} + +- (unsigned)getGlyphs: (NSGlyph *)glyphArray + range: (NSRange)glyphRange +{ + return (unsigned)0; +} + +- (void)deleteGlyphsInRange: (NSRange)aRange +{ +} + +- (unsigned)numberOfGlyphs +{ + return 0; +} + +// +// Mapping characters to glyphs +// +- (void)setCharacterIndex: (unsigned)charIndex + forGlyphAtIndex: (unsigned)glyphIndex +{ +} + +- (unsigned)characterIndexForGlyphAtIndex: (unsigned)glyphIndex +{ + return 0; +} + +- (NSRange)characterRangeForGlyphRange: (NSRange)glyphRange + actualGlyphRange: (NSRange *)actualGlyphRange +{ + return NSMakeRange(0, 0); +} + +- (NSRange)glyphRangeForCharacterRange: (NSRange)charRange + actualCharacterRange: (NSRange *)actualCharRange +{ + return NSMakeRange(0, 0); +} + +// +// Setting glyph attributes +// +- (void)setIntAttribute: (int)attribute + value: (int)anInt + forGlyphAtIndex: (unsigned)glyphIndex +{ +} + +- (int)intAttribute: (int)attribute + forGlyphAtIndex: (unsigned)glyphIndex +{ + return 0; +} + +// +// Handling layout for text containers +// +- (void)setTextContainer: (NSTextContainer *)aTextContainer + forGlyphRange: (NSRange)glyphRange +{ +} + +- (NSRange)glyphRangeForTextContainer: (NSTextContainer *)aTextContainer +{ + return NSMakeRange(0, 0); +} + +- (NSTextContainer *)textContainerForGlyphAtIndex: (unsigned)glyphIndex + effectiveRange: (NSRange *)effectiveRange +{ + return nil; +} + +- (NSRect)usedRectForTextContainer: (NSTextContainer *)aTextContainer +{ + return NSZeroRect; +} + +// +// Handling line fragment rectangles +// +- (void)setLineFragmentRect: (NSRect)fragmentRect + forGlyphRange: (NSRange)glyphRange + usedRect: (NSRect)usedRect +{ +} + +- (NSRect)lineFragmentRectForGlyphAtIndex: (unsigned)glyphIndex + effectiveRange: (NSRange *)lineFragmentRange +{ + return NSZeroRect; +} + +- (NSRect)lineFragmentUsedRectForGlyphAtIndex: (unsigned)glyphIndex + effectiveRange: (NSRange *)lineFragmentRange +{ + return NSZeroRect; +} + +- (void)setExtraLineFragmentRect: (NSRect)aRect + usedRect: (NSRect)usedRect + textContainer: (NSTextContainer *)aTextContainer +{ +} + +- (NSRect)extraLineFragmentRect +{ + return NSZeroRect; +} + +- (NSRect)extraLineFragmentUsedRect +{ + return NSZeroRect; +} + +- (NSTextContainer *)extraLineFragmentTextContainer +{ + return nil; +} + +- (void)setDrawsOutsideLineFragment: (BOOL)flag + forGlyphAtIndex: (unsigned)glyphIndex +{ +} + +- (BOOL)drawsOutsideLineFragmentForGlyphAtIndex: (unsigned)glyphIndex +{ + return NO; +} + +// +// Layout of glyphs +// +- (void)setLocation: (NSPoint)aPoint + forStartOfGlyphRange: (NSRange)glyphRange +{ +} + +- (NSPoint)locationForGlyphAtIndex: (unsigned)glyphIndex +{ + return NSZeroPoint; +} + +- (NSRange)rangeOfNominallySpacedGlyphsContainingIndex: (unsigned)glyphIndex +{ + return NSMakeRange(0, 0); +} + +- (NSRect *)rectArrayForCharacterRange: (NSRange)charRange + withinSelectedCharacterRange: (NSRange)selChareRange + inTextContainer: (NSTextContainer *)aTextContainer + rectCount: (unsigned *)rectCount +{ + return NULL; +} + +- (NSRect *)rectArrayForGlyphRange: (NSRange)glyphRange + withinSelectedGlyphRange: (NSRange)selectedGlyphRange + inTextContainer: (NSTextContainer *)aTextContainer + rectCount: (unsigned *)rectCount +{ + return NULL; +} + +- (NSRect)boundingRectForGlyphRange: (NSRange)glyphRange + inTextContainer: (NSTextContainer *)aTextContainer +{ + return NSZeroRect; +} + +- (NSRange)glyphRangeForBoundingRect: (NSRect)aRect + inTextContainer: (NSTextContainer *)aTextContainer +{ + return NSMakeRange(0, 0); +} + +- (NSRange)glyphRangeForBoundingRectWithoutAdditionalLayout: (NSRect)bounds + inTextContainer: (NSTextContainer *)aTextContainer +{ + return NSMakeRange(0, 0); +} + +- (unsigned)glyphIndexForPoint: (NSPoint)aPoint + inTextContainer: (NSTextContainer *)aTextContainer +fractionOfDistanceThroughGlyph: (float *)partialFraction +{ + return 0; +} + +// +// Display of special glyphs +// +- (void)setNotShownAttribute: (BOOL)flag + forGlyphAtIndex: (unsigned)glyphIndex +{ +} + +- (BOOL)notShownAttributeForGlyphAtIndex: (unsigned)glyphIndex +{ + return YES; +} + +- (void)setShowsInvisibleCharacters: (BOOL)flag +{ + _showsInvisibleChars = flag; +} + +- (BOOL)showsInvisibleCharacters +{ + return _showsInvisibleChars; +} + +- (void)setShowsControlCharacters: (BOOL)flag +{ + _showsControlChars = flag; +} + +- (BOOL)showsControlCharacters +{ + return _showsControlChars; +} + +// +// Controlling hyphenation +// +- (void)setHyphenationFactor: (float)factor +{ + _hyphenationFactor = factor; +} + +- (float)hyphenationFactor +{ + return _hyphenationFactor; +} + +// +// Finding unlaid characters/glyphs +// +- (void)getFirstUnlaidCharacterIndex: (unsigned *)charIndex + glyphIndex: (unsigned *)glyphIndex +{ +} + +// +// Using screen fonts +// +- (void)setUsesScreenFonts: (BOOL)flag +{ + _usesScreenFonts = flag; +} + +- (BOOL)usesScreenFonts +{ + return _usesScreenFonts; +} + +- (NSFont *)substituteFontForFont: (NSFont *)originalFont +{ + return originalFont; +} + +// +// Handling rulers +// +- (NSView *)rulerAccessoryViewForTextView: (NSTextView *)aTextView + paragraphStyle: (NSParagraphStyle *)paragraphStyle + ruler: (NSRulerView *)aRulerView + enabled: (BOOL)flag +{ + return NULL; +} + +- (NSArray *)rulerMarkersForTextView: (NSTextView *)aTextView + paragraphStyle: (NSParagraphStyle *)paragraphStyle + ruler: (NSRulerView *)aRulerView +{ + return NULL; +} + +// +// Managing the responder chain +// +- (BOOL)layoutManagerOwnsFirstResponderInWindow: (NSWindow *)aWindow +{ + return NO; +} + +- (NSTextView *)firstTextView +{ + return NULL; +} + +- (NSTextView *)textViewForBeginningOfSelection +{ + return NULL; +} + +// +// Drawing +// +- (void)drawBackgroundForGlyphRange: (NSRange)glyphRange + atPoint: (NSPoint)containerOrigin +{ +} + +- (void)drawGlyphsForGlyphRange: (NSRange)glyphRange + atPoint: (NSPoint)containerOrigin +{ +} + +- (void)drawUnderlineForGlyphRange: (NSRange)glyphRange + underlineType: (int)underlineType + baselineOffset: (float)baselineOffset + lineFragmentRect: (NSRect)lineRect + lineFragmentGlyphRange: (NSRange)lineGlyphRange + containerOrigin: (NSPoint)containerOrigin +{ +} + +- (void)underlineGlyphRange: (NSRange)glyphRange + underlineType: (int)underlineType + lineFragmentRect: (NSRect)lineRect + lineFragmentGlyphRange: (NSRange)lineGlyphRange + containerOrigin: (NSPoint)containerOrigin +{ +} + +// +// Setting the delegate +// +- (void)setDelegate: (id)aDelegate +{ + _delegate = aDelegate; +} + +- (id)delegate +{ + return _delegate; +} + +@end /* NSLayoutManager */ diff --git a/Source/NSPopUpButton.m b/Source/NSPopUpButton.m index df78d8e1b..5d37c7494 100644 --- a/Source/NSPopUpButton.m +++ b/Source/NSPopUpButton.m @@ -582,6 +582,9 @@ static NSFont* menuFont = nil; { id aCell; + if ([[list_items itemArray] count] == 0) + return; + if (!pulls_down) aCell = [[list_items itemArray] objectAtIndex:selected_item]; else diff --git a/Source/NSTextView.m b/Source/NSTextView.m index edc93493d..f3c955dbe 100644 --- a/Source/NSTextView.m +++ b/Source/NSTextView.m @@ -43,26 +43,22 @@ // This variant will create the text network (textStorage, layoutManager, and a container). - initWithFrame:(NSRect)frameRect -{ return [self initWithFrame:frameRect textContainer:nil]; -} - -#ifdef 0 -- initWithFrame:(NSRect)frameRect { + textStorage = [[NSTextStorage alloc] init]; - textStorage = [NSTextStorage new]; -// layoutManager = [NSLayoutManager new]; -// [textStorage addLayoutManager:layoutManager]; -// [layoutManager release]; + if (![textStorage delegate]) + NSLog(@"No delegate set."); - textContainer = [[NSTextContainer alloc] - initWithContainerSize:frameRect]; -// [layoutManager addTextContainer:textContainer]; - [textContainer release]; + layoutManager = [[NSLayoutManager alloc] init]; + [textStorage addLayoutManager:layoutManager]; + [layoutManager release]; + + textContainer = [[NSTextContainer alloc] initWithContainerSize:frameRect.size]; + [layoutManager addTextContainer:textContainer]; + [textContainer release]; return [self initWithFrame:frameRect textContainer:textContainer]; } -#endif /***************** Get/Set the container and other stuff *****************/