Various text/font fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6291 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2000-03-16 14:16:46 +00:00
parent b5be67ab7d
commit be2b1ba87b
6 changed files with 3091 additions and 3159 deletions

View file

@ -1,3 +1,9 @@
Thu Mar 16 13:15:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSText.m: Fixes by Fred Kiefer for rich text display.
* Source/NSTextView.m: ditto
* Source/NSFontManager.m: bugfixes - check for nil fonts.
Wed Mar 15 02:41:04 2000 Nicola Pero <n.pero@mi.flashnet.it> Wed Mar 15 02:41:04 2000 Nicola Pero <n.pero@mi.flashnet.it>
* Source/GSUtil.m: Removed file; it was duplicating * Source/GSUtil.m: Removed file; it was duplicating

View file

@ -1,33 +1,33 @@
/* /*
NSText.h NSText.h
The text object The text object
Copyright (C) 1996 Free Software Foundation, Inc. Copyright (C) 1996 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com> Author: Scott Christley <scottc@net-community.com>
Date: 1996 Date: 1996
Author: Felipe A. Rodriguez <far@ix.netcom.com> Author: Felipe A. Rodriguez <far@ix.netcom.com>
Date: July 1998 Date: July 1998
Author: Daniel Bðhringer <boehring@biomed.ruhr-uni-bochum.de> Author: Daniel Bðhringer <boehring@biomed.ruhr-uni-bochum.de>
Date: August 1998 Date: August 1998
This file is part of the GNUstep GUI Library. This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version. version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details. Library General Public License for more details.
You should have received a copy of the GNU Library General Public You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB. License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation, If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#ifndef _GNUstep_H_NSText #ifndef _GNUstep_H_NSText
@ -44,285 +44,288 @@
@class NSFont; @class NSFont;
typedef enum _NSTextAlignment { typedef enum _NSTextAlignment {
NSLeftTextAlignment = 0, NSLeftTextAlignment = 0,
NSRightTextAlignment, NSRightTextAlignment,
NSCenterTextAlignment, NSCenterTextAlignment,
NSJustifiedTextAlignment, NSJustifiedTextAlignment,
NSNaturalTextAlignment NSNaturalTextAlignment
} NSTextAlignment; } NSTextAlignment;
enum { enum {
NSIllegalTextMovement = 0, NSIllegalTextMovement = 0,
NSReturnTextMovement = 0x10, NSReturnTextMovement = 0x10,
NSTabTextMovement = 0x11, NSTabTextMovement = 0x11,
NSBacktabTextMovement = 0x12, NSBacktabTextMovement = 0x12,
NSLeftTextMovement = 0x13, NSLeftTextMovement = 0x13,
NSRightTextMovement = 0x14, NSRightTextMovement = 0x14,
NSUpTextMovement = 0x15, NSUpTextMovement = 0x15,
NSDownTextMovement = 0x16 NSDownTextMovement = 0x16
}; };
enum { enum {
NSParagraphSeparatorCharacter = 0x2029, NSParagraphSeparatorCharacter = 0x2029,
NSLineSeparatorCharacter = 0x2028, NSLineSeparatorCharacter = 0x2028,
NSTabCharacter = 0x0009, NSTabCharacter = 0x0009,
NSFormFeedCharacter = 0x000c, NSFormFeedCharacter = 0x000c,
NSNewlineCharacter = 0x000a, NSNewlineCharacter = 0x000a,
NSCarriageReturnCharacter = 0x000d, NSCarriageReturnCharacter = 0x000d,
NSEnterCharacter = 0x0003, NSEnterCharacter = 0x0003,
NSBackspaceCharacter = 0x0008, NSBackspaceCharacter = 0x0008,
NSBackTabCharacter = 0x0019, NSBackTabCharacter = 0x0019,
NSDeleteCharacter = 0x007f, NSDeleteCharacter = 0x007f,
}; };
#include <AppKit/NSStringDrawing.h> #include <AppKit/NSStringDrawing.h>
// these definitions should migrate to NSTextView when implemented // these definitions should migrate to NSTextView when implemented
typedef enum _NSSelectionGranularity { typedef enum _NSSelectionGranularity {
NSSelectByCharacter = 0, NSSelectByCharacter = 0,
NSSelectByWord = 1, NSSelectByWord = 1,
NSSelectByParagraph = 2, NSSelectByParagraph = 2,
} NSSelectionGranularity; } NSSelectionGranularity;
#if GNUSTEP #ifndef NO_GNUSTEP
typedef enum _NSSelectionAffinity { typedef enum _NSSelectionAffinity {
NSSelectionAffinityUpstream = 0, NSSelectionAffinityUpstream = 0,
NSSelectionAffinityDownstream = 1, NSSelectionAffinityDownstream = 1,
} NSSelectionAffinity; } NSSelectionAffinity;
#endif #endif
@interface NSText : NSView <NSChangeSpelling,NSIgnoreMisspelledWords,NSCoding> @interface NSText : NSView <NSChangeSpelling,NSIgnoreMisspelledWords,NSCoding>
{ // Attributes {
id delegate; // Attributes
unsigned int alignment; //NSTextAlignment id _delegate;
BOOL is_editable; struct GSTextFlagsType {
BOOL is_rich_text; unsigned is_editable: 1;
BOOL is_selectable; unsigned is_rich_text: 1;
BOOL imports_graphics; unsigned is_selectable: 1;
BOOL uses_font_panel; unsigned imports_graphics: 1;
BOOL is_horizontally_resizable; unsigned uses_font_panel: 1;
BOOL is_vertically_resizable; unsigned is_horizontally_resizable: 1;
BOOL is_ruler_visible; unsigned is_vertically_resizable: 1;
BOOL is_field_editor; unsigned is_ruler_visible: 1;
BOOL draws_background; unsigned is_field_editor: 1;
NSColor *background_color; unsigned draws_background: 1;
NSColor *text_color; } _tf;
NSFont *default_font; NSTextAlignment _alignment;
NSRange selected_range; NSColor *_background_color;
NSColor *_text_color;
NSFont *_default_font;
NSRange _selected_range;
NSSize _minSize;
NSSize _maxSize;
NSMutableDictionary *_typingAttributes;
// content
NSMutableAttributedString *_textStorage;
int _spellCheckerDocumentTag;
// column-stable cursor up/down
NSPoint _currentCursor;
// added by Daniel Bðhringer // contains private _GNULineLayoutInfo objects
id _layoutManager;
NSSize minSize,maxSize;
NSMutableDictionary *typingAttributes;
// content
NSMutableString *plainContent;
NSMutableAttributedString *rtfContent;
// internal stuff
// contains private _GNULineLayoutInfo objects
NSMutableArray *lineLayoutInformation;
int spellCheckerDocumentTag;
NSCharacterSet *selectionWordGranularitySet;
NSCharacterSet *selectionParagraphGranularitySet;
BOOL displayDisabled;
float currentCursorX; // column-stable cursor up/down
float currentCursorY; // column-stable cursor up/down
} }
// /*
// Getting and Setting Contents (low level: no selection handling, * Getting and Setting Contents
// relayout or display) */
// - (void) replaceCharactersInRange: (NSRange)aRange
- (void)replaceCharactersInRange:(NSRange)aRange withRTF:(NSData *)rtfData; withRTF: (NSData*)rtfData;
- (void)replaceCharactersInRange:(NSRange)aRange withRTFD:(NSData *)rtfdData; - (void) replaceCharactersInRange: (NSRange)aRange
- (void)replaceCharactersInRange:(NSRange)aRange withString:(NSString *)aString; withRTFD: (NSData*)rtfdData;
-(void) setString:(NSString *)string; - (void) replaceCharactersInRange: (NSRange)aRange
-(NSString*) string; withString: (NSString*)aString;
- (void) setString: (NSString*)string;
- (NSString*) string;
// old fashioned // old fashioned
-(void) replaceRange:(NSRange)range withString:(NSString*) aString; - (void) replaceRange: (NSRange)range withString: (NSString*)aString;
-(void) replaceRange:(NSRange)range withRTF:(NSData *)rtfData; - (void) replaceRange: (NSRange)range withRTF: (NSData*)rtfData;
-(void) replaceRange:(NSRange)range withRTFD:(NSData *)rtfdData; - (void) replaceRange: (NSRange)range withRTFD: (NSData*)rtfdData;
-(void) setText:(NSString *)string; - (void) setText: (NSString*)string;
-(void) setText:(NSString*) aString - (void) setText: (NSString*)aString
range:(NSRange) aRange; range: (NSRange)aRange;
-(NSString*) text; - (NSString*) text;
// /*
// Graphic attributes * Graphic attributes
// */
- (NSColor *) backgroundColor; - (NSColor*) backgroundColor;
- (BOOL) drawsBackground; - (BOOL) drawsBackground;
- (void) setBackgroundColor:(NSColor *)color; - (void) setBackgroundColor: (NSColor*)color;
- (void) setDrawsBackground:(BOOL)flag; - (void) setDrawsBackground: (BOOL)flag;
// /*
// Managing Global Characteristics * Managing Global Characteristics
// */
- (BOOL)importsGraphics; - (BOOL) importsGraphics;
- (BOOL)isEditable; - (BOOL) isEditable;
- (BOOL)isFieldEditor; - (BOOL) isFieldEditor;
- (BOOL)isRichText; - (BOOL) isRichText;
- (BOOL)isSelectable; - (BOOL) isSelectable;
- (void)setEditable:(BOOL)flag; - (void) setEditable: (BOOL)flag;
- (void)setFieldEditor:(BOOL)flag; - (void) setFieldEditor: (BOOL)flag;
- (void)setImportsGraphics:(BOOL)flag; - (void) setImportsGraphics: (BOOL)flag;
- (void)setRichText:(BOOL)flag; - (void) setRichText: (BOOL)flag;
- (void)setSelectable:(BOOL)flag; - (void) setSelectable: (BOOL)flag;
// /*
// Using the font panel * Using the font panel
// */
- (void) setUsesFontPanel: (BOOL) flag; - (void) setUsesFontPanel: (BOOL)flag;
- (BOOL) usesFontPanel; - (BOOL) usesFontPanel;
// /*
// Managing the Ruler * Managing the Ruler
// */
- (BOOL)isRulerVisible; - (BOOL) isRulerVisible;
- (void)toggleRuler:(id)sender; - (void) toggleRuler: (id)sender;
// /*
// Managing the Selection * Managing the Selection
// */
- (NSRange)selectedRange; - (NSRange) selectedRange;
- (void)setSelectedRange:(NSRange)range; - (void) setSelectedRange: (NSRange)range;
// /*
// Responding to Editing Commands * Responding to Editing Commands
// */
- (void)copy:(id)sender; - (void) copy: (id)sender;
- (void)copyFont:(id)sender; - (void) copyFont: (id)sender;
- (void)copyRuler:(id)sender; - (void) copyRuler: (id)sender;
- (void)cut:(id)sender; - (void) cut: (id)sender;
- (void)delete:(id)sender; - (void) delete: (id)sender;
- (void)paste:(id)sender; - (void) paste: (id)sender;
- (void)pasteFont:(id)sender; - (void) pasteFont: (id)sender;
- (void)pasteRuler:(id)sender; - (void) pasteRuler: (id)sender;
- (void)selectAll:(id)sender; - (void) selectAll: (id)sender;
// /*
// Managing Font * Managing Font
// */
- (void)changeFont:(id)sender; - (void) changeFont: (id)sender;
- (NSFont *)font; - (NSFont*) font;
- (void)setFont:(NSFont *)obj; - (void) setFont: (NSFont*)obj;
- (void)setFont:(NSFont *)font ofRange:(NSRange)range; - (void) setFont: (NSFont*)font ofRange: (NSRange)range;
// /*
// Managing Alingment * Managing Alignment
// */
- (NSTextAlignment) alignment; - (NSTextAlignment) alignment;
- (void) setAlignment: (NSTextAlignment) mode; - (void) setAlignment: (NSTextAlignment)mode;
- (void)alignCenter:(id)sender; - (void) alignCenter: (id)sender;
- (void)alignLeft:(id)sender; - (void) alignLeft: (id)sender;
- (void)alignRight:(id)sender; - (void) alignRight: (id)sender;
// /*
// Text colour * Text colour
// */
- (void) setTextColor:(NSColor *)color range:(NSRange)range; - (void) setTextColor: (NSColor*)color range: (NSRange)range;
- (void) setColor:(NSColor *)color ofRange:(NSRange)range; - (void) setColor: (NSColor*)color ofRange: (NSRange)range;
- (void) setTextColor:(NSColor *)color; - (void) setTextColor: (NSColor*)color;
- (NSColor *)textColor; - (NSColor*) textColor;
// /*
// Text attributes * Text attributes
// */
- (void)subscript:(id)sender; - (void) subscript: (id)sender;
- (void)superscript:(id)sender; - (void) superscript: (id)sender;
- (void)underline:(id)sender; - (void) underline: (id)sender;
- (void)unscript:(id)sender; - (void) unscript: (id)sender;
// /*
// Reading and Writing RTFD Files * Reading and Writing RTFD Files
// */
-(BOOL) readRTFDFromFile:(NSString *)path; -(BOOL) readRTFDFromFile: (NSString*)path;
-(BOOL) writeRTFDToFile:(NSString *)path atomically:(BOOL)flag; -(BOOL) writeRTFDToFile: (NSString*)path atomically: (BOOL)flag;
-(NSData*) RTFDFromRange:(NSRange)range; -(NSData*) RTFDFromRange: (NSRange)range;
-(NSData*) RTFFromRange:(NSRange)range; -(NSData*) RTFFromRange: (NSRange)range;
// /*
// Sizing the Frame Rectangle * Sizing the Frame Rectangle
// */
- (BOOL)isHorizontallyResizable; - (BOOL) isHorizontallyResizable;
- (BOOL)isVerticallyResizable; - (BOOL) isVerticallyResizable;
- (NSSize)maxSize; - (NSSize) maxSize;
- (NSSize)minSize; - (NSSize) minSize;
- (void)setHorizontallyResizable:(BOOL)flag; - (void) setHorizontallyResizable: (BOOL)flag;
- (void)setMaxSize:(NSSize)newMaxSize; - (void) setMaxSize: (NSSize)newMaxSize;
- (void)setMinSize:(NSSize)newMinSize; - (void) setMinSize: (NSSize)newMinSize;
- (void)setVerticallyResizable:(BOOL)flag; - (void) setVerticallyResizable: (BOOL)flag;
- (void)sizeToFit; - (void) sizeToFit;
// /*
// Spelling * Spelling
// */
-(void) checkSpelling:(id)sender; - (void) checkSpelling: (id)sender;
-(void) showGuessPanel:(id)sender; - (void) showGuessPanel: (id)sender;
// /*
// Scrolling * Scrolling
// */
- (void)scrollRangeToVisible:(NSRange)range; - (void) scrollRangeToVisible: (NSRange)range;
// /*
// Managing the Delegate * Managing the Delegate
// */
- delegate; - (id) delegate;
-(void) setDelegate:anObject; - (void) setDelegate: (id)anObject;
/*
* NSCoding protocol
*/
- (void) encodeWithCoder: (NSCoder*)aCoder;
- (id) initWithCoder: (NSCoder*)aDecoder;
// /*
// NSCoding protocol * NSChangeSpelling protocol
// */
- (void)encodeWithCoder:aCoder; - (void) changeSpelling: (id)sender;
- initWithCoder:aDecoder;
// /*
// NSChangeSpelling protocol * NSIgnoreMisspelledWords protocol
// */
- (void) changeSpelling:(id)sender; - (void) ignoreSpelling: (id)sender;
//
// NSIgnoreMisspelledWords protocol
//
- (void)ignoreSpelling:(id)sender;
@end @end
@interface NSText(GNUstepExtension) @interface NSText(GNUstepExtension)
// GNU extension (override it if you want other characters treated // GNU extension (override it if you want other characters treated
// as newline characters) // as newline characters)
+(NSString*) newlineString; + (NSString*) newlineString;
// GNU extension // GNU extension
-(void) replaceRange:(NSRange)range - (void) replaceRange: (NSRange)range
withAttributedString:(NSAttributedString*)attrString; withAttributedString: (NSAttributedString*)attrString;
-(unsigned) textLength; - (unsigned) textLength;
- (NSRange) lineRangeForRect: (NSRect) rect;
- (NSRect) rectForCharacterIndex: (unsigned) index;
// //
// these NSTextView methods are here only informally (GNU extensions) // these NSTextView methods are here only informally (GNU extensions)
// //
-(int) spellCheckerDocumentTag; - (int) spellCheckerDocumentTag;
-(void) insertText:insertString; // argument may be of class NSString or NSAttributedString (if isRichText) // changed to only except class NSString
-(NSMutableDictionary*) typingAttributes; - (void) insertText: (NSString*)insertString;
-(void) setTypingAttributes:(NSDictionary *)attrs;
-(BOOL) shouldDrawInsertionPoint; - (NSMutableDictionary*) typingAttributes;
-(void) drawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)flag; - (void) setTypingAttributes: (NSDictionary*)attrs;
-(NSRange) selectionRangeForProposedRange:(NSRange)proposedCharRange granularity:(NSSelectionGranularity)granularity; // override if you want special cursor behaviour - (void) updateFontPanel;
-(NSArray*) acceptableDragTypes; - (BOOL) shouldDrawInsertionPoint;
-(void) updateDragTypeRegistration; - (void) drawInsertionPointInRect: (NSRect)rect
color: (NSColor*)color
turnedOn: (BOOL)flag;
// override if you want special cursor behaviour
- (NSRange) selectionRangeForProposedRange: (NSRange)proposedCharRange
granularity: (NSSelectionGranularity)granularity;
- (NSArray*) acceptableDragTypes;
- (void) updateDragTypeRegistration;
@end @end
/* Notifications */ /* Notifications */
@ -332,11 +335,11 @@ extern NSString *NSTextDidChangeNotification;
#ifdef GNUSTEP #ifdef GNUSTEP
@interface NSObject(NSTextDelegate) @interface NSObject(NSTextDelegate)
- (BOOL)textShouldBeginEditing:(NSText *)textObject; /* YES means do it */ - (BOOL) textShouldBeginEditing: (NSText*)textObject; /* YES means do it */
- (BOOL)textShouldEndEditing:(NSText *)textObject; /* YES means do it */ - (BOOL) textShouldEndEditing: (NSText*)textObject; /* YES means do it */
- (void)textDidBeginEditing:(NSNotification *)notification; - (void) textDidBeginEditing: (NSNotification*)notification;
- (void)textDidEndEditing:(NSNotification *)notification; - (void) textDidEndEditing: (NSNotification*)notification;
- (void)textDidChange:(NSNotification *)notification; /* Any keyDown or paste which changes the contents causes this */ - (void) textDidChange: (NSNotification*)notification; /* Any keyDown or paste which changes the contents causes this */
@end @end
#endif #endif

View file

@ -365,8 +365,14 @@ static Class fontPanelClass = Nil;
// We update our own selected font // We update our own selected font
if (_selectedFont != nil) if (_selectedFont != nil)
[self setSelectedFont: [self convertFont: _selectedFont] {
isMultiple: _multiple]; NSFont *newFont = [self convertFont: _selectedFont];
if (newFont != nil)
{
[self setSelectedFont: newFont isMultiple: _multiple];
}
}
} }
- (void) removeFontTrait: (id)sender - (void) removeFontTrait: (id)sender
@ -377,8 +383,14 @@ static Class fontPanelClass = Nil;
// We update our own selected font // We update our own selected font
if (_selectedFont != nil) if (_selectedFont != nil)
[self setSelectedFont: [self convertFont: _selectedFont] {
isMultiple: _multiple]; NSFont *newFont = [self convertFont: _selectedFont];
if (newFont != nil)
{
[self setSelectedFont: newFont isMultiple: _multiple];
}
}
} }
- (void) modifyFont: (id)sender - (void) modifyFont: (id)sender
@ -388,8 +400,14 @@ static Class fontPanelClass = Nil;
// We update our own selected font // We update our own selected font
if (_selectedFont != nil) if (_selectedFont != nil)
[self setSelectedFont: [self convertFont: _selectedFont] {
isMultiple: _multiple]; NSFont *newFont = [self convertFont: _selectedFont];
if (newFont != nil)
{
[self setSelectedFont: newFont isMultiple: _multiple];
}
}
} }
- (void) modifyFontViaPanel: (id)sender - (void) modifyFontViaPanel: (id)sender
@ -399,8 +417,14 @@ static Class fontPanelClass = Nil;
// We update our own selected font // We update our own selected font
if (_selectedFont != nil) if (_selectedFont != nil)
[self setSelectedFont: [self convertFont: _selectedFont] {
isMultiple: _multiple]; NSFont *newFont = [self convertFont: _selectedFont];
if (newFont != nil)
{
[self setSelectedFont: newFont isMultiple: _multiple];
}
}
} }
/* /*

View file

@ -222,6 +222,8 @@ float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
//TODO: We go over every item in the panel and check if a //TODO: We go over every item in the panel and check if a
// value is selected. If so we send it on to the manager // value is selected. If so we send it on to the manager
// newFont = [fm convertFont: fontObject toHaveTrait: NSItalicFontMask]; // newFont = [fm convertFont: fontObject toHaveTrait: NSItalicFontMask];
NSLog(@"Multiple font conversion not implemented in NSFontPanel");
newFont = nil;
} }
else else
{ {

File diff suppressed because it is too large Load diff

View file

@ -934,8 +934,8 @@ container, returning the modified location. */
[super setDelegate: anObject]; [super setDelegate: anObject];
#define SET_DELEGATE_NOTIFICATION(notif_name) \ #define SET_DELEGATE_NOTIFICATION(notif_name) \
if ([delegate respondsToSelector: @selector(textView##notif_name: )]) \ if ([_delegate respondsToSelector: @selector(textView##notif_name: )]) \
[nc addObserver: delegate \ [nc addObserver: _delegate \
selector: @selector(textView##notif_name: ) \ selector: @selector(textView##notif_name: ) \
name: NSTextView##notif_name##Notification \ name: NSTextView##notif_name##Notification \
object: self] object: self]