NSText works!

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4457 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Michael Silva 1999-06-22 23:37:24 +00:00
parent fdb0188039
commit acf7614115
6 changed files with 531 additions and 726 deletions

View file

@ -1,3 +1,19 @@
1999-06-22 Michael Hanni <mhanni@sprintmail.com>
* Source/NSText.m: new file from Daniel. Modifications to allow it
to work with GNUstep. Plus multiple hacks to make it work with
NSTextField and NSTextView better.
* Source/NSTextView.m: ditto.
* Source/NSCell.m: modifications to editWithFrame:::: so our field
editor is a little better lined up. Plus fieldEditor gets our
mouseDown: event. Fixed flicker, I think.
TODO:
* fix Caret. Without an insertion marker its hard to see. :-)
* fix buffer for using a fieldEditor in a cell. Possibly modify
NSTextFieldCell so it doesn't draw text directly abutting the
side?
1999-06-21 Michael Hanni <mhanni@sprintmail.com>
* Source/NSText.m: a bunch of little tweaks. Will document today.

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>
Date: 1996
Author: Felipe A. Rodriguez <far@ix.netcom.com>
Date: July 1998
Author: Daniel Bðhringer <boehring@biomed.ruhr-uni-bochum.de>
Date: August 1998
This file is part of the GNUstep GUI Library.
Author: Scott Christley <scottc@net-community.com>
Date: 1996
Author: Felipe A. Rodriguez <far@ix.netcom.com>
Date: July 1998
Author: Daniel Bðhringer <boehring@biomed.ruhr-uni-bochum.de>
Date: August 1998
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.
This file is part of the GNUstep GUI Library.
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.
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.
*/
#ifndef _GNUstep_H_NSText
@ -44,6 +44,7 @@
@class NSColor;
@class NSFont;
#if GNUSTEP
typedef enum _NSTextAlignment {
NSLeftTextAlignment,
NSRightTextAlignment,
@ -55,13 +56,14 @@ typedef enum _NSTextAlignment {
enum {
NSIllegalTextMovement = 0,
NSReturnTextMovement = 0x10,
NSTabTextMovement = 0x11,
NSTabTextMovement = 0x11,
NSBacktabTextMovement = 0x12,
NSLeftTextMovement = 0x13,
NSRightTextMovement = 0x14,
NSUpTextMovement = 0x15,
NSDownTextMovement = 0x16
};
#endif
// these definitions should migrate to NSTextView when implemented
@ -71,16 +73,17 @@ typedef enum _NSSelectionGranularity
NSSelectByParagraph = 2,
} NSSelectionGranularity;
#if GNUSTEP
typedef enum _NSSelectionAffinity
{ NSSelectionAffinityUpstream = 0,
NSSelectionAffinityDownstream = 1,
} NSSelectionAffinity;
#endif
@interface NSText : NSView <NSChangeSpelling,NSIgnoreMisspelledWords,NSCoding>
{
{ // Attributes
id delegate;
unsigned int alignment;
unsigned int alignment; //NSTextAlignment
BOOL is_editable;
BOOL is_rich_text;
BOOL is_selectable;
@ -95,21 +98,23 @@ typedef enum _NSSelectionAffinity
NSColor *text_color;
NSFont *default_font;
NSRange selected_range;
void *be_text_reserved; // Reserved for back-end use
NSSize minSize, maxSize; // added for Daniel Bðhringer
// added by Daniel Bðhringer
NSSize minSize,maxSize;
NSMutableDictionary *typingAttributes;
// content
NSMutableString *plainContent;
NSMutableAttributedString *rtfContent;
NSCharacterSet *selectionWordGranularitySet;
NSCharacterSet *selectionParagraphGranularitySet;
NSMutableString *plainContent;
NSMutableAttributedString *rtfContent;
id lineLayoutInformation;
NSMutableDictionary *typingAttributes;
float currentCursorX; // column-stable cursor up/down
BOOL displayDisabled;
int spellCheckerDocumentTag;
// internal stuff
NSMutableArray *lineLayoutInformation; // contains private _GNULineLayoutInfo objects
int spellCheckerDocumentTag;
NSCharacterSet *selectionWordGranularitySet,*selectionParagraphGranularitySet;
BOOL displayDisabled;
float currentCursorX; // column-stable cursor up/down
}
@ -293,8 +298,7 @@ typedef enum _NSSelectionAffinity
// these are implementation specific (GNU extensions)
//
-(int) rebuildLineLayoutInformationStartingAtLine:(int) aLine; // returns count of lines actually updated (e.g. drawing optimization)
-(int) rebuildPlainLineLayoutInformationStartingAtLine:(int) aLine delta:(int) insertionDelta actualLine:(int) insertionLine; // override for special layout of plain text
-(int) rebuildRichLineLayoutInformationStartingAtLine:(int) aLine delta:(int) insertionDelta actualLine:(int) insertionLine; // ditto for rich text
-(int) rebuildLineLayoutInformationStartingAtLine:(int) aLine delta:(int) insertionDelta actualLine:(int) insertionLine; // override for special layout of text
-(int) lineLayoutIndexForCharacterIndex:(unsigned) anIndex; // return value is identical to the real line number (plus counted newline characters)
-(void) redisplayForLineRange:(NSRange) redrawLineRange;
@ -304,6 +308,7 @@ typedef enum _NSSelectionAffinity
//
// various GNU extensions
//
-(void) rebuildFromCharacterIndex:(int) anIndex;
-(void) setSelectionWordGranularitySet:(NSCharacterSet*) aSet;
-(void) setSelectionParagraphGranularitySet:(NSCharacterSet*) aSet;
@ -313,8 +318,6 @@ typedef enum _NSSelectionAffinity
//
-(void) drawRectNoSelection:(NSRect)rect;
-(int) rebuildPlainLineLayoutInformationStartingAtLine:(int) aLine; // low level never invoke (use rebuildLineLayoutInformationStartingAtLine:)
-(int) rebuildRichLineLayoutInformationStartingAtLine:(int) aLine; // ditto
@end
@ -323,6 +326,7 @@ extern NSString *NSTextDidBeginEditingNotification;
extern NSString *NSTextDidEndEditingNotification;
extern NSString *NSTextDidChangeNotification;
#ifdef GNUSTEP
@interface NSObject(NSTextDelegate)
- (BOOL)textShouldBeginEditing:(NSText *)textObject; /* YES means do it */
- (BOOL)textShouldEndEditing:(NSText *)textObject; /* YES means do it */
@ -330,5 +334,19 @@ extern NSString *NSTextDidChangeNotification;
- (void)textDidEndEditing:(NSNotification *)notification;
- (void)textDidChange:(NSNotification *)notification; /* Any keyDown or paste which changes the contents causes this */
@end
#endif
#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

@ -1,38 +1,11 @@
/*
NSTextView.h
* GNUTextView.h
*/
NSTextView is an NSText subclass that displays the glyphs laid
out in one NSTextContainer.
// GNUTextView is a 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>
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 _GNUstep_H_NSTextView
#define _GNUstep_H_NSTextView
#include <AppKit/NSText.h>
#include <AppKit/NSTextAttachment.h>
#import <AppKit/NSText.h>
#import <AppKit/NSTextAttachment.h>
#include <AppKit/NSRulerView.h>
#include <AppKit/NSRulerMarker.h>
@ -41,16 +14,19 @@
@class NSLayoutManager;
//@interface NSTextView : NSText <NSTextInput>
@interface NSTextView : NSText
{ NSTextContainer *textContainer;
NSColor *insertionPointColor;
BOOL smartInsertDeleteEnabled;
NSSelectionAffinity selectionAffinity;
NSSelectionGranularity selectionGranularity;
NSSize textContainerInset;
NSPoint textContainerOrigin;
NSLayoutManager *layoutManager;
NSTextStorage *textStorage;
@interface NSTextView : NSText
{
NSTextContainer *textContainer;
NSColor *insertionPointColor;
BOOL smartInsertDeleteEnabled;
NSSelectionAffinity selectionAffinity;
NSSelectionGranularity selectionGranularity;
NSSize textContainerInset;
NSPoint textContainerOrigin;
NSLayoutManager *layoutManager;
NSTextStorage *textStorage;
}
/**************************** Initializing ****************************/
@ -150,7 +126,7 @@
@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.
// The methods in this category deal with settings that need to be shared by all the GNUTextViews of a single NSLayoutManager. Many of these methods are overrides of NSText or NSResponder methods.
/*************************** Selected/Marked range ***************************/
@ -172,7 +148,7 @@
- (void)setMarkedTextAttributes:(NSDictionary *)attributeDictionary;
- (NSDictionary *)markedTextAttributes;
/*************************** Other NSTextView methods ***************************/
/*************************** Other GNUTextView methods ***************************/
- (void)setRulerVisible:(BOOL)flag;
- (BOOL)usesRuler;
@ -192,28 +168,28 @@
/*************************** 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;
- (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;
- (NSRange)selectedRange;
- (void)setSelectedRange:(NSRange)charRange;
/*************************** NSResponder methods ***************************/
@ -238,7 +214,8 @@
- (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
- (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.
@ -258,5 +235,3 @@ extern NSString *NSTextViewWillChangeNotifyingTextViewNotification;
extern NSString *NSTextViewDidChangeSelectionNotification;
// NSOldSelectedCharacterRange -> NSValue with old range.
#endif /* _GNUstep_H_NSTextView */

View file

@ -451,16 +451,21 @@ static Class imageClass;
(int)bRect.size.width,
(int)bRect.size.height);
bRect.origin.x -= 2;
bRect.size.width += 2;
[textObject setDelegate: anObject];
[textObject setFrame: bRect];
[[NSColor redColor] set];
NSRectFill(aRect);
// NSEraseRect(aRect);
NSEraseRect(aRect);
[textObject setText: [self stringValue]];
[[[controlView window] contentView] addSubview: textObject];
if ([theEvent type] == NSLeftMouseDown)
[textObject mouseDown:theEvent];
[textObject display];
[controlView unlockFocus];
}

File diff suppressed because it is too large Load diff

View file

@ -1,29 +1,8 @@
/*
NSTextView.m
* NSTextView.h
*/
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.
*/
// classes needed are: NSRulerView NSTextContainer NSLayoutManager
#include <AppKit/NSTextView.h>
#include <AppKit/NSRulerView.h>
@ -34,8 +13,6 @@
#include <AppKit/NSLayoutManager.h>
#include <AppKit/NSTextStorage.h>
// classes needed are: NSRulerView NSTextContainer NSLayoutManager
@implementation NSTextView
/**************************** Initializing ****************************/
@ -56,14 +33,11 @@
// container may be nil
- initWithFrame:(NSRect)frameRect textContainer:(NSTextContainer *)container
{
// self=[super initWithFrame:frameRect];
[super initWithFrame:frameRect];
if(container) [self setTextContainer: container];
{ if(container) [self setTextContainer: container];
else // set up a new container
{
}
self=[super initWithFrame:frameRect];
return self;
}
@ -113,13 +87,11 @@ if(container) [self setTextContainer: container];
/************************* Key binding entry-point *************************/
// This method is the funnel point for text insertion after keys pass through the key binder.
#ifdef DEBUGG
-(void) insertText:(NSString*) insertString
{
[super insertText: insertString];
}
#endif /* DEBUGG */
#endif
/*************************** Sizing methods ***************************/
@ -204,7 +176,6 @@ if(container) [self setTextContainer: container];
-(void) setNeedsDisplayInRect:(NSRect)rect avoidAdditionalLayout:(BOOL)fla
{
}
#ifdef DEBUGG
-(BOOL)shouldDrawInsertionPoint
{
@ -212,8 +183,7 @@ if(container) [self setTextContainer: container];
-(void) drawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)flag
{
}
#endif /* DEBUGG */
#endif
/*************************** Especially for subclassers ***************************/
-(void) updateRuler
@ -230,17 +200,14 @@ if(container) [self setTextContainer: container];
if([self importsGraphics]) [ret addObject:NSRTFDPboardType];
return ret;
}
#ifdef DEBUGG
- (void)updateDragTypeRegistration
{
}
- (NSRange)selectionRangeForProposedRange:(NSRange)proposedCharRange granularity:(NSSelectionGranularity)granularity
{
}
#endif /* DEBUGG */
{}
#endif
@end
@implementation NSTextView (NSSharing)
@ -286,7 +253,7 @@ if(container) [self setTextContainer: container];
{
}
/*************************** Other NSTextView methods ***************************/
/*************************** Other GNUTextView methods ***************************/
-(void) setRulerVisible:(BOOL)flag
{
@ -332,7 +299,6 @@ if(container) [self setTextContainer: container];
/*************************** NSResponder methods ***************************/
#ifdef DEBUGG
-(BOOL) resignFirstResponder
{ return YES;
@ -340,8 +306,7 @@ if(container) [self setTextContainer: container];
-(BOOL) becomeFirstResponder
{ return YES;
}
#endif /* DEBUGG */
#endif
/*************************** Smart copy/paste/delete support ***************************/
-(BOOL)smartInsertDeleteEnabled {return smartInsertDeleteEnabled;}
@ -357,19 +322,18 @@ if(container) [self setTextContainer: container];
- (void) setDelegate: (id) anObject
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[super setDelegate: anObject];
#define SET_DELEGATE_NOTIFICATION(notif_name) \
if ([delegate respondsToSelector: @selector(textView##notif_name:)]) \
[nc addObserver: delegate \
selector: @selector(textView##notif_name:) \
name: NSTextView##notif_name##Notification \
object: self]
selector: @selector(textView##notif_name:) \
name: NSTextView##notif_name##Notification \
object: self]
SET_DELEGATE_NOTIFICATION(DidChangeSelection);
SET_DELEGATE_NOTIFICATION(WillChangeNotifyingTextView);
}
@end