2000-03-16 14:16:46 +00:00
|
|
|
|
/*
|
1996-05-30 20:03:15 +00:00
|
|
|
|
NSText.m
|
|
|
|
|
|
|
|
|
|
The RTFD text class
|
|
|
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
1999-11-11 17:17:14 +00:00
|
|
|
|
Author: Scott Christley <scottc@net-community.com>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
Date: 1996
|
1998-08-01 15:41:49 +00:00
|
|
|
|
Author: Felipe A. Rodriguez <far@ix.netcom.com>
|
|
|
|
|
Date: July 1998
|
1999-11-11 17:17:14 +00:00
|
|
|
|
Author: Daniel B<EFBFBD>hringer <boehring@biomed.ruhr-uni-bochum.de>
|
1998-08-20 09:56:26 +00:00
|
|
|
|
Date: August 1998
|
2000-03-16 14:16:46 +00:00
|
|
|
|
Author: Fred Kiefer <FredKiefer@gmx.de>
|
|
|
|
|
Date: March 2000
|
|
|
|
|
Reorganised and cleaned up code, added some action methods
|
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
|
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.
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
|
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
|
1996-10-18 17:14:13 +00:00
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
|
If not, write to the Free Software Foundation,
|
1999-11-02 07:58:11 +00:00
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111 - 1307, USA.
|
1999-06-22 23:37:24 +00:00
|
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
1999-11-11 17:17:14 +00:00
|
|
|
|
// toDo: - caret blinking
|
|
|
|
|
// - formatting routine: broader than 1.5x width cause display problems
|
|
|
|
|
// - optimization: 1.deletion of single char in paragraph [opti hook 1]
|
|
|
|
|
// - optimization: 2.newline in first line
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// - optimization: 3.paragraph made one less line due to delition
|
1999-11-11 17:17:14 +00:00
|
|
|
|
// of single char [opti hook 1; diff from 1.]
|
1998-10-15 12:04:53 +00:00
|
|
|
|
|
1997-09-23 22:43:24 +00:00
|
|
|
|
#include <gnustep/gui/config.h>
|
1999-11-14 03:23:54 +00:00
|
|
|
|
#include <Foundation/NSNotification.h>
|
1997-08-18 17:10:23 +00:00
|
|
|
|
#include <Foundation/NSString.h>
|
1998-08-20 09:56:26 +00:00
|
|
|
|
|
1998-09-02 15:05:13 +00:00
|
|
|
|
#include <AppKit/NSFileWrapper.h>
|
|
|
|
|
#include <AppKit/NSControl.h>
|
1997-02-18 00:29:25 +00:00
|
|
|
|
#include <AppKit/NSText.h>
|
|
|
|
|
#include <AppKit/NSApplication.h>
|
|
|
|
|
#include <AppKit/NSWindow.h>
|
2000-03-08 08:43:15 +00:00
|
|
|
|
#include <AppKit/NSFontManager.h>
|
1997-02-18 00:29:25 +00:00
|
|
|
|
#include <AppKit/NSFont.h>
|
|
|
|
|
#include <AppKit/NSColor.h>
|
2000-03-08 08:43:15 +00:00
|
|
|
|
#include <AppKit/NSParagraphStyle.h>
|
1998-08-20 09:56:26 +00:00
|
|
|
|
#include <AppKit/NSPasteboard.h>
|
1998-09-02 15:05:13 +00:00
|
|
|
|
#include <AppKit/NSSpellChecker.h>
|
1999-06-22 23:37:24 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
#include <AppKit/NSDragging.h>
|
1998-09-02 15:05:13 +00:00
|
|
|
|
#include <AppKit/NSStringDrawing.h>
|
2000-03-23 11:32:59 +00:00
|
|
|
|
#include <AppKit/NSTextStorage.h>
|
2000-04-23 22:31:25 +00:00
|
|
|
|
#include <AppKit/NSTextContainer.h>
|
1998-08-20 09:56:26 +00:00
|
|
|
|
|
1998-09-02 15:05:13 +00:00
|
|
|
|
#include <Foundation/NSNotification.h>
|
|
|
|
|
#include <Foundation/NSArchiver.h>
|
|
|
|
|
#include <Foundation/NSValue.h>
|
1998-08-20 09:56:26 +00:00
|
|
|
|
#include <Foundation/NSScanner.h>
|
1998-10-15 12:04:53 +00:00
|
|
|
|
#include <Foundation/NSData.h>
|
|
|
|
|
|
|
|
|
|
#define HUGE 1e99
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
static NSCharacterSet *selectionWordGranularitySet;
|
|
|
|
|
static NSCharacterSet *selectionParagraphGranularitySet;
|
2000-04-23 22:31:25 +00:00
|
|
|
|
static NSCharacterSet *invSelectionWordGranularitySet;
|
|
|
|
|
static NSCharacterSet *invSelectionParagraphGranularitySet;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
1999-08-31 09:19:39 +00:00
|
|
|
|
@interface _GNULineLayoutInfo: NSObject
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
@public
|
|
|
|
|
NSRange lineRange;
|
1999-11-11 17:17:14 +00:00
|
|
|
|
NSRect lineRect;
|
|
|
|
|
unsigned type;
|
1998-09-02 15:05:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef enum
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
1999-11-11 17:17:14 +00:00
|
|
|
|
// do not use 0 in order to secure calls to nil (calls to nil return 0)!
|
|
|
|
|
LineLayoutInfoType_Text = 1,
|
|
|
|
|
LineLayoutInfoType_Paragraph = 2
|
1998-09-02 15:05:13 +00:00
|
|
|
|
} _GNULineLayoutInfo_t;
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
+ (id) lineLayoutWithRange: (NSRange)aRange
|
|
|
|
|
rect: (NSRect)aRect
|
|
|
|
|
type: (unsigned)aType;
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
1999-11-11 17:17:14 +00:00
|
|
|
|
- (NSRange) lineRange;
|
|
|
|
|
- (NSRect) lineRect;
|
|
|
|
|
- (unsigned) type;
|
1999-11-02 07:58:11 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setLineRange: (NSRange)aRange;
|
|
|
|
|
- (void) setLineRect: (NSRect)aRect;
|
|
|
|
|
- (void) setType: (unsigned)aType;
|
1999-11-02 07:58:11 +00:00
|
|
|
|
|
|
|
|
|
- (NSString*) description;
|
1998-09-02 15:05:13 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation _GNULineLayoutInfo
|
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
+ (_GNULineLayoutInfo *) lineLayoutWithRange: (NSRange)aRange
|
2000-03-16 14:16:46 +00:00
|
|
|
|
rect: (NSRect)aRect
|
|
|
|
|
type: (unsigned)aType
|
|
|
|
|
{
|
2000-04-23 22:31:25 +00:00
|
|
|
|
_GNULineLayoutInfo *ret = AUTORELEASE([_GNULineLayoutInfo new]);
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
ret->lineRange = aRange;
|
|
|
|
|
ret->lineRect =aRect;
|
|
|
|
|
ret->type = aType;
|
1999-11-11 17:17:14 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (unsigned) type
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (NSRange) lineRange
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
|
|
|
|
return lineRange;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (NSRect) lineRect
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
|
|
|
|
return lineRect;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setLineRange: (NSRange)aRange
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
|
|
|
|
lineRange = aRange;
|
|
|
|
|
}
|
1999-06-22 23:37:24 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setLineRect: (NSRect)aRect
|
1999-06-22 23:37:24 +00:00
|
|
|
|
{
|
1999-11-02 07:58:11 +00:00
|
|
|
|
lineRect = aRect;
|
1999-06-22 23:37:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setType: (unsigned)aType
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
|
|
|
|
type = aType;
|
|
|
|
|
}
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
1999-11-02 07:58:11 +00:00
|
|
|
|
- (NSString*) description
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
|
|
|
|
return [[NSDictionary dictionaryWithObjectsAndKeys:
|
1999-11-11 17:17:14 +00:00
|
|
|
|
NSStringFromRange(lineRange), @"LineRange",
|
|
|
|
|
NSStringFromRect(lineRect), @"LineRect",
|
2000-03-16 14:16:46 +00:00
|
|
|
|
nil]
|
1999-11-11 17:17:14 +00:00
|
|
|
|
description];
|
1998-09-02 15:05:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
1999-11-11 17:17:14 +00:00
|
|
|
|
static NSRange MakeRangeFromAbs (int a1,int a2) // not the same as NSMakeRange!
|
1999-06-22 23:37:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (a1 < 0)
|
1999-11-02 07:58:11 +00:00
|
|
|
|
a1 = 0;
|
1999-06-22 23:37:24 +00:00
|
|
|
|
if (a2 < 0)
|
1999-11-02 07:58:11 +00:00
|
|
|
|
a2 = 0;
|
1999-06-22 23:37:24 +00:00
|
|
|
|
if (a1 < a2)
|
1999-11-11 17:17:14 +00:00
|
|
|
|
return NSMakeRange (a1, a2 - a1);
|
1999-06-22 23:37:24 +00:00
|
|
|
|
else
|
1999-11-11 17:17:14 +00:00
|
|
|
|
return NSMakeRange (a2, a1 - a2);
|
1999-06-22 23:37:24 +00:00
|
|
|
|
}
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// end: _GNULineLayoutInfo------------------------------------------------------
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
1999-08-31 09:19:39 +00:00
|
|
|
|
@interface _GNUSeekableArrayEnumerator: NSObject
|
1999-11-02 07:58:11 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned currentIndex;
|
|
|
|
|
NSArray *array;
|
1998-10-15 12:04:53 +00:00
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (id) initWithArray: (NSArray*)anArray;
|
|
|
|
|
- (id) nextObject;
|
|
|
|
|
- (id) previousObject;
|
|
|
|
|
- (id) currentObject;
|
1998-10-15 12:04:53 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation _GNUSeekableArrayEnumerator
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (id) initWithArray: (NSArray*)anArray
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
self = [super init];
|
|
|
|
|
array = RETAIN(anArray);
|
1999-11-11 17:17:14 +00:00
|
|
|
|
return self;
|
1998-10-15 12:04:53 +00:00
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
|
|
|
|
- (id) nextObject
|
|
|
|
|
{
|
|
|
|
|
if (currentIndex >= [array count])
|
1999-11-11 17:17:14 +00:00
|
|
|
|
return nil;
|
|
|
|
|
return [array objectAtIndex: currentIndex++];
|
1998-10-15 12:04:53 +00:00
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
|
|
|
|
- (id) previousObject
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (currentIndex == 0)
|
1999-11-11 17:17:14 +00:00
|
|
|
|
return nil;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return [array objectAtIndex: --currentIndex];
|
1998-10-15 12:04:53 +00:00
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
|
|
|
|
- (id) currentObject
|
|
|
|
|
{
|
1999-11-11 17:17:14 +00:00
|
|
|
|
return [array objectAtIndex: currentIndex];
|
1998-10-15 12:04:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-02 07:58:11 +00:00
|
|
|
|
- (void) dealloc
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
|
|
|
|
RELEASE(array);
|
1999-11-11 17:17:14 +00:00
|
|
|
|
[super dealloc];
|
1998-10-15 12:04:53 +00:00
|
|
|
|
}
|
|
|
|
|
@end
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
1998-10-15 12:04:53 +00:00
|
|
|
|
@interface NSArray(SeekableEnumerator)
|
1999-11-02 07:58:11 +00:00
|
|
|
|
- (_GNUSeekableArrayEnumerator*) seekableEnumerator;
|
1998-10-15 12:04:53 +00:00
|
|
|
|
@end
|
|
|
|
|
@implementation NSArray(SeekableEnumerator)
|
1999-11-02 07:58:11 +00:00
|
|
|
|
- (_GNUSeekableArrayEnumerator*) seekableEnumerator
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
|
|
|
|
return AUTORELEASE([[_GNUSeekableArrayEnumerator alloc] initWithArray: self]);
|
1998-10-15 12:04:53 +00:00
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
1999-06-22 23:37:24 +00:00
|
|
|
|
|
|
|
|
|
|
2000-03-08 08:43:15 +00:00
|
|
|
|
@interface NSText(GNUstepPrivate)
|
2000-03-16 14:16:46 +00:00
|
|
|
|
/*
|
|
|
|
|
* these NSLayoutManager- like methods are here only informally (GNU extensions)
|
|
|
|
|
*/
|
|
|
|
|
- (unsigned) characterIndexForPoint: (NSPoint)point;
|
|
|
|
|
- (NSRect) rectForCharacterIndex: (unsigned)index;
|
2000-03-19 07:33:26 +00:00
|
|
|
|
- (void) _buildUpLayout;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) drawRect: (NSRect)rect
|
|
|
|
|
withSelection: (NSRange)range;
|
2000-06-26 19:55:01 +00:00
|
|
|
|
- (NSRect) _textBounds;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
/*
|
|
|
|
|
* various GNU extensions
|
|
|
|
|
*/
|
|
|
|
|
+ (void) setSelectionWordGranularitySet: (NSCharacterSet*)aSet;
|
|
|
|
|
+ (void) setSelectionParagraphGranularitySet: (NSCharacterSet*)aSet;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
+ (NSDictionary*) defaultTypingAttributes;
|
|
|
|
|
|
2000-03-08 08:43:15 +00:00
|
|
|
|
//
|
2000-06-26 19:55:01 +00:00
|
|
|
|
// GNU utility methods
|
2000-03-08 08:43:15 +00:00
|
|
|
|
//
|
2000-06-26 19:55:01 +00:00
|
|
|
|
- (void) setAttributes: (NSDictionary*) attributes range: (NSRange) aRange;
|
|
|
|
|
- (void) _illegalMovement: (int) notNumber;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) deleteRange: (NSRange)aRange backspace: (BOOL)flag;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
|
|
|
|
- (void) setSelectedRangeNoDrawing: (NSRange)range;
|
|
|
|
|
- (void) drawInsertionPointAtIndex: (unsigned)index
|
|
|
|
|
color: (NSColor*)color
|
|
|
|
|
turnedOn: (BOOL)flag;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) drawSelectionAsRangeNoCaret: (NSRange)aRange;
|
|
|
|
|
- (void) drawSelectionAsRange: (NSRange)aRange;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
1998-11-24 15:25:22 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
@interface GSSimpleLayoutManager: NSObject
|
|
|
|
|
{
|
|
|
|
|
// contains private _GNULineLayoutInfo objects
|
|
|
|
|
NSMutableArray *lineLayoutInformation;
|
|
|
|
|
NSText *_textHolder;
|
2000-04-02 05:58:50 +00:00
|
|
|
|
NSTextStorage *_textStorage;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-02 05:58:50 +00:00
|
|
|
|
- (id) initForText: (NSText*) aTextHolder;
|
2000-04-23 22:31:25 +00:00
|
|
|
|
- (NSTextStorage*) textStorage;
|
2000-04-02 05:58:50 +00:00
|
|
|
|
- (void) setTextStorage: (NSTextStorage*) aTextStorage;
|
2000-04-23 22:31:25 +00:00
|
|
|
|
- (void)textStorage:(NSTextStorage *)aTextStorage
|
|
|
|
|
edited:(unsigned int)mask
|
|
|
|
|
range:(NSRange)range
|
|
|
|
|
changeInLength:(int)lengthChange
|
|
|
|
|
invalidatedRange:(NSRange)invalidatedCharRange;
|
|
|
|
|
/*
|
|
|
|
|
- (NSRect *) rectArrayForCharacterRange: (NSRange)charRange
|
|
|
|
|
withinSelectedCharacterRange: (NSRange)selCharRange
|
|
|
|
|
inTextContainer: (NSTextContainer *)aTextContainer
|
|
|
|
|
rectCount: (unsigned int *)rectCount;
|
|
|
|
|
*/
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (NSSize) _sizeOfRange: (NSRange) range;
|
|
|
|
|
- (NSRect) _textBounds;
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (unsigned) characterIndexForPoint: (NSPoint)point;
|
|
|
|
|
- (NSRect) rectForCharacterIndex: (unsigned) index;
|
|
|
|
|
- (NSRange) characterRangeForBoundingRect: (NSRect)bounds;
|
|
|
|
|
- (NSRange) lineRangeForRect: (NSRect) aRect;
|
|
|
|
|
|
|
|
|
|
// return value is identical to the real line number
|
|
|
|
|
// (plus counted newline characters)
|
|
|
|
|
- (int) lineLayoutIndexForCharacterIndex: (unsigned) anIndex;
|
|
|
|
|
// returns the full character range for a line range
|
|
|
|
|
- (NSRange) characterRangeForLineLayoutRange: (NSRange) aRange;
|
|
|
|
|
|
|
|
|
|
- (void) setNeedsDisplayForLineRange: (NSRange) redrawLineRange;
|
|
|
|
|
// override for special layout of text
|
2000-04-23 22:31:25 +00:00
|
|
|
|
- (NSRange) rebuildForRange: (NSRange)aRange
|
|
|
|
|
delta: (int)insertionDelta;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// low level, override but never invoke (use setNeedsDisplayForLineRange:)
|
|
|
|
|
- (void) drawLinesInLineRange: (NSRange)aRange;
|
|
|
|
|
- (NSRange) drawRectCharacters: (NSRect)rect;
|
|
|
|
|
@end
|
1999-08-19 23:18:25 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
@implementation GSSimpleLayoutManager
|
|
|
|
|
- (id) initForText: (NSText*)aTextHolder
|
1999-08-31 09:19:39 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_textHolder = aTextHolder;
|
1999-08-31 09:19:39 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
2000-03-19 07:33:26 +00:00
|
|
|
|
|
2000-04-02 05:58:50 +00:00
|
|
|
|
- (void) setTextStorage: (NSTextStorage*)aTextStorage
|
1998-11-24 15:25:22 +00:00
|
|
|
|
{
|
2000-04-23 22:31:25 +00:00
|
|
|
|
unsigned length = [aTextStorage length];
|
|
|
|
|
NSRange aRange = NSMakeRange(0, length);
|
2000-04-02 05:58:50 +00:00
|
|
|
|
ASSIGN(_textStorage, aTextStorage);
|
2000-04-23 22:31:25 +00:00
|
|
|
|
// force complete re - layout
|
|
|
|
|
RELEASE(lineLayoutInformation);
|
|
|
|
|
lineLayoutInformation = nil;
|
|
|
|
|
[self textStorage: aTextStorage
|
|
|
|
|
edited: NSTextStorageEditedCharacters | NSTextStorageEditedAttributes
|
|
|
|
|
range: aRange
|
|
|
|
|
changeInLength: length
|
|
|
|
|
invalidatedRange: aRange];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSTextStorage*) textStorage
|
|
|
|
|
{
|
|
|
|
|
return _textStorage;
|
1998-11-24 15:25:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (NSSize) _sizeOfRange: (NSRange)aRange
|
1998-11-24 15:25:22 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (!aRange.length || _textStorage == nil ||
|
|
|
|
|
NSMaxRange(aRange) > [_textStorage length])
|
|
|
|
|
return NSZeroSize;
|
1998-10-15 12:04:53 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return [[_textStorage attributedSubstringFromRange: aRange] size];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// Returns the currently used bounds for all the text
|
|
|
|
|
- (NSRect) _textBounds
|
|
|
|
|
{
|
|
|
|
|
if ([lineLayoutInformation count])
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSEnumerator *lineEnum;
|
|
|
|
|
_GNULineLayoutInfo *currentInfo;
|
|
|
|
|
NSRect retRect = NSMakeRect (0, 0, 0, 0);
|
|
|
|
|
|
|
|
|
|
for ((lineEnum = [lineLayoutInformation objectEnumerator]);
|
|
|
|
|
(currentInfo = [lineEnum nextObject]);)
|
|
|
|
|
{
|
|
|
|
|
retRect = NSUnionRect (retRect, [currentInfo lineRect]);
|
|
|
|
|
}
|
|
|
|
|
return retRect;
|
1999-11-11 17:17:14 +00:00
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
else
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return NSZeroRect;
|
1999-07-18 03:53:42 +00:00
|
|
|
|
}
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
- (NSRect) frame
|
1999-08-31 09:19:39 +00:00
|
|
|
|
{
|
2000-04-23 22:31:25 +00:00
|
|
|
|
NSRect aRect = [_textHolder frame];
|
1999-08-31 09:19:39 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
if ([_textHolder isHorizontallyResizable])
|
|
|
|
|
aRect.size.width = HUGE;
|
|
|
|
|
if ([_textHolder isVerticallyResizable])
|
|
|
|
|
aRect.size.height = HUGE;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
return aRect;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (NSRange) characterRangeForLineLayoutRange: (NSRange)aRange;
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_GNULineLayoutInfo *currentInfo;
|
|
|
|
|
unsigned startLine = aRange.location;
|
|
|
|
|
unsigned endLine = NSMaxRange(aRange);
|
|
|
|
|
unsigned startIndex;
|
|
|
|
|
unsigned endIndex;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (startLine >= [lineLayoutInformation count])
|
|
|
|
|
currentInfo = [lineLayoutInformation lastObject];
|
|
|
|
|
else
|
|
|
|
|
currentInfo = [lineLayoutInformation objectAtIndex: startLine];
|
|
|
|
|
startIndex = [currentInfo lineRange].location;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (endLine >= [lineLayoutInformation count])
|
|
|
|
|
currentInfo = [lineLayoutInformation lastObject];
|
|
|
|
|
else
|
|
|
|
|
currentInfo = [lineLayoutInformation objectAtIndex: endLine];
|
|
|
|
|
endIndex = NSMaxRange([currentInfo lineRange]);
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
return NSMakeRange(startIndex, endIndex - startIndex);
|
1999-11-11 17:17:14 +00:00
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (NSRange) characterRangeForBoundingRect: (NSRect)boundsRect
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSRange lineRange = [self lineRangeForRect: boundsRect];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (lineRange.length)
|
|
|
|
|
return [self characterRangeForLineLayoutRange: lineRange];
|
|
|
|
|
else
|
|
|
|
|
return NSMakeRange (0, 0);
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
- (unsigned) lineLayoutIndexForPoint: (NSPoint)point
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
2000-04-23 22:31:25 +00:00
|
|
|
|
int min = 0;
|
|
|
|
|
int max = MAX(0, [lineLayoutInformation count] - 1);
|
|
|
|
|
float y = point.y;
|
|
|
|
|
float fmin = NSMinY([[lineLayoutInformation objectAtIndex: 0] lineRect]);
|
|
|
|
|
float fmax = NSMaxY([[lineLayoutInformation lastObject] lineRect]);
|
|
|
|
|
NSRect rect;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
if (y >= fmax)
|
|
|
|
|
return max;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
if (y <= fmin)
|
|
|
|
|
return min;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
// this should give a good starting index for binary search
|
|
|
|
|
i = (int)((max - min) * (y - fmin) / (fmax - fmin)) + min;
|
|
|
|
|
while (min < max)
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
2000-04-23 22:31:25 +00:00
|
|
|
|
_GNULineLayoutInfo *ci = [lineLayoutInformation objectAtIndex: i];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
rect = [ci lineRect];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
if (NSMaxY(rect) < y)
|
|
|
|
|
{
|
|
|
|
|
min = i + 1;
|
|
|
|
|
i = (max + min) / 2;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (NSMinY(rect) > y)
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
2000-04-23 22:31:25 +00:00
|
|
|
|
max = i - 1;
|
|
|
|
|
i = (max + min) / 2;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
// As the newline char generates its own lineLayoutinfo box
|
|
|
|
|
// there may be two in one line, we have to check for this
|
|
|
|
|
if ((NSMinX(rect) > point.x) && (i > 0) &&
|
|
|
|
|
([ci type] == LineLayoutInfoType_Paragraph))
|
|
|
|
|
{
|
|
|
|
|
_GNULineLayoutInfo *bi = [lineLayoutInformation objectAtIndex: i - 1];
|
|
|
|
|
rect = [bi lineRect];
|
|
|
|
|
if (NSPointInRect(point, rect))
|
|
|
|
|
return i - 1;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
2000-04-23 22:31:25 +00:00
|
|
|
|
if ((NSMaxX(rect) < point.x) && (i < [lineLayoutInformation count] - 1) &&
|
|
|
|
|
([ci type] == LineLayoutInfoType_Text))
|
|
|
|
|
{
|
|
|
|
|
_GNULineLayoutInfo *bi = [lineLayoutInformation objectAtIndex: i + 1];
|
|
|
|
|
rect = [bi lineRect];
|
|
|
|
|
if (NSPointInRect(point, rect))
|
|
|
|
|
return i + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return i;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
2000-04-23 22:31:25 +00:00
|
|
|
|
return min;
|
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
- (unsigned) characterIndexForPoint: (NSPoint)point
|
|
|
|
|
{
|
|
|
|
|
_GNULineLayoutInfo *currentInfo = [lineLayoutInformation
|
|
|
|
|
objectAtIndex:
|
|
|
|
|
[self lineLayoutIndexForPoint: point]];
|
|
|
|
|
NSRect rect = [currentInfo lineRect];
|
|
|
|
|
NSRange range = [currentInfo lineRange];
|
|
|
|
|
int i;
|
|
|
|
|
int min = range.location;
|
|
|
|
|
int max = NSMaxRange(range);
|
|
|
|
|
float x = point.x;
|
|
|
|
|
float fmin = rect.origin.x;
|
|
|
|
|
float fmax = NSMaxX(rect);
|
|
|
|
|
float w1, w2;
|
|
|
|
|
|
|
|
|
|
if (x <= fmin)
|
|
|
|
|
return MAX(0, min - 1);
|
|
|
|
|
if (x >= fmax)
|
|
|
|
|
return MAX(0, max - 1);
|
|
|
|
|
if (range.length == 1)
|
|
|
|
|
return min;
|
|
|
|
|
|
|
|
|
|
// this should give a good starting index for binary search
|
|
|
|
|
i = (int)((max - min) * (x - fmin) / (fmax - fmin)) + min;
|
|
|
|
|
while (min < max)
|
|
|
|
|
{
|
|
|
|
|
w1 = [self _sizeOfRange:
|
|
|
|
|
NSMakeRange (range.location,
|
|
|
|
|
i - range.location)].width + fmin;
|
|
|
|
|
if (i > range.location)
|
|
|
|
|
w2 = [self _sizeOfRange:
|
|
|
|
|
NSMakeRange (range.location,
|
|
|
|
|
i-1 - range.location)].width + fmin;
|
|
|
|
|
else
|
|
|
|
|
w2 = fmin;
|
|
|
|
|
|
|
|
|
|
if (w1 < x)
|
|
|
|
|
{
|
|
|
|
|
min = i + 1;
|
|
|
|
|
i = (max + min) / 2;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (w2 > x)
|
|
|
|
|
{
|
|
|
|
|
max = i - 1;
|
|
|
|
|
i = (max + min) / 2;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
return MAX(0, i-1);
|
|
|
|
|
}
|
|
|
|
|
return MAX(0, min - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (int) lineLayoutIndexForCharacterIndex: (unsigned)anIndex
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int min = 0;
|
|
|
|
|
int max = MAX(0, [lineLayoutInformation count] - 1);
|
|
|
|
|
unsigned y = anIndex;
|
|
|
|
|
unsigned fmin = [[lineLayoutInformation objectAtIndex: 0] lineRange].location;
|
|
|
|
|
unsigned fmax = NSMaxRange([[lineLayoutInformation lastObject] lineRange]);
|
|
|
|
|
NSRange range;
|
|
|
|
|
|
|
|
|
|
if (y >= fmax)
|
|
|
|
|
return max;
|
|
|
|
|
|
|
|
|
|
if (y <= fmin)
|
|
|
|
|
return min;
|
|
|
|
|
|
|
|
|
|
// this should give a good starting index for binary search
|
|
|
|
|
i = (int)((max - min) * (y - fmin) / (fmax - fmin)) + min;
|
|
|
|
|
while (min < max)
|
|
|
|
|
{
|
|
|
|
|
_GNULineLayoutInfo *ci = [lineLayoutInformation objectAtIndex: i];
|
|
|
|
|
|
|
|
|
|
range = [ci lineRange];
|
|
|
|
|
|
|
|
|
|
if (NSMaxRange(range) <= y)
|
|
|
|
|
{
|
|
|
|
|
min = i + 1;
|
|
|
|
|
i = (max + min) / 2;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (range.location > y)
|
|
|
|
|
{
|
|
|
|
|
max = i - 1;
|
|
|
|
|
i = (max + min) / 2;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// Do we need a special treatment for paragraph infos?
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
return min;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// rect to the end of line
|
|
|
|
|
- (NSRect) rectForCharacterIndex: (unsigned)index
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-04-23 22:31:25 +00:00
|
|
|
|
float maxWidth = [self frame].size.width;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_GNULineLayoutInfo *currentInfo;
|
2000-04-23 22:31:25 +00:00
|
|
|
|
unsigned start;
|
|
|
|
|
NSRect rect;
|
|
|
|
|
float x;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
if (![_textStorage length])
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
|
|
|
|
return NSMakeRect (0, 0, maxWidth,
|
|
|
|
|
[self _sizeOfRange: NSMakeRange(0,1)].height);
|
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (index >= NSMaxRange([[lineLayoutInformation lastObject] lineRange]))
|
|
|
|
|
{
|
|
|
|
|
NSRect rect = [[lineLayoutInformation lastObject] lineRect];
|
|
|
|
|
if (NSMaxX (rect) >= maxWidth)
|
|
|
|
|
{
|
|
|
|
|
return NSMakeRect (0, NSMaxY(rect),
|
|
|
|
|
maxWidth, rect.size.height);
|
|
|
|
|
}
|
|
|
|
|
return NSMakeRect (NSMaxX (rect), rect.origin.y,
|
|
|
|
|
maxWidth - NSMaxX (rect),
|
|
|
|
|
rect.size.height);
|
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
currentInfo = [lineLayoutInformation
|
|
|
|
|
objectAtIndex: [self lineLayoutIndexForCharacterIndex:
|
|
|
|
|
index]];
|
|
|
|
|
start = [currentInfo lineRange].location;
|
|
|
|
|
rect = [currentInfo lineRect];
|
|
|
|
|
x = rect.origin.x + [self _sizeOfRange: MakeRangeFromAbs(start,
|
|
|
|
|
index)].width;
|
|
|
|
|
|
|
|
|
|
return NSMakeRect (x, rect.origin.y, NSMaxX (rect) - x,
|
|
|
|
|
rect.size.height);
|
1998-09-02 15:05:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setNeedsDisplayForLineRange: (NSRange)redrawLineRange
|
|
|
|
|
{
|
2000-04-23 22:31:25 +00:00
|
|
|
|
NSRect myFrame = [self frame];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
float maxWidth = myFrame.size.width;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if ([lineLayoutInformation count]
|
|
|
|
|
&& redrawLineRange.location < [lineLayoutInformation count]
|
|
|
|
|
&& redrawLineRange.length)
|
|
|
|
|
{
|
|
|
|
|
_GNULineLayoutInfo *firstInfo
|
|
|
|
|
= [lineLayoutInformation objectAtIndex: redrawLineRange.location];
|
|
|
|
|
NSRect displayRect, firstRect = [firstInfo lineRect];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if ([firstInfo type] == LineLayoutInfoType_Paragraph
|
|
|
|
|
&& firstRect.origin.x >0 && redrawLineRange.location)
|
|
|
|
|
{
|
|
|
|
|
redrawLineRange.location--;
|
|
|
|
|
redrawLineRange.length++;
|
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
displayRect
|
|
|
|
|
= NSUnionRect ([[lineLayoutInformation
|
|
|
|
|
objectAtIndex: redrawLineRange.location]
|
|
|
|
|
lineRect],
|
|
|
|
|
[[lineLayoutInformation
|
|
|
|
|
objectAtIndex:
|
|
|
|
|
MAX (0, (int)NSMaxRange (redrawLineRange) - 1)]
|
|
|
|
|
lineRect]);
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
displayRect.size.width = maxWidth - displayRect.origin.x;
|
|
|
|
|
[_textHolder setNeedsDisplayInRect: displayRect];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// clean up the remaining area below the text
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
float lowestY = 0;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if ([lineLayoutInformation count])
|
|
|
|
|
lowestY = NSMaxY ([[lineLayoutInformation lastObject] lineRect]);
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (![lineLayoutInformation count]
|
|
|
|
|
|| (lowestY < NSMaxY(myFrame)))
|
|
|
|
|
{
|
|
|
|
|
[_textHolder setNeedsDisplayInRect: NSMakeRect(0, lowestY,
|
|
|
|
|
myFrame.size.width,
|
|
|
|
|
NSMaxY (myFrame) - lowestY)];
|
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-02 05:58:50 +00:00
|
|
|
|
- (void)textStorage:(NSTextStorage *)aTextStorage
|
|
|
|
|
edited:(unsigned int)mask
|
|
|
|
|
range:(NSRange)aRange
|
|
|
|
|
changeInLength:(int)delta
|
|
|
|
|
invalidatedRange:(NSRange)invalidatedCharRange;
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-04-23 22:31:25 +00:00
|
|
|
|
NSRange lineRange;
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
lineRange = [self rebuildForRange: aRange
|
|
|
|
|
delta: delta];
|
|
|
|
|
[self setNeedsDisplayForLineRange: lineRange];
|
1998-08-04 08:33:31 +00:00
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// internal method <!> range is currently not passed as absolute
|
|
|
|
|
- (void) addNewlines: (NSRange)aRange
|
|
|
|
|
intoLayoutArray: (NSMutableArray*)anArray
|
|
|
|
|
atPoint: (NSPoint*)aPointP
|
|
|
|
|
width: (float)width
|
|
|
|
|
characterIndex: (unsigned)startingLineCharIndex
|
|
|
|
|
ghostEnumerator: (_GNUSeekableArrayEnumerator*)prevArrayEnum
|
|
|
|
|
didShift: (BOOL*)didShift
|
|
|
|
|
verticalDisplacement: (float*)verticalDisplacement
|
|
|
|
|
{
|
|
|
|
|
NSSize advanceSize = [self _sizeOfRange:
|
|
|
|
|
NSMakeRange (startingLineCharIndex, 1)];
|
2000-04-23 22:31:25 +00:00
|
|
|
|
int count = aRange.length;
|
|
|
|
|
int charIndex;
|
|
|
|
|
_GNULineLayoutInfo *ghostInfo = nil;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
(*didShift) = NO;
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
for (charIndex = aRange.location; --count >= 0; charIndex++)
|
|
|
|
|
{
|
|
|
|
|
[anArray addObject:
|
2000-04-23 22:31:25 +00:00
|
|
|
|
[_GNULineLayoutInfo
|
|
|
|
|
lineLayoutWithRange:
|
|
|
|
|
NSMakeRange (startingLineCharIndex, 1)
|
|
|
|
|
rect: NSMakeRect (aPointP->x, aPointP->y,
|
|
|
|
|
width - aPointP->x, advanceSize.height)
|
|
|
|
|
type: LineLayoutInfoType_Paragraph]];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
|
|
|
|
startingLineCharIndex++;
|
2000-04-23 22:31:25 +00:00
|
|
|
|
aPointP->x = 0;
|
|
|
|
|
aPointP->y += advanceSize.height;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
|
|
|
|
if (prevArrayEnum && !(ghostInfo = [prevArrayEnum nextObject]))
|
|
|
|
|
prevArrayEnum = nil;
|
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
if (ghostInfo && ([ghostInfo type] != LineLayoutInfoType_Paragraph))
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_GNULineLayoutInfo *prevInfo = [prevArrayEnum previousObject];
|
|
|
|
|
prevArrayEnum = nil;
|
|
|
|
|
(*didShift) = YES;
|
|
|
|
|
(*verticalDisplacement) += aPointP ->y - [prevInfo lineRect].origin.y;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
1999-11-11 17:17:14 +00:00
|
|
|
|
}
|
1998-09-02 15:05:13 +00:00
|
|
|
|
}
|
1999-06-23 23:27:16 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// private helper function
|
2000-04-23 22:31:25 +00:00
|
|
|
|
- (unsigned) _relocLayoutArray: (NSArray*)ghostArray
|
|
|
|
|
atLine: (int) aLine
|
|
|
|
|
offset: (int) relocOffset
|
|
|
|
|
lineTrift: (int) rebuildLineDrift
|
|
|
|
|
floatTrift: (float) yReloc
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// lines actually updated (optimized drawing)
|
|
|
|
|
unsigned ret = [lineLayoutInformation count] - aLine;
|
|
|
|
|
NSArray *relocArray
|
|
|
|
|
= [ghostArray subarrayWithRange:
|
|
|
|
|
MakeRangeFromAbs (MAX (0, ret + rebuildLineDrift),
|
|
|
|
|
[ghostArray count])];
|
|
|
|
|
NSEnumerator *relocEnum;
|
|
|
|
|
_GNULineLayoutInfo *currReloc;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (![relocArray count])
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
for ((relocEnum = [relocArray objectEnumerator]);
|
|
|
|
|
(currReloc = [relocEnum nextObject]);)
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSRange range = [currReloc lineRange];
|
|
|
|
|
[currReloc setLineRange: NSMakeRange (range.location + relocOffset,
|
|
|
|
|
range.length)];
|
|
|
|
|
if (yReloc)
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSRect rect = [currReloc lineRect];
|
|
|
|
|
[currReloc setLineRect: NSMakeRect (rect.origin.x,
|
|
|
|
|
rect.origin.y + yReloc,
|
|
|
|
|
rect.size.width,
|
|
|
|
|
rect.size.height)];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
[lineLayoutInformation addObjectsFromArray: relocArray];
|
|
|
|
|
return ret;
|
1998-08-04 08:33:31 +00:00
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
/*
|
|
|
|
|
* A little utility function to determine the range of characters in a scanner
|
|
|
|
|
* that are present in a specified character set.
|
|
|
|
|
*/
|
|
|
|
|
static inline NSRange
|
|
|
|
|
scanRange(NSScanner *scanner, NSCharacterSet* aSet)
|
1998-08-04 08:33:31 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
unsigned start = [scanner scanLocation];
|
|
|
|
|
unsigned end = start;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if ([scanner scanCharactersFromSet: aSet intoString: 0] == YES)
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
end = [scanner scanLocation];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return NSMakeRange(start, end - start);
|
1998-08-04 08:33:31 +00:00
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// begin: central line formatting method---------------------------------------
|
|
|
|
|
// returns count of lines actually updated
|
|
|
|
|
// <!> detachNewThreadSelector: selector toTarget: target withObject: argument;
|
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
- (NSRange) rebuildForRange: (NSRange)aRange
|
|
|
|
|
delta: (int)insertionDelta
|
|
|
|
|
{
|
|
|
|
|
int aLine = 0;
|
|
|
|
|
int insertionLineIndex = 0;
|
2000-05-20 16:55:08 +00:00
|
|
|
|
//unsigned oldMax = NSMaxRange(aRange);
|
2000-05-04 22:44:20 +00:00
|
|
|
|
//unsigned newMax = oldMax + insertionDelta;
|
2000-04-23 22:31:25 +00:00
|
|
|
|
NSPoint drawingPoint = NSZeroPoint;
|
|
|
|
|
NSScanner *pScanner;
|
|
|
|
|
float width = [self frame].size.width;
|
|
|
|
|
unsigned startingIndex = 0;
|
|
|
|
|
unsigned currentLineIndex;
|
|
|
|
|
// for optimization detection
|
|
|
|
|
NSArray *ghostArray;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_GNUSeekableArrayEnumerator *prevArrayEnum;
|
|
|
|
|
NSString *parsedString;
|
|
|
|
|
int lineDriftOffset = 0, rebuildLineDrift = 0;
|
2000-04-23 22:31:25 +00:00
|
|
|
|
BOOL frameshiftCorrection = NO, nlDidShift = NO;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
float yDisplacement = 0;
|
|
|
|
|
|
|
|
|
|
// sanity check that it is possible to do the layout
|
|
|
|
|
if (width == 0.0)
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSLog(@"NSText formatting with empty frame");
|
2000-04-23 22:31:25 +00:00
|
|
|
|
return NSMakeRange(0,0);
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
if (lineLayoutInformation == nil)
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
lineLayoutInformation = [[NSMutableArray alloc] init];
|
|
|
|
|
aLine = 0;
|
|
|
|
|
ghostArray = nil;
|
|
|
|
|
prevArrayEnum = nil;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
2000-04-23 22:31:25 +00:00
|
|
|
|
insertionLineIndex = [self lineLayoutIndexForCharacterIndex:
|
|
|
|
|
aRange.location];
|
|
|
|
|
aLine = MAX(0, insertionLineIndex - 1);
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// remember old array for optimization purposes
|
|
|
|
|
ghostArray = [lineLayoutInformation
|
|
|
|
|
subarrayWithRange:
|
|
|
|
|
NSMakeRange (aLine, [lineLayoutInformation count] - aLine)];
|
|
|
|
|
// every time an object is added to lineLayoutInformation
|
|
|
|
|
// a nextObject has to be performed on prevArrayEnum!
|
|
|
|
|
prevArrayEnum = [ghostArray seekableEnumerator];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (aLine)
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-04-23 22:31:25 +00:00
|
|
|
|
_GNULineLayoutInfo *lastValidLineInfo = [lineLayoutInformation
|
|
|
|
|
objectAtIndex: aLine - 1];
|
|
|
|
|
NSRect aRect = [lastValidLineInfo lineRect];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
startingIndex = NSMaxRange([lastValidLineInfo lineRange]);
|
2000-04-23 22:31:25 +00:00
|
|
|
|
drawingPoint = aRect.origin;
|
|
|
|
|
drawingPoint.y += aRect.size.height;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if ([lastValidLineInfo type] == LineLayoutInfoType_Paragraph)
|
|
|
|
|
{
|
|
|
|
|
drawingPoint.x = 0;
|
|
|
|
|
}
|
2000-04-23 22:31:25 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// keep paragraph - terminating space on same line as paragraph
|
|
|
|
|
if ((((int)[lineLayoutInformation count]) - 1) >= aLine)
|
|
|
|
|
{
|
|
|
|
|
_GNULineLayoutInfo *anchorLine
|
|
|
|
|
= [lineLayoutInformation objectAtIndex: aLine];
|
|
|
|
|
NSRect anchorRect = [anchorLine lineRect];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (anchorRect.origin.x > drawingPoint.x
|
2000-04-23 22:31:25 +00:00
|
|
|
|
&& aRect.origin.y == anchorRect.origin.y)
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
|
|
|
|
drawingPoint = anchorRect.origin;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-11-11 17:17:14 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[lineLayoutInformation
|
|
|
|
|
removeObjectsInRange:
|
|
|
|
|
NSMakeRange (aLine, [lineLayoutInformation count] - aLine)];
|
1999-11-11 17:17:14 +00:00
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
if (![_textStorage length])
|
|
|
|
|
{
|
|
|
|
|
// If there is no text add one empty box
|
|
|
|
|
[lineLayoutInformation
|
|
|
|
|
addObject: [_GNULineLayoutInfo
|
|
|
|
|
lineLayoutWithRange: NSMakeRange (0, 0)
|
|
|
|
|
rect: NSMakeRect (0, 0, 0, 0)
|
|
|
|
|
type: LineLayoutInfoType_Text]];
|
|
|
|
|
return NSMakeRange(0,0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
currentLineIndex = aLine;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// each paragraph
|
|
|
|
|
parsedString = [[_textStorage string] substringFromIndex: startingIndex];
|
|
|
|
|
pScanner = [NSScanner scannerWithString: parsedString];
|
|
|
|
|
[pScanner setCharactersToBeSkipped: nil];
|
|
|
|
|
while ([pScanner isAtEnd] == NO)
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSScanner *lScanner;
|
|
|
|
|
NSString *paragraph;
|
|
|
|
|
NSRange paragraphRange, leadingNlRange, trailingNlRange;
|
|
|
|
|
unsigned currentLoc = [pScanner scanLocation];
|
|
|
|
|
unsigned startingParagraphIndex = currentLoc + startingIndex;
|
|
|
|
|
unsigned startingLineCharIndex = startingParagraphIndex;
|
|
|
|
|
BOOL isBuckled = NO, inBuckling = NO;
|
1998-10-15 12:04:53 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
leadingNlRange
|
|
|
|
|
= scanRange(pScanner, selectionParagraphGranularitySet);
|
|
|
|
|
if (leadingNlRange.length > 0)
|
|
|
|
|
{
|
|
|
|
|
[self addNewlines: leadingNlRange
|
|
|
|
|
intoLayoutArray: lineLayoutInformation
|
|
|
|
|
atPoint: &drawingPoint
|
|
|
|
|
width: width
|
|
|
|
|
characterIndex: startingLineCharIndex
|
|
|
|
|
ghostEnumerator: prevArrayEnum
|
|
|
|
|
didShift: &nlDidShift
|
|
|
|
|
verticalDisplacement: &yDisplacement];
|
2000-02-19 00:40:47 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (nlDidShift)
|
|
|
|
|
{
|
|
|
|
|
if (insertionDelta == 1)
|
|
|
|
|
{
|
|
|
|
|
frameshiftCorrection = YES;
|
|
|
|
|
rebuildLineDrift--;
|
|
|
|
|
}
|
|
|
|
|
else if (insertionDelta == - 1)
|
|
|
|
|
{
|
|
|
|
|
frameshiftCorrection = YES;
|
|
|
|
|
rebuildLineDrift++;
|
|
|
|
|
}
|
|
|
|
|
else nlDidShift = NO;
|
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
startingLineCharIndex += leadingNlRange.length;
|
|
|
|
|
currentLineIndex += leadingNlRange.length;
|
|
|
|
|
}
|
2000-02-19 00:40:47 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// each line
|
2000-04-23 22:31:25 +00:00
|
|
|
|
paragraphRange
|
|
|
|
|
= scanRange(pScanner, invSelectionParagraphGranularitySet);
|
2000-03-16 14:16:46 +00:00
|
|
|
|
paragraph = [parsedString substringWithRange: paragraphRange];
|
|
|
|
|
lScanner = [NSScanner scannerWithString: paragraph];
|
|
|
|
|
[lScanner setCharactersToBeSkipped: nil];
|
|
|
|
|
while ([lScanner isAtEnd] == NO)
|
|
|
|
|
{
|
|
|
|
|
NSRect currentLineRect = NSMakeRect (0, drawingPoint.y, 0, 0);
|
|
|
|
|
// starts with zero, do not confuse with startingLineCharIndex
|
|
|
|
|
unsigned localLineStartIndex = [lScanner scanLocation];
|
|
|
|
|
NSSize advanceSize = NSZeroSize;
|
2000-02-19 00:40:47 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// scan the individual words to the end of the line
|
|
|
|
|
for (; ![lScanner isAtEnd]; drawingPoint.x += advanceSize.width)
|
|
|
|
|
{
|
|
|
|
|
NSRange currentStringRange, trailingSpacesRange;
|
|
|
|
|
NSRange leadingSpacesRange;
|
|
|
|
|
unsigned scannerPosition = [lScanner scanLocation];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// snack next word
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// leading spaces: only first time
|
|
|
|
|
leadingSpacesRange
|
|
|
|
|
= scanRange(lScanner, selectionWordGranularitySet);
|
|
|
|
|
currentStringRange
|
|
|
|
|
= scanRange(lScanner, invSelectionWordGranularitySet);
|
|
|
|
|
trailingSpacesRange
|
|
|
|
|
= scanRange(lScanner, selectionWordGranularitySet);
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (leadingSpacesRange.length)
|
|
|
|
|
currentStringRange = NSUnionRange(leadingSpacesRange,
|
|
|
|
|
currentStringRange);
|
|
|
|
|
if (trailingSpacesRange.length)
|
|
|
|
|
currentStringRange = NSUnionRange(trailingSpacesRange,
|
|
|
|
|
currentStringRange);
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// evaluate size of current word and line so far
|
|
|
|
|
advanceSize = [self _sizeOfRange:
|
|
|
|
|
NSMakeRange (currentStringRange.location +
|
|
|
|
|
paragraphRange.location +
|
|
|
|
|
startingIndex,
|
|
|
|
|
currentStringRange.length)];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
currentLineRect = NSUnionRect (currentLineRect,
|
|
|
|
|
NSMakeRect (drawingPoint.x,
|
|
|
|
|
drawingPoint.y,
|
|
|
|
|
advanceSize.width,
|
|
|
|
|
advanceSize.height));
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// handle case where single word is broader than width
|
|
|
|
|
// (buckle word) <!> unfinished and untested
|
|
|
|
|
// for richText (absolute position see above)
|
2000-04-23 22:31:25 +00:00
|
|
|
|
if (advanceSize.width >= width)
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
|
|
|
|
if (isBuckled)
|
|
|
|
|
{
|
|
|
|
|
NSSize currentSize = NSMakeSize (HUGE, 0);
|
|
|
|
|
unsigned lastVisibleCharIndex;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
for (lastVisibleCharIndex
|
|
|
|
|
= startingLineCharIndex + currentStringRange.length;
|
|
|
|
|
currentSize.width>= width
|
|
|
|
|
&& lastVisibleCharIndex> startingLineCharIndex;
|
|
|
|
|
lastVisibleCharIndex--)
|
|
|
|
|
{
|
|
|
|
|
currentSize = [self _sizeOfRange:
|
|
|
|
|
MakeRangeFromAbs (startingLineCharIndex,
|
|
|
|
|
lastVisibleCharIndex)];
|
|
|
|
|
}
|
|
|
|
|
isBuckled = NO;
|
|
|
|
|
inBuckling = YES;
|
|
|
|
|
scannerPosition
|
|
|
|
|
= localLineStartIndex
|
|
|
|
|
+ (lastVisibleCharIndex - startingLineCharIndex);
|
|
|
|
|
currentLineRect.size.width = advanceSize.width = width;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// undo layout of extralarge word
|
|
|
|
|
// (will be done the next line [see above])
|
|
|
|
|
isBuckled = YES;
|
|
|
|
|
currentLineRect.size.width -= advanceSize.width;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// end of line -> word wrap
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// >= : wichtig f<EFBFBD>r abknicken (isBuckled)
|
2000-04-23 22:31:25 +00:00
|
|
|
|
if (currentLineRect.size.width >= width || isBuckled)
|
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_GNULineLayoutInfo *ghostInfo = nil, *thisInfo;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// undo layout of last word
|
|
|
|
|
[lScanner setScanLocation: scannerPosition];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
currentLineRect.origin.x = 0;
|
|
|
|
|
currentLineRect.origin.y = drawingPoint.y;
|
|
|
|
|
drawingPoint.y += currentLineRect.size.height;
|
|
|
|
|
drawingPoint.x = 0;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[lineLayoutInformation
|
|
|
|
|
addObject: (thisInfo
|
|
|
|
|
= [_GNULineLayoutInfo
|
|
|
|
|
lineLayoutWithRange:
|
|
|
|
|
NSMakeRange (startingLineCharIndex,
|
|
|
|
|
scannerPosition - localLineStartIndex)
|
|
|
|
|
rect: currentLineRect
|
|
|
|
|
type: LineLayoutInfoType_Text])];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
currentLineIndex++;
|
|
|
|
|
startingLineCharIndex = NSMaxRange([thisInfo lineRange]);
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (prevArrayEnum
|
|
|
|
|
&& !(ghostInfo = [prevArrayEnum nextObject]))
|
|
|
|
|
prevArrayEnum = nil;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// optimization stuff
|
|
|
|
|
// (do relayout only as much lines as necessary
|
|
|
|
|
// and patch the rest)---------
|
|
|
|
|
if (ghostInfo)
|
|
|
|
|
{
|
|
|
|
|
if ([ghostInfo type] != [thisInfo type])
|
|
|
|
|
{
|
|
|
|
|
// frameshift correction
|
|
|
|
|
frameshiftCorrection = YES;
|
|
|
|
|
if (insertionDelta == - 1)
|
|
|
|
|
{
|
|
|
|
|
// deletition of newline
|
|
|
|
|
_GNULineLayoutInfo *nextObject;
|
|
|
|
|
if (!(nextObject = [prevArrayEnum nextObject]))
|
|
|
|
|
prevArrayEnum = nil;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (nlDidShift && frameshiftCorrection)
|
|
|
|
|
{
|
|
|
|
|
// frameshiftCorrection = NO;
|
|
|
|
|
#if 0
|
|
|
|
|
NSLog(@"opti hook 1 (preferred)");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lineDriftOffset
|
|
|
|
|
+= ([thisInfo lineRange].length
|
|
|
|
|
- [ghostInfo lineRange].length
|
|
|
|
|
- [nextObject lineRange].length);
|
|
|
|
|
yDisplacement
|
|
|
|
|
+= [thisInfo lineRect].origin.y
|
|
|
|
|
- [nextObject lineRect].origin.y;
|
|
|
|
|
rebuildLineDrift++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
lineDriftOffset += ([thisInfo lineRange].length
|
|
|
|
|
- [ghostInfo lineRange].length);
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// is it possible to simply patch layout changes
|
|
|
|
|
// into layout array instead of doing a time
|
|
|
|
|
// consuming re - layout of the whole doc?
|
|
|
|
|
if ((currentLineIndex - 1 > insertionLineIndex
|
|
|
|
|
&& !inBuckling && !isBuckled)
|
|
|
|
|
&& (!(lineDriftOffset - insertionDelta)
|
2000-04-23 22:31:25 +00:00
|
|
|
|
|| (nlDidShift && !lineDriftOffset)))
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
2000-04-23 22:31:25 +00:00
|
|
|
|
unsigned erg = [self _relocLayoutArray: ghostArray
|
|
|
|
|
atLine: aLine
|
|
|
|
|
offset: insertionDelta
|
|
|
|
|
lineTrift: rebuildLineDrift
|
|
|
|
|
floatTrift: yDisplacement];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// y displacement: redisplay all remaining lines
|
|
|
|
|
if (frameshiftCorrection)
|
|
|
|
|
erg = [lineLayoutInformation count] - aLine;
|
|
|
|
|
else if (currentLineIndex - 1 == insertionLineIndex
|
|
|
|
|
&& ABS(insertionDelta) == 1)
|
|
|
|
|
{
|
|
|
|
|
// return 2: redisplay only this and previous line
|
|
|
|
|
erg = 2;
|
|
|
|
|
}
|
|
|
|
|
#if 0
|
|
|
|
|
NSLog(@"opti for: %d",erg);
|
|
|
|
|
#endif
|
2000-04-23 22:31:25 +00:00
|
|
|
|
return NSMakeRange(aLine, MAX(1, erg));
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// end: optimization stuff--------------------------
|
|
|
|
|
// -----------------------------------------------
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// newline - induced premature lineending: flush
|
|
|
|
|
}
|
|
|
|
|
else if ([lScanner isAtEnd])
|
|
|
|
|
{
|
|
|
|
|
_GNULineLayoutInfo *thisInfo;
|
|
|
|
|
scannerPosition = [lScanner scanLocation];
|
|
|
|
|
[lineLayoutInformation
|
|
|
|
|
addObject: (thisInfo
|
|
|
|
|
= [_GNULineLayoutInfo
|
|
|
|
|
lineLayoutWithRange:
|
|
|
|
|
NSMakeRange (startingLineCharIndex,
|
|
|
|
|
scannerPosition - localLineStartIndex)
|
|
|
|
|
rect: currentLineRect
|
|
|
|
|
type: LineLayoutInfoType_Text])];
|
|
|
|
|
currentLineIndex++;
|
|
|
|
|
startingLineCharIndex = NSMaxRange ([thisInfo lineRange]);
|
|
|
|
|
|
|
|
|
|
// check for optimization (lines after paragraph
|
|
|
|
|
// are unchanged and do not need redisplay/relayout)------
|
|
|
|
|
if (prevArrayEnum)
|
|
|
|
|
{
|
|
|
|
|
_GNULineLayoutInfo *ghostInfo = nil;
|
|
|
|
|
|
|
|
|
|
ghostInfo = [prevArrayEnum nextObject];
|
|
|
|
|
|
|
|
|
|
if (ghostInfo)
|
|
|
|
|
{
|
|
|
|
|
if ([ghostInfo type] != [thisInfo type])
|
|
|
|
|
{
|
|
|
|
|
// frameshift correction for inserted newline
|
|
|
|
|
frameshiftCorrection = YES;
|
|
|
|
|
|
|
|
|
|
if (insertionDelta == 1)
|
|
|
|
|
{
|
|
|
|
|
[prevArrayEnum previousObject];
|
|
|
|
|
lineDriftOffset
|
|
|
|
|
+= ([thisInfo lineRange].length
|
|
|
|
|
- [ghostInfo lineRange].length) + insertionDelta;
|
|
|
|
|
rebuildLineDrift--;
|
|
|
|
|
yDisplacement
|
|
|
|
|
+= [thisInfo lineRect].origin.y
|
|
|
|
|
- [ghostInfo lineRect].origin.y;
|
|
|
|
|
}
|
|
|
|
|
else if (insertionDelta == - 1)
|
|
|
|
|
{
|
|
|
|
|
if (nlDidShift && frameshiftCorrection)
|
|
|
|
|
{
|
|
|
|
|
// frameshiftCorrection = NO;
|
|
|
|
|
#if 0
|
|
|
|
|
NSLog(@"opti hook 2");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
lineDriftOffset
|
|
|
|
|
+= ([thisInfo lineRange].length
|
|
|
|
|
- [ghostInfo lineRange].length);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// new array obviously longer than the previous one
|
|
|
|
|
prevArrayEnum = nil;
|
|
|
|
|
}
|
|
|
|
|
// end: optimization stuff------------------------------
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// add the trailing newlines of current paragraph if any
|
2000-04-23 22:31:25 +00:00
|
|
|
|
trailingNlRange
|
|
|
|
|
= scanRange(pScanner, selectionParagraphGranularitySet);
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (trailingNlRange.length)
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[self addNewlines: trailingNlRange
|
|
|
|
|
intoLayoutArray: lineLayoutInformation
|
|
|
|
|
atPoint: &drawingPoint
|
|
|
|
|
width: width
|
|
|
|
|
characterIndex: startingLineCharIndex
|
|
|
|
|
ghostEnumerator: prevArrayEnum
|
|
|
|
|
didShift: &nlDidShift
|
|
|
|
|
verticalDisplacement: &yDisplacement];
|
|
|
|
|
if (nlDidShift)
|
|
|
|
|
{
|
|
|
|
|
if (insertionDelta == 1)
|
|
|
|
|
{
|
|
|
|
|
frameshiftCorrection = YES;
|
|
|
|
|
rebuildLineDrift--;
|
|
|
|
|
}
|
|
|
|
|
else if (insertionDelta == - 1)
|
|
|
|
|
{
|
|
|
|
|
frameshiftCorrection = YES;
|
|
|
|
|
rebuildLineDrift++;
|
|
|
|
|
}
|
|
|
|
|
else nlDidShift = NO;
|
|
|
|
|
}
|
|
|
|
|
currentLineIndex += trailingNlRange.length;
|
1998-09-02 15:05:13 +00:00
|
|
|
|
}
|
1999-11-11 17:17:14 +00:00
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// lines actually updated (optimized drawing)
|
2000-04-23 22:31:25 +00:00
|
|
|
|
return NSMakeRange(aLine, MAX(1, [lineLayoutInformation count] - aLine));
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// end: central line formatting method------------------------------------
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// relies on lineLayoutInformation
|
|
|
|
|
- (void) drawLinesInLineRange: (NSRange)aRange;
|
|
|
|
|
{
|
|
|
|
|
NSArray *linesToDraw = [lineLayoutInformation subarrayWithRange: aRange];
|
|
|
|
|
NSEnumerator *lineEnum;
|
|
|
|
|
_GNULineLayoutInfo *currentInfo;
|
|
|
|
|
|
|
|
|
|
for ((lineEnum = [linesToDraw objectEnumerator]);
|
|
|
|
|
(currentInfo = [lineEnum nextObject]);)
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if ([currentInfo type] == LineLayoutInfoType_Paragraph)
|
|
|
|
|
continue; // e.g. for nl
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[_textStorage drawRange: [currentInfo lineRange]
|
|
|
|
|
atPoint: [currentInfo lineRect].origin];
|
|
|
|
|
// <!> make this use drawRange: inRect: in the future
|
|
|
|
|
// (for proper adoption of layout information [e.g. centering])
|
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-19 07:33:26 +00:00
|
|
|
|
// Draws the lines in the given rectangle and hands back the drawn
|
|
|
|
|
// character range.
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (NSRange) drawRectCharacters: (NSRect)rect
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSRange aRange = [self lineRangeForRect: rect];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[self drawLinesInLineRange: aRange];
|
|
|
|
|
return [self characterRangeForLineLayoutRange: aRange];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (NSRange) lineRangeForRect: (NSRect)rect
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSPoint upperLeftPoint = rect.origin;
|
|
|
|
|
NSPoint lowerRightPoint = NSMakePoint (NSMaxX (rect), NSMaxY (rect));
|
|
|
|
|
unsigned startLine, endLine;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
startLine = [self lineLayoutIndexForPoint: upperLeftPoint];
|
|
|
|
|
endLine = [self lineLayoutIndexForPoint: lowerRightPoint];
|
|
|
|
|
if (++endLine > [lineLayoutInformation count])
|
|
|
|
|
endLine = [lineLayoutInformation count];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return NSMakeRange(startLine, endLine - startLine);
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// begin: NSText------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
@implementation NSText
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
|
|
|
|
//
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// Class methods
|
2000-03-08 08:43:15 +00:00
|
|
|
|
//
|
2000-03-16 14:16:46 +00:00
|
|
|
|
+ (void)initialize
|
|
|
|
|
{
|
|
|
|
|
if (self == [NSText class])
|
|
|
|
|
{
|
2000-05-23 22:58:24 +00:00
|
|
|
|
NSArray *types;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[self setVersion: 1]; // Initial version
|
|
|
|
|
|
|
|
|
|
[self setSelectionWordGranularitySet:
|
|
|
|
|
[NSCharacterSet whitespaceCharacterSet]];
|
|
|
|
|
[self setSelectionParagraphGranularitySet:
|
|
|
|
|
[NSCharacterSet characterSetWithCharactersInString:
|
|
|
|
|
[self newlineString]]];
|
2000-05-23 22:58:24 +00:00
|
|
|
|
types = [NSArray arrayWithObjects: NSStringPboardType, NSRTFPboardType, NSRTFDPboardType, nil];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-05-23 22:58:24 +00:00
|
|
|
|
[[NSApplication sharedApplication] registerServicesMenuSendTypes: types
|
|
|
|
|
returnTypes: types];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// Instance methods
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// Initialization
|
2000-03-08 08:43:15 +00:00
|
|
|
|
//
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
|
|
|
|
- (id) init
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return [self initWithFrame: NSMakeRect (0, 0, 100, 100)];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (id) initWithFrame: (NSRect)frameRect
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[super initWithFrame: frameRect];
|
|
|
|
|
|
|
|
|
|
[self setMinSize: frameRect.size];
|
|
|
|
|
[self setMaxSize: NSMakeSize(HUGE,HUGE)];
|
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
_tf.is_field_editor = NO;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_tf.is_editable = YES;
|
|
|
|
|
_tf.is_selectable = YES;
|
|
|
|
|
_tf.is_rich_text = NO;
|
2000-05-20 16:55:08 +00:00
|
|
|
|
_tf.imports_graphics = NO;
|
|
|
|
|
_tf.draws_background = NO;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_tf.is_horizontally_resizable = NO;
|
|
|
|
|
_tf.is_vertically_resizable = YES;
|
2000-05-20 16:55:08 +00:00
|
|
|
|
_tf.uses_font_panel = YES;
|
|
|
|
|
_tf.uses_ruler = YES;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_tf.is_ruler_visible = NO;
|
2000-05-13 14:28:02 +00:00
|
|
|
|
ASSIGN(_caret_color, [NSColor blackColor]);
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self setTypingAttributes: [[self class] defaultTypingAttributes]];
|
|
|
|
|
|
|
|
|
|
[self setBackgroundColor: [NSColor textBackgroundColor]];
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// sets up the contents object
|
2000-03-19 07:33:26 +00:00
|
|
|
|
[self setString: @""];
|
|
|
|
|
//[self setSelectedRange: NSMakeRange (0, 0)];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return self;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void)dealloc
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
RELEASE(_background_color);
|
2000-05-13 14:28:02 +00:00
|
|
|
|
RELEASE(_caret_color);
|
2000-03-16 14:16:46 +00:00
|
|
|
|
RELEASE(_textStorage);
|
2000-05-13 14:28:02 +00:00
|
|
|
|
RELEASE(_typingAttributes);
|
|
|
|
|
RELEASE(_layoutManager);
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[super dealloc];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
/*
|
|
|
|
|
* Getting and Setting Contents
|
|
|
|
|
*/
|
|
|
|
|
- (void) replaceCharactersInRange: (NSRange)aRange
|
|
|
|
|
withRTF: (NSData*)rtfData
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-05-04 22:44:20 +00:00
|
|
|
|
[self replaceRange: aRange
|
|
|
|
|
withAttributedString: AUTORELEASE([[NSAttributedString alloc]
|
|
|
|
|
initWithRTF: rtfData
|
|
|
|
|
documentAttributes: NULL])];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) replaceCharactersInRange: (NSRange)aRange
|
|
|
|
|
withRTFD: (NSData*)rtfdData
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[self replaceRange: aRange
|
|
|
|
|
withAttributedString: AUTORELEASE([[NSAttributedString alloc]
|
|
|
|
|
initWithRTFD: rtfdData
|
|
|
|
|
documentAttributes: NULL])];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) replaceCharactersInRange: (NSRange)aRange
|
|
|
|
|
withString: (NSString*)aString
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-06-26 19:55:01 +00:00
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
|
return;
|
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
2000-06-26 19:55:01 +00:00
|
|
|
|
replacementString: aString])
|
2000-05-20 16:55:08 +00:00
|
|
|
|
return;
|
2000-04-02 05:58:50 +00:00
|
|
|
|
[_textStorage beginEditing];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[_textStorage replaceCharactersInRange: aRange withString: aString];
|
2000-04-02 05:58:50 +00:00
|
|
|
|
[_textStorage endEditing];
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self didChangeText];
|
2000-04-23 22:31:25 +00:00
|
|
|
|
[self sizeToFit];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setString: (NSString*)aString
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
RELEASE(_textStorage);
|
2000-04-02 05:58:50 +00:00
|
|
|
|
_textStorage = [[NSTextStorage alloc]
|
2000-03-16 14:16:46 +00:00
|
|
|
|
initWithString: aString
|
2000-05-20 16:55:08 +00:00
|
|
|
|
attributes: [self typingAttributes]];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-03-19 07:33:26 +00:00
|
|
|
|
[self _buildUpLayout];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
[self sizeToFit];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[self setSelectedRangeNoDrawing: NSMakeRange (0, 0)];
|
|
|
|
|
[self setNeedsDisplay: YES];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (NSString*) string
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return [_textStorage string];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// old methods
|
|
|
|
|
- (void) replaceRange: (NSRange)aRange withRTFD: (NSData*)rtfdData
|
|
|
|
|
{
|
|
|
|
|
[self replaceCharactersInRange: aRange withRTFD: rtfdData];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) replaceRange: (NSRange)aRange withRTF: (NSData*)rtfData
|
|
|
|
|
{
|
|
|
|
|
[self replaceCharactersInRange: aRange withRTF: rtfData];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) replaceRange: (NSRange)aRange withString: (NSString*)aString
|
|
|
|
|
{
|
|
|
|
|
[self replaceCharactersInRange: aRange withString: aString];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setText: (NSString*)aString range: (NSRange)aRange
|
|
|
|
|
{
|
|
|
|
|
[self replaceCharactersInRange: aRange withString: aString];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setText: (NSString*)string
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[self setString: string];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (NSString*) text
|
|
|
|
|
{
|
|
|
|
|
return [self string];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
//
|
|
|
|
|
// Graphic attributes
|
|
|
|
|
//
|
|
|
|
|
- (NSColor*) backgroundColor
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return _background_color;
|
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (BOOL) drawsBackground
|
|
|
|
|
{
|
|
|
|
|
return _tf.draws_background;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setBackgroundColor: (NSColor*)color
|
|
|
|
|
{
|
|
|
|
|
ASSIGN(_background_color, color);
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void)setDrawsBackground: (BOOL)flag
|
|
|
|
|
{
|
|
|
|
|
_tf.draws_background = flag;
|
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
|
|
|
|
//
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// Managing Global Characteristics
|
|
|
|
|
//
|
|
|
|
|
- (BOOL) importsGraphics
|
|
|
|
|
{
|
|
|
|
|
return _tf.imports_graphics;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (BOOL) isEditable
|
|
|
|
|
{
|
|
|
|
|
return _tf.is_editable;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (BOOL) isFieldEditor
|
|
|
|
|
{
|
|
|
|
|
return _tf.is_field_editor;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (BOOL) isRichText
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return _tf.is_rich_text;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (BOOL) isSelectable
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return _tf.is_selectable;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void)setEditable: (BOOL)flag
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_tf.is_editable = flag;
|
2000-05-04 22:44:20 +00:00
|
|
|
|
// If we are editable then we are selectable
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (flag)
|
2000-03-19 07:33:26 +00:00
|
|
|
|
{
|
|
|
|
|
_tf.is_selectable = YES;
|
|
|
|
|
// FIXME: We should show the insertion point
|
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setFieldEditor: (BOOL)flag
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_tf.is_field_editor = flag;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void)setImportsGraphics: (BOOL)flag
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (flag)
|
|
|
|
|
_tf.is_rich_text = flag;
|
2000-06-26 19:55:01 +00:00
|
|
|
|
// FIXME: When switched off remove attachments
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_tf.imports_graphics = flag;
|
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setRichText: (BOOL)flag
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_tf.is_rich_text = flag;
|
|
|
|
|
if (!flag)
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
_tf.imports_graphics = flag;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[self setString: [self string]];
|
1999-11-11 17:17:14 +00:00
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setSelectable: (BOOL)flag
|
|
|
|
|
{
|
|
|
|
|
_tf.is_selectable = flag;
|
|
|
|
|
// If we are not selectable then we must not be editable
|
|
|
|
|
if (!flag)
|
|
|
|
|
_tf.is_editable = NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Using the font panel
|
|
|
|
|
//
|
|
|
|
|
- (BOOL) usesFontPanel
|
|
|
|
|
{
|
|
|
|
|
return _tf.uses_font_panel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setUsesFontPanel: (BOOL)flag
|
|
|
|
|
{
|
|
|
|
|
_tf.uses_font_panel = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Managing the Ruler
|
|
|
|
|
//
|
|
|
|
|
- (BOOL) isRulerVisible
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-05-04 22:44:20 +00:00
|
|
|
|
return _tf.is_ruler_visible;
|
1999-06-22 23:37:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) toggleRuler: (id)sender
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self setRulerVisible: !_tf.is_ruler_visible];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Managing the Selection
|
|
|
|
|
//
|
|
|
|
|
- (NSRange)selectedRange
|
|
|
|
|
{
|
|
|
|
|
return _selected_range;
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
1998-10-15 12:04:53 +00:00
|
|
|
|
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setSelectedRange: (NSRange)range
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
BOOL didLock = NO;
|
|
|
|
|
|
|
|
|
|
if (!_window)
|
|
|
|
|
return;
|
|
|
|
|
|
2000-03-19 07:33:26 +00:00
|
|
|
|
if ([[self class] focusView] != self)
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[self lockFocus];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
didLock = YES;
|
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
|
|
|
|
if (_selected_range.length == 0) // remove old cursor
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[self drawInsertionPointAtIndex: _selected_range.location
|
|
|
|
|
color: nil turnedOn: NO];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
else
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// This does an unhighlight of the old selected region
|
|
|
|
|
[self drawSelectionAsRange: _selected_range];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self setSelectedRangeNoDrawing: range];
|
|
|
|
|
|
|
|
|
|
// display
|
|
|
|
|
if (range.length)
|
|
|
|
|
{
|
|
|
|
|
// <!>disable caret timed entry
|
|
|
|
|
}
|
|
|
|
|
else // no selection
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (_tf.is_rich_text)
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self setTypingAttributes: [_textStorage attributesAtIndex: range.location
|
|
|
|
|
effectiveRange: NULL]];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// <!>enable caret timed entry
|
|
|
|
|
}
|
|
|
|
|
[self drawSelectionAsRange: range];
|
|
|
|
|
[self scrollRangeToVisible: range];
|
|
|
|
|
|
2000-03-08 08:43:15 +00:00
|
|
|
|
if (didLock)
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-03-08 08:43:15 +00:00
|
|
|
|
[self unlockFocus];
|
1999-11-11 17:17:14 +00:00
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
1999-11-11 17:17:14 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copy and paste
|
|
|
|
|
*/
|
|
|
|
|
- (void) copy: (id)sender
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-05-23 22:58:24 +00:00
|
|
|
|
NSMutableArray *types = [NSMutableArray array];
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (_tf.imports_graphics)
|
|
|
|
|
[types addObject: NSRTFDPboardType];
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (_tf.is_rich_text)
|
2000-05-23 22:58:24 +00:00
|
|
|
|
[types addObject: NSRTFPboardType];
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
2000-05-23 22:58:24 +00:00
|
|
|
|
[types addObject: NSStringPboardType];
|
|
|
|
|
|
|
|
|
|
[self writeSelectionToPasteboard: [NSPasteboard generalPasteboard]
|
|
|
|
|
types: types];
|
1998-09-02 15:05:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// Copy the current font to the font pasteboard
|
|
|
|
|
- (void) copyFont: (id)sender
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-05-23 22:58:24 +00:00
|
|
|
|
[self writeSelectionToPasteboard: [NSPasteboard pasteboardWithName: NSFontPboard]
|
|
|
|
|
type: NSFontPboardType];
|
1998-09-02 15:05:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// Copy the current ruler settings to the ruler pasteboard
|
|
|
|
|
- (void) copyRuler: (id)sender
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-05-23 22:58:24 +00:00
|
|
|
|
[self writeSelectionToPasteboard: [NSPasteboard pasteboardWithName: NSRulerPboard]
|
|
|
|
|
type: NSRulerPboardType];
|
1999-02-10 15:09:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) delete: (id)sender
|
1999-08-22 04:04:38 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[self deleteRange: _selected_range backspace: NO];
|
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) cut: (id)sender
|
|
|
|
|
{
|
|
|
|
|
if (_selected_range.length)
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[self copy: sender];
|
|
|
|
|
[self delete: sender];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
1998-08-20 09:56:26 +00:00
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) paste: (id)sender
|
|
|
|
|
{
|
2000-05-23 22:58:24 +00:00
|
|
|
|
[self readSelectionFromPasteboard: [NSPasteboard generalPasteboard]];
|
1999-08-31 09:19:39 +00:00
|
|
|
|
}
|
1999-02-17 09:13:43 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) pasteFont: (id)sender
|
1999-02-17 09:13:43 +00:00
|
|
|
|
{
|
2000-05-23 22:58:24 +00:00
|
|
|
|
[self readSelectionFromPasteboard:
|
|
|
|
|
[NSPasteboard pasteboardWithName: NSFontPboard]
|
|
|
|
|
type: NSFontPboardType];
|
1998-08-20 09:56:26 +00:00
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) pasteRuler: (id)sender
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-05-23 22:58:24 +00:00
|
|
|
|
[self readSelectionFromPasteboard:
|
|
|
|
|
[NSPasteboard pasteboardWithName: NSRulerPboard]
|
|
|
|
|
type: NSRulerPboardType];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) selectAll: (id)sender
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[self setSelectedRange: NSMakeRange(0,[self textLength])];
|
1999-11-11 17:17:14 +00:00
|
|
|
|
}
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
/*
|
2000-05-20 16:55:08 +00:00
|
|
|
|
* Managing Font
|
2000-03-16 14:16:46 +00:00
|
|
|
|
*/
|
|
|
|
|
- (NSFont*) font
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if ([_textStorage length])
|
|
|
|
|
{
|
|
|
|
|
NSFont *font = [_textStorage attribute: NSFontAttributeName
|
|
|
|
|
atIndex: 0
|
|
|
|
|
effectiveRange: NULL];
|
|
|
|
|
if (font != nil)
|
|
|
|
|
return font;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [_typingAttributes objectForKey: NSFontAttributeName];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
/*
|
|
|
|
|
* This action method changes the font of the selection for a rich text object,
|
|
|
|
|
* or of all text for a plain text object. If the receiver doesn't use the Font
|
|
|
|
|
* Panel, however, this method does nothing.
|
|
|
|
|
*/
|
|
|
|
|
- (void) changeFont: (id)sender
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
NSRange foundRange;
|
|
|
|
|
int maxSelRange;
|
|
|
|
|
NSRange aRange= [self rangeForUserCharacterAttributeChange];
|
|
|
|
|
NSRange searchRange = aRange;
|
2000-06-26 19:55:01 +00:00
|
|
|
|
NSFont *font;
|
2000-05-20 16:55:08 +00:00
|
|
|
|
|
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
|
replacementString: nil])
|
|
|
|
|
return;
|
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
|
for (maxSelRange = NSMaxRange(aRange);
|
|
|
|
|
searchRange.location < maxSelRange;
|
|
|
|
|
searchRange = NSMakeRange (NSMaxRange (foundRange),
|
|
|
|
|
maxSelRange - NSMaxRange(foundRange)))
|
|
|
|
|
{
|
2000-06-26 19:55:01 +00:00
|
|
|
|
font = [_textStorage attribute: NSFontAttributeName
|
|
|
|
|
atIndex: searchRange.location
|
|
|
|
|
longestEffectiveRange: &foundRange
|
|
|
|
|
inRange: searchRange];
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (font != nil)
|
|
|
|
|
{
|
|
|
|
|
[self setFont: [sender convertFont: font]
|
|
|
|
|
ofRange: foundRange];
|
|
|
|
|
}
|
1999-11-11 17:17:14 +00:00
|
|
|
|
}
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[_textStorage endEditing];
|
|
|
|
|
[self didChangeText];
|
2000-06-26 19:55:01 +00:00
|
|
|
|
// Set typing attributes
|
|
|
|
|
font = [_typingAttributes objectForKey: NSFontAttributeName];
|
|
|
|
|
if (font != nil)
|
|
|
|
|
{
|
|
|
|
|
[_typingAttributes setObject: [sender convertFont: font]
|
|
|
|
|
forKey: NSFontAttributeName];
|
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setFont: (NSFont*)font
|
|
|
|
|
{
|
2000-04-02 05:58:50 +00:00
|
|
|
|
NSRange fullRange = NSMakeRange(0, [_textStorage length]);
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self setFont: font ofRange: fullRange];
|
|
|
|
|
[_typingAttributes setObject: font forKey: NSFontAttributeName];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setFont: (NSFont*)font
|
|
|
|
|
ofRange: (NSRange)aRange
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (font != nil)
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
|
replacementString: nil])
|
|
|
|
|
return;
|
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
|
[_textStorage addAttribute: NSFontAttributeName
|
|
|
|
|
value: font
|
|
|
|
|
range: aRange];
|
|
|
|
|
[_textStorage endEditing];
|
|
|
|
|
[self didChangeText];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
1998-10-15 12:04:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
/*
|
|
|
|
|
* Managing Alingment
|
|
|
|
|
*/
|
|
|
|
|
- (NSTextAlignment) alignment
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
NSRange aRange = [self rangeForUserParagraphAttributeChange];
|
|
|
|
|
NSParagraphStyle *aStyle;
|
|
|
|
|
|
|
|
|
|
if (aRange.location != NSNotFound)
|
|
|
|
|
{
|
|
|
|
|
aStyle = [_textStorage attribute: NSParagraphStyleAttributeName
|
|
|
|
|
atIndex: aRange.location
|
|
|
|
|
effectiveRange: NULL];
|
|
|
|
|
if (aStyle != nil)
|
|
|
|
|
return [aStyle alignment];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get alignment from typing attributes
|
|
|
|
|
return [[[self typingAttributes]
|
|
|
|
|
objectForKey: NSParagraphStyleAttributeName] alignment];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setAlignment: (NSTextAlignment) mode
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self setAlignment: mode
|
|
|
|
|
range: NSMakeRange(0, [_textStorage length])];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) alignCenter: (id) sender
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self setAlignment: NSCenterTextAlignment
|
|
|
|
|
range: [self rangeForUserParagraphAttributeChange]];
|
1998-10-15 12:04:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) alignLeft: (id) sender
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self setAlignment: NSLeftTextAlignment
|
|
|
|
|
range: [self rangeForUserParagraphAttributeChange]];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) alignRight: (id) sender
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self setAlignment: NSRightTextAlignment
|
|
|
|
|
range: [self rangeForUserParagraphAttributeChange]];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
/*
|
|
|
|
|
* Text colour
|
|
|
|
|
*/
|
2000-05-20 16:55:08 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (NSColor*) textColor
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
|
|
|
|
|
|
|
|
|
if (aRange.location != NSNotFound)
|
|
|
|
|
return [_textStorage attribute: NSForegroundColorAttributeName
|
|
|
|
|
atIndex: aRange.location
|
|
|
|
|
effectiveRange: NULL];
|
|
|
|
|
else
|
|
|
|
|
return [_typingAttributes objectForKey: NSForegroundColorAttributeName];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
1998-10-15 12:04:53 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setTextColor: (NSColor*) color
|
|
|
|
|
range: (NSRange) aRange
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
|
replacementString: nil])
|
|
|
|
|
return;
|
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
|
if (color != nil)
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[_textStorage addAttribute: NSForegroundColorAttributeName
|
|
|
|
|
value: color
|
|
|
|
|
range: aRange];
|
|
|
|
|
[_typingAttributes setObject: color forKey: NSForegroundColorAttributeName];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
2000-05-20 16:55:08 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[_textStorage removeAttribute: NSForegroundColorAttributeName
|
|
|
|
|
range: aRange];
|
|
|
|
|
}
|
|
|
|
|
[_textStorage endEditing];
|
|
|
|
|
[self didChangeText];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setColor: (NSColor*) color
|
|
|
|
|
ofRange: (NSRange) aRange
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[self setTextColor: color range: aRange];
|
|
|
|
|
}
|
1999-11-11 17:17:14 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) setTextColor: (NSColor*) color
|
|
|
|
|
{
|
2000-04-02 05:58:50 +00:00
|
|
|
|
NSRange fullRange = NSMakeRange(0, [_textStorage length]);
|
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self setTextColor: color range: fullRange];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Text attributes
|
|
|
|
|
//
|
|
|
|
|
- (void) subscript: (id)sender
|
|
|
|
|
{
|
2000-06-26 19:55:01 +00:00
|
|
|
|
NSNumber *value = [_typingAttributes
|
|
|
|
|
objectForKey: NSSuperscriptAttributeName];
|
|
|
|
|
int sValue;
|
2000-05-20 16:55:08 +00:00
|
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
2000-04-02 05:58:50 +00:00
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
|
return;
|
2000-04-02 05:58:50 +00:00
|
|
|
|
|
|
|
|
|
if (aRange.length)
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
|
replacementString: nil])
|
|
|
|
|
return;
|
2000-04-02 05:58:50 +00:00
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
|
[_textStorage subscriptRange: aRange];
|
|
|
|
|
[_textStorage endEditing];
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self didChangeText];
|
2000-04-02 05:58:50 +00:00
|
|
|
|
}
|
2000-06-26 19:55:01 +00:00
|
|
|
|
|
|
|
|
|
// Set the typing attributes
|
|
|
|
|
if (value != nil)
|
|
|
|
|
sValue = [value intValue] - 1;
|
2000-04-02 05:58:50 +00:00
|
|
|
|
else
|
2000-06-26 19:55:01 +00:00
|
|
|
|
sValue = -1;
|
|
|
|
|
[_typingAttributes setObject: [NSNumber numberWithInt: sValue]
|
|
|
|
|
forKey: NSSuperscriptAttributeName];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) superscript: (id)sender
|
|
|
|
|
{
|
2000-06-26 19:55:01 +00:00
|
|
|
|
NSNumber *value = [_typingAttributes
|
|
|
|
|
objectForKey: NSSuperscriptAttributeName];
|
|
|
|
|
int sValue;
|
2000-05-20 16:55:08 +00:00
|
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
2000-04-02 05:58:50 +00:00
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
|
return;
|
2000-04-02 05:58:50 +00:00
|
|
|
|
|
|
|
|
|
if (aRange.length)
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
|
replacementString: nil])
|
|
|
|
|
return;
|
2000-04-02 05:58:50 +00:00
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
|
[_textStorage superscriptRange: aRange];
|
|
|
|
|
[_textStorage endEditing];
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self didChangeText];
|
2000-04-02 05:58:50 +00:00
|
|
|
|
}
|
2000-06-26 19:55:01 +00:00
|
|
|
|
|
|
|
|
|
// Set the typing attributes
|
|
|
|
|
if (value != nil)
|
|
|
|
|
sValue = [value intValue] + 1;
|
2000-04-02 05:58:50 +00:00
|
|
|
|
else
|
2000-06-26 19:55:01 +00:00
|
|
|
|
sValue = 1;
|
|
|
|
|
[_typingAttributes setObject: [NSNumber numberWithInt: sValue]
|
|
|
|
|
forKey: NSSuperscriptAttributeName];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) unscript: (id)sender
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
2000-04-02 05:58:50 +00:00
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
|
return;
|
2000-04-02 05:58:50 +00:00
|
|
|
|
|
|
|
|
|
if (aRange.length)
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
|
replacementString: nil])
|
|
|
|
|
return;
|
2000-04-02 05:58:50 +00:00
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
|
[_textStorage unscriptRange: aRange];
|
|
|
|
|
[_textStorage endEditing];
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self didChangeText];
|
2000-04-02 05:58:50 +00:00
|
|
|
|
}
|
2000-06-26 19:55:01 +00:00
|
|
|
|
|
|
|
|
|
// Set the typing attributes
|
|
|
|
|
[_typingAttributes removeObjectForKey: NSSuperscriptAttributeName];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) underline: (id)sender
|
|
|
|
|
{
|
2000-04-02 05:58:50 +00:00
|
|
|
|
BOOL doUnderline = YES;
|
2000-05-20 16:55:08 +00:00
|
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
|
return;
|
2000-04-02 05:58:50 +00:00
|
|
|
|
|
|
|
|
|
if ([[_textStorage attribute: NSUnderlineStyleAttributeName
|
|
|
|
|
atIndex: aRange.location
|
|
|
|
|
effectiveRange: NULL] intValue])
|
|
|
|
|
doUnderline = NO;
|
|
|
|
|
|
|
|
|
|
if (aRange.length)
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
|
replacementString: nil])
|
|
|
|
|
return;
|
2000-04-02 05:58:50 +00:00
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
|
[_textStorage addAttribute: NSUnderlineStyleAttributeName
|
|
|
|
|
value: [NSNumber numberWithInt: doUnderline]
|
|
|
|
|
range: aRange];
|
|
|
|
|
[_textStorage endEditing];
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self didChangeText];
|
1999-11-11 17:17:14 +00:00
|
|
|
|
}
|
2000-06-26 19:55:01 +00:00
|
|
|
|
|
|
|
|
|
[_typingAttributes
|
2000-04-02 05:58:50 +00:00
|
|
|
|
setObject: [NSNumber numberWithInt: doUnderline]
|
|
|
|
|
forKey: NSUnderlineStyleAttributeName];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
//
|
|
|
|
|
// Reading and Writing RTFD Files
|
|
|
|
|
//
|
|
|
|
|
- (BOOL) readRTFDFromFile: (NSString*)path
|
|
|
|
|
{
|
2000-05-04 22:44:20 +00:00
|
|
|
|
NSAttributedString *peek = [[NSAttributedString alloc]
|
|
|
|
|
initWithPath: path
|
|
|
|
|
documentAttributes: NULL];
|
2000-02-19 00:40:47 +00:00
|
|
|
|
|
2000-05-04 22:44:20 +00:00
|
|
|
|
if (peek != nil)
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (!_tf.is_rich_text)
|
|
|
|
|
{
|
2000-05-23 22:58:24 +00:00
|
|
|
|
[self setRichText: YES];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
[self replaceRange: NSMakeRange (0, [self textLength])
|
|
|
|
|
withAttributedString: peek];
|
2000-05-04 22:44:20 +00:00
|
|
|
|
RELEASE(peek);
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
2000-02-19 00:40:47 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (BOOL) writeRTFDToFile: (NSString*)path atomically: (BOOL)flag
|
|
|
|
|
{
|
|
|
|
|
NSFileWrapper *wrapper = [_textStorage RTFDFileWrapperFromRange:
|
|
|
|
|
NSMakeRange(0, [_textStorage length])
|
|
|
|
|
documentAttributes: nil];
|
|
|
|
|
return [wrapper writeToFile: path atomically: flag updateFilenames: YES];
|
|
|
|
|
}
|
2000-02-19 00:40:47 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (NSData*) RTFDFromRange: (NSRange) aRange
|
|
|
|
|
{
|
|
|
|
|
return [_textStorage RTFDFromRange: aRange
|
|
|
|
|
documentAttributes: nil];
|
|
|
|
|
}
|
2000-02-19 00:40:47 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (NSData*) RTFFromRange: (NSRange) aRange
|
|
|
|
|
{
|
2000-05-04 22:44:20 +00:00
|
|
|
|
return [_textStorage RTFFromRange: aRange
|
|
|
|
|
documentAttributes: nil];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
2000-02-19 00:40:47 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
//
|
|
|
|
|
// Sizing the Frame Rectangle
|
|
|
|
|
//
|
|
|
|
|
- (BOOL) isHorizontallyResizable
|
|
|
|
|
{
|
|
|
|
|
return _tf.is_horizontally_resizable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) isVerticallyResizable
|
|
|
|
|
{
|
|
|
|
|
return _tf.is_vertically_resizable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSSize) maxSize
|
|
|
|
|
{
|
|
|
|
|
return _maxSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSSize) minSize
|
|
|
|
|
{
|
|
|
|
|
return _minSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setHorizontallyResizable: (BOOL)flag
|
|
|
|
|
{
|
|
|
|
|
_tf.is_horizontally_resizable = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setMaxSize: (NSSize)newMaxSize
|
|
|
|
|
{
|
|
|
|
|
_maxSize = newMaxSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setMinSize: (NSSize)newMinSize
|
|
|
|
|
{
|
|
|
|
|
_minSize = newMinSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setVerticallyResizable: (BOOL)flag
|
|
|
|
|
{
|
|
|
|
|
_tf.is_vertically_resizable = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) sizeToFit
|
|
|
|
|
{
|
|
|
|
|
// if we are a field editor we don't have to handle the size.
|
|
|
|
|
if ([self isFieldEditor])
|
|
|
|
|
return;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSSize oldSize = _frame.size;
|
|
|
|
|
float newWidth = oldSize.width;
|
|
|
|
|
float newHeight = oldSize.height;
|
|
|
|
|
NSRect textRect = [self _textBounds];
|
|
|
|
|
NSSize newSize;
|
|
|
|
|
|
|
|
|
|
if (_tf.is_horizontally_resizable)
|
|
|
|
|
{
|
|
|
|
|
newWidth = textRect.size.width;
|
|
|
|
|
}
|
|
|
|
|
else if (_tf.is_vertically_resizable)
|
|
|
|
|
{
|
|
|
|
|
newHeight = textRect.size.height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newSize = NSMakeSize(MIN(_maxSize.width, MAX(newWidth, _minSize.width)),
|
|
|
|
|
MIN(_maxSize.height, MAX(newHeight, _minSize.height)));
|
|
|
|
|
if (!NSEqualSizes(oldSize, newSize))
|
|
|
|
|
{
|
|
|
|
|
[self setFrameSize: newSize];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Spelling
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
- (void) checkSpelling: (id)sender
|
|
|
|
|
{
|
|
|
|
|
NSRange errorRange
|
|
|
|
|
= [[NSSpellChecker sharedSpellChecker]
|
|
|
|
|
checkSpellingOfString: [self string]
|
|
|
|
|
startingAt: NSMaxRange (_selected_range)];
|
|
|
|
|
|
|
|
|
|
if (errorRange.length)
|
|
|
|
|
[self setSelectedRange: errorRange];
|
|
|
|
|
else
|
|
|
|
|
NSBeep();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) showGuessPanel: (id)sender
|
|
|
|
|
{
|
|
|
|
|
[[[NSSpellChecker sharedSpellChecker] spellingPanel] orderFront: self];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Scrolling
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
- (void) scrollRangeToVisible: (NSRange) aRange
|
|
|
|
|
{
|
2000-06-16 19:03:15 +00:00
|
|
|
|
// Don't try scrolling an ancestor clipview if we are field editor.
|
|
|
|
|
// This makes things so much simpler and stabler for now.
|
|
|
|
|
if (_tf.is_field_editor == NO)
|
|
|
|
|
{
|
|
|
|
|
[self scrollRectToVisible:
|
|
|
|
|
NSUnionRect ([self rectForCharacterIndex:
|
|
|
|
|
_selected_range.location],
|
|
|
|
|
[self rectForCharacterIndex:
|
|
|
|
|
NSMaxRange (_selected_range)])];
|
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-16 19:03:15 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
/*
|
|
|
|
|
* Managing the Delegate
|
|
|
|
|
*/
|
|
|
|
|
- (id) delegate
|
|
|
|
|
{
|
|
|
|
|
return _delegate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setDelegate: (id) anObject
|
|
|
|
|
{
|
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
|
|
|
|
|
|
|
|
|
if (_delegate)
|
|
|
|
|
[nc removeObserver: _delegate name: nil object: self];
|
|
|
|
|
ASSIGN(_delegate, anObject);
|
|
|
|
|
|
|
|
|
|
#define SET_DELEGATE_NOTIFICATION(notif_name) \
|
|
|
|
|
if ([_delegate respondsToSelector: @selector(text##notif_name:)]) \
|
|
|
|
|
[nc addObserver: _delegate \
|
|
|
|
|
selector: @selector(text##notif_name:) \
|
|
|
|
|
name: NSText##notif_name##Notification \
|
|
|
|
|
object: self]
|
|
|
|
|
|
|
|
|
|
SET_DELEGATE_NOTIFICATION(DidBeginEditing);
|
|
|
|
|
SET_DELEGATE_NOTIFICATION(DidChange);
|
|
|
|
|
SET_DELEGATE_NOTIFICATION(DidEndEditing);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Handling Events
|
|
|
|
|
//
|
|
|
|
|
- (void) mouseDown: (NSEvent*)theEvent
|
|
|
|
|
{
|
|
|
|
|
NSSelectionGranularity granularity = NSSelectByCharacter;
|
|
|
|
|
NSRange chosenRange, prevChosenRange, proposedRange;
|
|
|
|
|
NSPoint point, startPoint;
|
|
|
|
|
NSEvent *currentEvent;
|
|
|
|
|
unsigned startIndex;
|
|
|
|
|
BOOL didDragging = NO;
|
|
|
|
|
|
|
|
|
|
// If not selectable then don't recognize the mouse down
|
|
|
|
|
if (!_tf.is_selectable)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (![_window makeFirstResponder: self])
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch ([theEvent clickCount])
|
|
|
|
|
{
|
|
|
|
|
case 1: granularity = NSSelectByCharacter;
|
|
|
|
|
break;
|
|
|
|
|
case 2: granularity = NSSelectByWord;
|
|
|
|
|
break;
|
|
|
|
|
case 3: granularity = NSSelectByParagraph;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
startPoint = [self convertPoint: [theEvent locationInWindow] fromView: nil];
|
|
|
|
|
startIndex = [self characterIndexForPoint: startPoint];
|
|
|
|
|
|
|
|
|
|
proposedRange = NSMakeRange (startIndex, 0);
|
|
|
|
|
chosenRange = prevChosenRange = [self selectionRangeForProposedRange:
|
|
|
|
|
proposedRange
|
|
|
|
|
granularity: granularity];
|
|
|
|
|
|
|
|
|
|
[self lockFocus];
|
|
|
|
|
|
|
|
|
|
// clean up before doing the dragging
|
|
|
|
|
if (_selected_range.length == 0) // remove old cursor
|
|
|
|
|
{
|
|
|
|
|
[self drawInsertionPointAtIndex: _selected_range.location
|
|
|
|
|
color: nil turnedOn: NO];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
[self drawSelectionAsRangeNoCaret: _selected_range];
|
|
|
|
|
|
|
|
|
|
//<!> make this non - blocking (or make use of timed entries)
|
|
|
|
|
for (currentEvent = [_window
|
|
|
|
|
nextEventMatchingMask:
|
|
|
|
|
(NSLeftMouseDraggedMask|NSLeftMouseUpMask)];
|
|
|
|
|
[currentEvent type] != NSLeftMouseUp;
|
|
|
|
|
(currentEvent = [_window
|
|
|
|
|
nextEventMatchingMask:
|
|
|
|
|
(NSLeftMouseDraggedMask|NSLeftMouseUpMask)]),
|
|
|
|
|
prevChosenRange = chosenRange) // run modal loop
|
|
|
|
|
{
|
|
|
|
|
BOOL didScroll = [self autoscroll: currentEvent];
|
|
|
|
|
point = [self convertPoint: [currentEvent locationInWindow]
|
|
|
|
|
fromView: nil];
|
|
|
|
|
proposedRange = MakeRangeFromAbs ([self characterIndexForPoint: point],
|
|
|
|
|
startIndex);
|
|
|
|
|
chosenRange = [self selectionRangeForProposedRange: proposedRange
|
|
|
|
|
granularity: granularity];
|
|
|
|
|
|
|
|
|
|
if (NSEqualRanges (prevChosenRange, chosenRange))
|
|
|
|
|
{
|
|
|
|
|
if (!didDragging)
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[self drawSelectionAsRangeNoCaret: chosenRange];
|
|
|
|
|
[_window flushWindow];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// this changes the selection without needing instance drawing
|
|
|
|
|
// (carefully thought out ; - )
|
|
|
|
|
if (!didScroll)
|
|
|
|
|
{
|
|
|
|
|
[self drawSelectionAsRangeNoCaret:
|
|
|
|
|
MakeRangeFromAbs (MIN (chosenRange.location,
|
|
|
|
|
prevChosenRange.location),
|
|
|
|
|
MAX (chosenRange.location,
|
|
|
|
|
prevChosenRange.location))];
|
|
|
|
|
[self drawSelectionAsRangeNoCaret:
|
|
|
|
|
MakeRangeFromAbs (MIN (NSMaxRange (chosenRange),
|
|
|
|
|
NSMaxRange (prevChosenRange)),
|
|
|
|
|
MAX (NSMaxRange (chosenRange),
|
|
|
|
|
NSMaxRange (prevChosenRange)))];
|
|
|
|
|
[_window flushWindow];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[self drawRect: [self visibleRect] withSelection: chosenRange];
|
|
|
|
|
[_window flushWindow];
|
|
|
|
|
}
|
2000-02-19 00:40:47 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
didDragging = YES;
|
|
|
|
|
}
|
1999-11-11 17:17:14 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSDebugLog(@"chosenRange. location = % d, length = %d\n",
|
|
|
|
|
(int)chosenRange.location, (int)chosenRange.length);
|
|
|
|
|
|
|
|
|
|
[self setSelectedRangeNoDrawing: chosenRange];
|
|
|
|
|
if (!didDragging)
|
|
|
|
|
[self drawSelectionAsRange: chosenRange];
|
|
|
|
|
else if (chosenRange.length == 0)
|
|
|
|
|
[self drawInsertionPointAtIndex: chosenRange.location
|
2000-05-13 14:28:02 +00:00
|
|
|
|
color: _caret_color turnedOn: YES];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
|
|
|
|
// remember for column stable cursor up/down
|
|
|
|
|
_currentCursor = [self rectForCharacterIndex: chosenRange.location].origin;
|
|
|
|
|
|
|
|
|
|
[self unlockFocus];
|
|
|
|
|
[_window flushWindow];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) keyDown: (NSEvent*)theEvent
|
|
|
|
|
{
|
2000-04-02 05:58:50 +00:00
|
|
|
|
// If not editable, don't recognize the key down
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (!_tf.is_editable)
|
|
|
|
|
{
|
|
|
|
|
[super keyDown: theEvent];
|
2000-03-19 07:33:26 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[self interpretKeyEvents: [NSArray arrayWithObject: theEvent]];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) insertNewline: (id) sender
|
|
|
|
|
{
|
|
|
|
|
if (_tf.is_field_editor)
|
|
|
|
|
{
|
|
|
|
|
[self _illegalMovement: NSReturnTextMovement];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-19 07:33:26 +00:00
|
|
|
|
[self insertText: [[self class] newlineString]];
|
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-03-19 07:33:26 +00:00
|
|
|
|
- (void) insertTab: (id) sender
|
|
|
|
|
{
|
|
|
|
|
if (_tf.is_field_editor)
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
2000-03-19 07:33:26 +00:00
|
|
|
|
[self _illegalMovement: NSTabTextMovement];
|
|
|
|
|
return;
|
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-03-19 07:33:26 +00:00
|
|
|
|
[self insertText: @"\t"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) insertBacktab: (id) sender
|
|
|
|
|
{
|
|
|
|
|
if (_tf.is_field_editor)
|
|
|
|
|
{
|
|
|
|
|
[self _illegalMovement: NSBacktabTextMovement];
|
|
|
|
|
return;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-19 07:33:26 +00:00
|
|
|
|
//[self insertText: @"\t"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) deleteForward: (id) sender
|
|
|
|
|
{
|
|
|
|
|
if (_selected_range.location != [self textLength])
|
|
|
|
|
{
|
|
|
|
|
/* Not at the end of text -- delete following character */
|
|
|
|
|
[self deleteRange:
|
|
|
|
|
[self selectionRangeForProposedRange:
|
|
|
|
|
NSMakeRange (_selected_range.location, 1)
|
|
|
|
|
granularity: NSSelectByCharacter]
|
|
|
|
|
backspace: NO];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* end of text: behave the same way as NSBackspaceKey */
|
|
|
|
|
[self deleteBackward: sender];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) deleteBackward: (id) sender
|
|
|
|
|
{
|
|
|
|
|
[self deleteRange: _selected_range backspace: YES];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<!> choose granularity according to keyboard modifier flags
|
|
|
|
|
- (void) moveUp: (id) sender
|
|
|
|
|
{
|
|
|
|
|
unsigned cursorIndex;
|
|
|
|
|
NSPoint cursorPoint;
|
|
|
|
|
|
2000-03-19 07:33:26 +00:00
|
|
|
|
if (_tf.is_field_editor)
|
|
|
|
|
{
|
|
|
|
|
[self _illegalMovement: NSUpTextMovement];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
/* Do nothing if we are at beginning of text */
|
|
|
|
|
if (_selected_range.location == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (_selected_range.length)
|
|
|
|
|
{
|
|
|
|
|
_currentCursor = [self rectForCharacterIndex:
|
|
|
|
|
_selected_range.location].origin;
|
|
|
|
|
}
|
|
|
|
|
cursorIndex = _selected_range.location;
|
|
|
|
|
cursorPoint = [self rectForCharacterIndex: cursorIndex].origin;
|
|
|
|
|
cursorIndex = [self characterIndexForPoint:
|
|
|
|
|
NSMakePoint (_currentCursor.x + 0.001,
|
|
|
|
|
MAX (0, cursorPoint.y - 0.001))];
|
|
|
|
|
[self setSelectedRange: [self selectionRangeForProposedRange:
|
|
|
|
|
NSMakeRange (cursorIndex, 0)
|
|
|
|
|
granularity: NSSelectByCharacter]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) moveDown: (id) sender
|
|
|
|
|
{
|
|
|
|
|
unsigned cursorIndex;
|
|
|
|
|
NSRect cursorRect;
|
|
|
|
|
|
2000-03-19 07:33:26 +00:00
|
|
|
|
if (_tf.is_field_editor)
|
|
|
|
|
{
|
|
|
|
|
[self _illegalMovement: NSDownTextMovement];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
/* Do nothing if we are at end of text */
|
|
|
|
|
if (_selected_range.location == [self textLength])
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (_selected_range.length)
|
|
|
|
|
{
|
|
|
|
|
_currentCursor = [self rectForCharacterIndex:
|
|
|
|
|
NSMaxRange (_selected_range)].origin;
|
|
|
|
|
}
|
|
|
|
|
cursorIndex = _selected_range.location;
|
|
|
|
|
cursorRect = [self rectForCharacterIndex: cursorIndex];
|
|
|
|
|
cursorIndex = [self characterIndexForPoint:
|
|
|
|
|
NSMakePoint (_currentCursor.x + 0.001,
|
|
|
|
|
NSMaxY (cursorRect) + 0.001)];
|
|
|
|
|
[self setSelectedRange: [self selectionRangeForProposedRange:
|
|
|
|
|
NSMakeRange (cursorIndex, 0)
|
|
|
|
|
granularity: NSSelectByCharacter]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) moveLeft: (id) sender
|
|
|
|
|
{
|
|
|
|
|
/* Do nothing if we are at beginning of text */
|
|
|
|
|
if (_selected_range.location == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
[self setSelectedRange:
|
|
|
|
|
[self selectionRangeForProposedRange:
|
|
|
|
|
NSMakeRange (_selected_range.location - 1, 0)
|
|
|
|
|
granularity: NSSelectByCharacter]];
|
|
|
|
|
_currentCursor.x = [self rectForCharacterIndex:
|
|
|
|
|
_selected_range.location].origin.x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) moveRight: (id) sender
|
|
|
|
|
{
|
|
|
|
|
/* Do nothing if we are at end of text */
|
|
|
|
|
if (_selected_range.location == [self textLength])
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
[self setSelectedRange:
|
|
|
|
|
[self selectionRangeForProposedRange:
|
|
|
|
|
NSMakeRange (MIN (NSMaxRange (_selected_range) + 1,
|
|
|
|
|
[self textLength]), 0)
|
|
|
|
|
granularity: NSSelectByCharacter]];
|
|
|
|
|
_currentCursor.x = [self rectForCharacterIndex:
|
|
|
|
|
_selected_range.location].origin.x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) acceptsFirstResponder
|
|
|
|
|
{
|
|
|
|
|
if ([self isSelectable])
|
|
|
|
|
return YES;
|
|
|
|
|
else
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) resignFirstResponder
|
|
|
|
|
{
|
|
|
|
|
if (([self isEditable])
|
|
|
|
|
&& ([_delegate respondsToSelector: @selector(textShouldEndEditing:)])
|
|
|
|
|
&& ([_delegate textShouldEndEditing: self] == NO))
|
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
|
|
// Add any clean-up stuff here
|
|
|
|
|
|
|
|
|
|
if ([self shouldDrawInsertionPoint])
|
2000-04-23 22:31:25 +00:00
|
|
|
|
{
|
|
|
|
|
[self lockFocus];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[self drawInsertionPointAtIndex: _selected_range.location
|
|
|
|
|
color: nil turnedOn: NO];
|
2000-04-23 22:31:25 +00:00
|
|
|
|
[self unlockFocus];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
//<!> stop timed entry
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
|
postNotificationName: NSTextDidEndEditingNotification
|
|
|
|
|
object: self];
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) becomeFirstResponder
|
|
|
|
|
{
|
|
|
|
|
if ([self isSelectable] == NO)
|
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
|
|
if (([_delegate respondsToSelector: @selector(textShouldBeginEditing:)])
|
|
|
|
|
&& ([_delegate textShouldBeginEditing: self] == NO))
|
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
|
|
// Add any initialization stuff here.
|
|
|
|
|
|
|
|
|
|
//if ([self shouldDrawInsertionPoint])
|
|
|
|
|
// {
|
|
|
|
|
// [self lockFocus];
|
|
|
|
|
// [self drawInsertionPointAtIndex: _selected_range.location
|
2000-05-13 14:28:02 +00:00
|
|
|
|
// color: _caret_color turnedOn: YES];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// [self unlockFocus];
|
|
|
|
|
// //<!> restart timed entry
|
|
|
|
|
// }
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
|
postNotificationName: NSTextDidBeginEditingNotification
|
|
|
|
|
object: self];
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) drawRect: (NSRect)rect
|
|
|
|
|
{
|
|
|
|
|
[self drawRect: rect withSelection: _selected_range];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// text lays out from top to bottom
|
|
|
|
|
- (BOOL) isFlipped
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) isOpaque
|
|
|
|
|
{
|
|
|
|
|
if (_tf.draws_background == NO
|
|
|
|
|
|| _background_color == nil
|
|
|
|
|
|| [_background_color alphaComponent] < 1.0)
|
|
|
|
|
return NO;
|
|
|
|
|
else
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Handle enabling/disabling of services menu items.
|
|
|
|
|
*/
|
|
|
|
|
- (id) validRequestorForSendType: (NSString*) sendType
|
|
|
|
|
returnType: (NSString*) returnType
|
|
|
|
|
{
|
2000-05-23 22:58:24 +00:00
|
|
|
|
if ((!sendType || (_selected_range.length &&
|
|
|
|
|
[sendType isEqual: NSStringPboardType]))
|
|
|
|
|
&& (!returnType || ([self isEditable] &&
|
|
|
|
|
[returnType isEqual: NSStringPboardType])))
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
2000-05-23 22:58:24 +00:00
|
|
|
|
return self;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
2000-05-23 22:58:24 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return [super validRequestorForSendType: sendType
|
|
|
|
|
returnType: returnType];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// NSCoding protocol
|
|
|
|
|
//
|
|
|
|
|
- (void)encodeWithCoder: aCoder
|
|
|
|
|
{
|
|
|
|
|
BOOL flag;
|
|
|
|
|
[super encodeWithCoder: aCoder];
|
|
|
|
|
|
|
|
|
|
[aCoder encodeConditionalObject: _delegate];
|
|
|
|
|
[aCoder encodeObject: _textStorage];
|
|
|
|
|
|
2000-05-13 14:28:02 +00:00
|
|
|
|
flag = _tf.is_field_editor;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-05-13 14:28:02 +00:00
|
|
|
|
flag = _tf.is_editable;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
|
|
|
|
|
flag = _tf.is_selectable;
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-05-13 14:28:02 +00:00
|
|
|
|
flag = _tf.is_rich_text;
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
flag = _tf.imports_graphics;
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-05-13 14:28:02 +00:00
|
|
|
|
flag = _tf.draws_background;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
|
|
|
|
|
flag = _tf.is_horizontally_resizable;
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
|
|
|
|
|
flag = _tf.is_vertically_resizable;
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-05-13 14:28:02 +00:00
|
|
|
|
flag = _tf.uses_font_panel;
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
|
|
|
|
|
flag = _tf.uses_ruler;
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
flag = _tf.is_ruler_visible;
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-05-13 14:28:02 +00:00
|
|
|
|
flag = _tf.smart_insert_delete;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-05-20 16:55:08 +00:00
|
|
|
|
flag = _tf.allows_undo;
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-05-13 14:28:02 +00:00
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[aCoder encodeObject: _typingAttributes];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[aCoder encodeObject: _background_color];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(NSRange) at: &_selected_range];
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[aCoder encodeObject: _caret_color];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(NSSize) at: &_minSize];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(NSSize) at: &_maxSize];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- initWithCoder: aDecoder
|
|
|
|
|
{
|
|
|
|
|
BOOL flag;
|
|
|
|
|
[super initWithCoder: aDecoder];
|
|
|
|
|
|
|
|
|
|
_delegate = [aDecoder decodeObject];
|
|
|
|
|
_textStorage = [aDecoder decodeObject];
|
|
|
|
|
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-05-13 14:28:02 +00:00
|
|
|
|
_tf.is_field_editor = flag;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-05-13 14:28:02 +00:00
|
|
|
|
_tf.is_editable = flag;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
|
|
|
|
|
_tf.is_selectable = flag;
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-05-13 14:28:02 +00:00
|
|
|
|
_tf.is_rich_text = flag;
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_tf.imports_graphics = flag;
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-05-13 14:28:02 +00:00
|
|
|
|
_tf.draws_background = flag;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
|
|
|
|
|
_tf.is_horizontally_resizable = flag;
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
|
|
|
|
|
_tf.is_vertically_resizable = flag;
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-05-13 14:28:02 +00:00
|
|
|
|
_tf.uses_font_panel = flag;
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
|
|
|
|
|
_tf.uses_ruler = flag;
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_tf.is_ruler_visible = flag;
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
|
2000-05-13 14:28:02 +00:00
|
|
|
|
_tf.smart_insert_delete = flag;
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
|
|
|
|
|
_tf.allows_undo = flag;
|
2000-05-13 14:28:02 +00:00
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
_typingAttributes = [aDecoder decodeObject];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
_background_color = [aDecoder decodeObject];
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(NSRange) at: &_selected_range];
|
2000-05-20 16:55:08 +00:00
|
|
|
|
_caret_color = [aDecoder decodeObject];
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(NSSize) at: &_minSize];
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(NSSize) at: &_maxSize];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-04-02 05:58:50 +00:00
|
|
|
|
// build up the layout information that dont get stored
|
2000-03-19 07:33:26 +00:00
|
|
|
|
[self _buildUpLayout];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// NSChangeSpelling protocol
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
- (void) changeSpelling: (id)sender
|
|
|
|
|
{
|
|
|
|
|
[self insertText: [[(NSControl*)sender selectedCell] stringValue]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// NSIgnoreMisspelledWords protocol
|
|
|
|
|
//
|
|
|
|
|
- (void) ignoreSpelling: (id)sender
|
|
|
|
|
{
|
|
|
|
|
[[NSSpellChecker sharedSpellChecker]
|
|
|
|
|
ignoreWord: [[(NSControl*)sender selectedCell] stringValue]
|
|
|
|
|
inSpellDocumentWithTag: [self spellCheckerDocumentTag]];
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSText(GNUstepExtension)
|
|
|
|
|
|
|
|
|
|
+ (NSString*) newlineString
|
|
|
|
|
{
|
|
|
|
|
return @"\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) replaceRange: (NSRange) aRange
|
|
|
|
|
withAttributedString: (NSAttributedString*) attrString
|
|
|
|
|
{
|
2000-06-26 19:55:01 +00:00
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
|
return;
|
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
|
replacementString: [attrString string]])
|
|
|
|
|
return;
|
2000-06-26 19:55:01 +00:00
|
|
|
|
|
2000-04-02 05:58:50 +00:00
|
|
|
|
[_textStorage beginEditing];
|
2000-05-23 22:58:24 +00:00
|
|
|
|
if (_tf.is_rich_text)
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[_textStorage replaceCharactersInRange: aRange
|
|
|
|
|
withAttributedString: attrString];
|
|
|
|
|
else
|
|
|
|
|
[_textStorage replaceCharactersInRange: aRange
|
|
|
|
|
withString: [attrString string]];
|
2000-04-02 05:58:50 +00:00
|
|
|
|
[_textStorage endEditing];
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self didChangeText];
|
2000-04-23 22:31:25 +00:00
|
|
|
|
// ScrollView interaction
|
|
|
|
|
[self sizeToFit];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (unsigned) textLength
|
|
|
|
|
{
|
|
|
|
|
return [_textStorage length];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) sizeToFit: (id)sender
|
|
|
|
|
{
|
|
|
|
|
[self sizeToFit];
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSText(NSTextView)
|
|
|
|
|
|
|
|
|
|
- (void) setRulerVisible: (BOOL)flag
|
|
|
|
|
{
|
|
|
|
|
NSScrollView *sv = [self enclosingScrollView];
|
|
|
|
|
|
|
|
|
|
_tf.is_ruler_visible = flag;
|
|
|
|
|
if (sv != nil)
|
|
|
|
|
[sv setRulersVisible: _tf.is_ruler_visible];
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (int) spellCheckerDocumentTag
|
|
|
|
|
{
|
|
|
|
|
if (!_spellCheckerDocumentTag)
|
|
|
|
|
_spellCheckerDocumentTag = [NSSpellChecker uniqueSpellDocumentTag];
|
|
|
|
|
|
|
|
|
|
return _spellCheckerDocumentTag;
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
- (BOOL) shouldChangeTextInRange: (NSRange)affectedCharRange
|
|
|
|
|
replacementString: (NSString*)replacementString
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) didChangeText
|
|
|
|
|
{
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
|
postNotificationName: NSTextDidChangeNotification object: self];
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// central text inserting method (takes care
|
|
|
|
|
// of optimized redraw/ cursor positioning)
|
|
|
|
|
- (void) insertText: (NSString*) insertString
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
NSRange insertRange = [self rangeForUserTextChange];
|
|
|
|
|
|
|
|
|
|
if (insertRange.location == NSNotFound)
|
|
|
|
|
return;
|
|
|
|
|
|
2000-05-23 22:58:24 +00:00
|
|
|
|
if (_tf.is_rich_text)
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self replaceRange: insertRange
|
2000-03-16 14:16:46 +00:00
|
|
|
|
withAttributedString: AUTORELEASE([[NSAttributedString alloc]
|
|
|
|
|
initWithString: insertString
|
|
|
|
|
attributes: [self typingAttributes]])];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self replaceCharactersInRange: insertRange
|
2000-03-16 14:16:46 +00:00
|
|
|
|
withString: insertString];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// move cursor <!> [self selectionRangeForProposedRange: ]
|
|
|
|
|
[self setSelectedRange:
|
2000-05-20 16:55:08 +00:00
|
|
|
|
NSMakeRange (insertRange.location + [insertString length], 0)];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
|
|
|
|
// remember x for row - stable cursor movements
|
|
|
|
|
_currentCursor = [self rectForCharacterIndex:
|
|
|
|
|
_selected_range.location].origin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setTypingAttributes: (NSDictionary*) dict
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (dict == nil)
|
|
|
|
|
dict = [[self class] defaultTypingAttributes];
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (![dict isKindOfClass: [NSMutableDictionary class]])
|
|
|
|
|
{
|
|
|
|
|
RELEASE(_typingAttributes);
|
|
|
|
|
_typingAttributes = [[NSMutableDictionary alloc] initWithDictionary: dict];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
ASSIGN(_typingAttributes, (NSMutableDictionary*)dict);
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
- (NSDictionary*) typingAttributes
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
return [NSDictionary dictionaryWithDictionary: _typingAttributes];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) updateFontPanel
|
|
|
|
|
{
|
|
|
|
|
// update fontPanel only if told so
|
|
|
|
|
if (_tf.uses_font_panel)
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
NSRange longestRange;
|
|
|
|
|
NSFont *currentFont = [_textStorage attribute: NSFontAttributeName
|
|
|
|
|
atIndex: _selected_range.location
|
|
|
|
|
longestEffectiveRange: &longestRange
|
|
|
|
|
inRange: _selected_range];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[[NSFontManager sharedFontManager]
|
|
|
|
|
setSelectedFont: currentFont
|
2000-06-11 00:28:35 +00:00
|
|
|
|
isMultiple: !NSEqualRanges(longestRange, _selected_range)];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) shouldDrawInsertionPoint
|
|
|
|
|
{
|
|
|
|
|
return (_selected_range.length == 0) && [self isEditable];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) drawInsertionPointInRect: (NSRect)rect
|
|
|
|
|
color: (NSColor*)color
|
|
|
|
|
turnedOn: (BOOL)flag
|
|
|
|
|
{
|
|
|
|
|
if (!_window)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (flag)
|
|
|
|
|
{
|
|
|
|
|
[color set];
|
|
|
|
|
NSRectFill(rect);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[[self backgroundColor] set];
|
|
|
|
|
NSRectFill(rect);
|
2000-04-23 22:31:25 +00:00
|
|
|
|
// FIXME: We should redisplay the character the cursor was on.
|
|
|
|
|
//[self setNeedsDisplayInRect: rect];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-23 22:31:25 +00:00
|
|
|
|
[_window flushWindow];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSRange) selectionRangeForProposedRange: (NSRange)proposedCharRange
|
|
|
|
|
granularity: (NSSelectionGranularity)granularity
|
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
unsigned index;
|
|
|
|
|
NSRange aRange;
|
|
|
|
|
NSRange newRange = proposedCharRange;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSString *string = [self string];
|
2000-05-20 16:55:08 +00:00
|
|
|
|
unsigned length = [string length];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-06-19 17:13:06 +00:00
|
|
|
|
if (proposedCharRange.location >= length)
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
2000-05-20 16:55:08 +00:00
|
|
|
|
proposedCharRange.location = length;
|
|
|
|
|
proposedCharRange.length = 0;
|
2000-06-19 17:09:45 +00:00
|
|
|
|
return proposedCharRange;
|
2000-05-20 16:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
if (proposedCharRange.length > length - proposedCharRange.location)
|
|
|
|
|
{
|
|
|
|
|
proposedCharRange.length = length - proposedCharRange.location;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (!length)
|
|
|
|
|
return proposedCharRange;
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
switch (granularity)
|
|
|
|
|
{
|
|
|
|
|
case NSSelectByWord:
|
2000-05-20 16:55:08 +00:00
|
|
|
|
index = [_textStorage nextWordFromIndex: proposedCharRange.location
|
|
|
|
|
forward: NO];
|
|
|
|
|
newRange.location = index;
|
|
|
|
|
index = [_textStorage nextWordFromIndex: NSMaxRange(proposedCharRange)
|
|
|
|
|
forward: YES];
|
|
|
|
|
if (index > newRange.location)
|
|
|
|
|
newRange.length = index - 1 - newRange.location;
|
|
|
|
|
return newRange;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
case NSSelectByParagraph:
|
2000-05-20 16:55:08 +00:00
|
|
|
|
return [[self string] lineRangeForRange: proposedCharRange];
|
|
|
|
|
|
|
|
|
|
case NSSelectByCharacter:
|
|
|
|
|
default:
|
|
|
|
|
aRange = [string rangeOfComposedCharacterSequenceAtIndex: proposedCharRange.location];
|
|
|
|
|
newRange.location = aRange.location;
|
|
|
|
|
// If the proposedCharRange is empty we only ajust the beginning
|
|
|
|
|
if (!proposedCharRange.length)
|
|
|
|
|
return newRange;
|
|
|
|
|
aRange = [string rangeOfComposedCharacterSequenceAtIndex: NSMaxRange(proposedCharRange)];
|
|
|
|
|
newRange.length = NSMaxRange(aRange) - newRange.location;
|
|
|
|
|
return newRange;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
2000-05-20 16:55:08 +00:00
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
- (NSRange) rangeForUserCharacterAttributeChange
|
|
|
|
|
{
|
|
|
|
|
if (!_tf.is_editable || !_tf.uses_font_panel)
|
|
|
|
|
return NSMakeRange(NSNotFound, 0);
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
if (_tf.is_rich_text)
|
|
|
|
|
// This expects the selection to be already corrected to characters
|
|
|
|
|
return _selected_range;
|
|
|
|
|
else
|
|
|
|
|
return NSMakeRange(0, [_textStorage length]);
|
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
- (NSRange) rangeForUserParagraphAttributeChange
|
|
|
|
|
{
|
|
|
|
|
if (!_tf.is_editable || !_tf.uses_ruler)
|
|
|
|
|
return NSMakeRange(NSNotFound, 0);
|
|
|
|
|
|
|
|
|
|
if (_tf.is_rich_text)
|
|
|
|
|
return [self selectionRangeForProposedRange: _selected_range
|
|
|
|
|
granularity: NSSelectByParagraph];
|
|
|
|
|
else
|
|
|
|
|
return NSMakeRange(0, [_textStorage length]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSRange) rangeForUserTextChange
|
|
|
|
|
{
|
|
|
|
|
if (!_tf.is_editable)
|
|
|
|
|
return NSMakeRange(NSNotFound, 0);
|
|
|
|
|
|
|
|
|
|
// This expects the selection to be already corrected to characters
|
|
|
|
|
return _selected_range;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setAlignment: (NSTextAlignment)alignment
|
|
|
|
|
range: (NSRange)aRange
|
|
|
|
|
{
|
2000-06-16 17:07:11 +00:00
|
|
|
|
NSParagraphStyle *style;
|
|
|
|
|
NSMutableParagraphStyle *mstyle;
|
2000-05-20 16:55:08 +00:00
|
|
|
|
|
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
|
replacementString: nil])
|
|
|
|
|
return;
|
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
|
[_textStorage setAlignment: alignment
|
|
|
|
|
range: aRange];
|
|
|
|
|
[_textStorage endEditing];
|
|
|
|
|
[self didChangeText];
|
|
|
|
|
|
|
|
|
|
// Set the typing attributes
|
2000-06-16 17:07:11 +00:00
|
|
|
|
style = [_typingAttributes objectForKey: NSParagraphStyleAttributeName];
|
|
|
|
|
if (style == nil)
|
|
|
|
|
style = [NSParagraphStyle defaultParagraphStyle];
|
|
|
|
|
|
|
|
|
|
mstyle = [style mutableCopy];
|
|
|
|
|
|
|
|
|
|
[mstyle setAlignment: alignment];
|
2000-05-20 16:55:08 +00:00
|
|
|
|
// FIXME: Should use setTypingAttributes
|
2000-06-16 17:07:11 +00:00
|
|
|
|
[_typingAttributes setObject: mstyle forKey: NSParagraphStyleAttributeName];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-23 22:58:24 +00:00
|
|
|
|
- (NSString*) preferredPasteboardTypeFromArray: (NSArray*)availableTypes
|
|
|
|
|
restrictedToTypesFromArray: (NSArray*)allowedTypes
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
2000-05-23 22:58:24 +00:00
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
NSString *type;
|
|
|
|
|
|
|
|
|
|
if (availableTypes == nil)
|
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
|
|
if (allowedTypes == nil)
|
|
|
|
|
return [availableTypes objectAtIndex: 0];
|
|
|
|
|
|
|
|
|
|
enumerator = [allowedTypes objectEnumerator];
|
|
|
|
|
while ((type = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([availableTypes containsObject: type])
|
|
|
|
|
{
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) readSelectionFromPasteboard: (NSPasteboard*)pboard
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
Reads the text view's preferred type of data from the pasteboard specified
|
|
|
|
|
by the pboard parameter. This method
|
|
|
|
|
invokes the preferredPasteboardTypeFromArray: restrictedToTypesFromArray:
|
|
|
|
|
method to determine the text view's
|
|
|
|
|
preferred type of data and then reads the data using the
|
|
|
|
|
readSelectionFromPasteboard: type: method. Returns YES if the
|
|
|
|
|
data was successfully read.
|
|
|
|
|
*/
|
|
|
|
|
NSString *type = [self preferredPasteboardTypeFromArray: [pboard types]
|
|
|
|
|
restrictedToTypesFromArray: [self readablePasteboardTypes]];
|
|
|
|
|
|
|
|
|
|
if (type == nil)
|
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
|
|
return [self readSelectionFromPasteboard: pboard
|
|
|
|
|
type: type];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) readSelectionFromPasteboard: (NSPasteboard*)pboard
|
|
|
|
|
type: (NSString*)type
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
Reads data of the given type from pboard. The new data is placed at the
|
|
|
|
|
current insertion point, replacing the current selection if one exists.
|
|
|
|
|
Returns YES if the data was successfully read.
|
|
|
|
|
|
|
|
|
|
You should override this method to read pasteboard types other than the
|
|
|
|
|
default types. Use the rangeForUserTextChange method to obtain the range
|
|
|
|
|
of characters (if any) to be replaced by the new data.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if ([type isEqualToString: NSStringPboardType])
|
|
|
|
|
{
|
|
|
|
|
[self insertText: [pboard stringForType: NSStringPboardType]];
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
|
|
|
|
if ([self isRichText])
|
2000-05-23 22:58:24 +00:00
|
|
|
|
{
|
|
|
|
|
if ([type isEqualToString: NSRTFPboardType])
|
|
|
|
|
{
|
2000-06-26 19:55:01 +00:00
|
|
|
|
[self replaceCharactersInRange: [self rangeForUserTextChange]
|
|
|
|
|
withRTF: [pboard dataForType: NSRTFPboardType]];
|
2000-05-23 22:58:24 +00:00
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_tf.imports_graphics)
|
|
|
|
|
{
|
|
|
|
|
if ([type isEqualToString: NSRTFDPboardType])
|
|
|
|
|
{
|
2000-06-26 19:55:01 +00:00
|
|
|
|
[self replaceCharactersInRange: [self rangeForUserTextChange]
|
|
|
|
|
withRTFD: [pboard dataForType: NSRTFDPboardType]];
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
// FIXME: Should also support: NSTIFFPboardType
|
|
|
|
|
if ([type isEqualToString: NSFileContentsPboardType])
|
|
|
|
|
{
|
|
|
|
|
NSTextAttachment *attachment = [[NSTextAttachment alloc]
|
|
|
|
|
initWithFileWrapper:
|
|
|
|
|
[pboard readFileWrapper]];
|
|
|
|
|
|
2000-05-23 22:58:24 +00:00
|
|
|
|
[self replaceRange: [self rangeForUserTextChange]
|
2000-06-26 19:55:01 +00:00
|
|
|
|
withAttributedString:
|
|
|
|
|
[NSAttributedString attributedStringWithAttachment: attachment]];
|
|
|
|
|
RELEASE(attachment);
|
2000-05-23 22:58:24 +00:00
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// color accepting
|
|
|
|
|
if ([type isEqualToString: NSColorPboardType])
|
|
|
|
|
{
|
|
|
|
|
NSColor *color = [NSColor colorFromPasteboard: pboard];
|
|
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
|
|
|
|
|
|
|
|
|
if (aRange.location != NSNotFound)
|
|
|
|
|
[self setTextColor: color range: aRange];
|
|
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// font pasting
|
|
|
|
|
if ([type isEqualToString: NSFontPboardType])
|
|
|
|
|
{
|
2000-06-26 19:55:01 +00:00
|
|
|
|
NSDictionary *dict = [pboard propertyListForType: NSFontPboardType];
|
2000-05-23 22:58:24 +00:00
|
|
|
|
|
2000-06-26 19:55:01 +00:00
|
|
|
|
if (dict != nil)
|
2000-05-23 22:58:24 +00:00
|
|
|
|
{
|
2000-06-26 19:55:01 +00:00
|
|
|
|
[self setAttributes: dict
|
|
|
|
|
range: [self rangeForUserCharacterAttributeChange]];
|
|
|
|
|
return YES;
|
2000-05-23 22:58:24 +00:00
|
|
|
|
}
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ruler pasting
|
|
|
|
|
if ([type isEqualToString: NSRulerPboardType])
|
|
|
|
|
{
|
2000-06-26 19:55:01 +00:00
|
|
|
|
NSDictionary *dict = [pboard propertyListForType: NSRulerPboardType];
|
2000-05-23 22:58:24 +00:00
|
|
|
|
|
2000-06-26 19:55:01 +00:00
|
|
|
|
if (dict != nil)
|
2000-05-23 22:58:24 +00:00
|
|
|
|
{
|
2000-06-26 19:55:01 +00:00
|
|
|
|
[self setAttributes: dict
|
|
|
|
|
range: [self rangeForUserParagraphAttributeChange]];
|
|
|
|
|
return YES;
|
2000-05-23 22:58:24 +00:00
|
|
|
|
}
|
2000-06-26 19:55:01 +00:00
|
|
|
|
return NO;
|
2000-05-23 22:58:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSArray*) readablePasteboardTypes
|
|
|
|
|
{
|
|
|
|
|
// get default types, what are they?
|
2000-06-26 19:55:01 +00:00
|
|
|
|
NSMutableArray *ret = [NSMutableArray arrayWithObjects: NSRulerPboardType,
|
|
|
|
|
NSColorPboardType, NSFontPboardType, nil];
|
2000-05-23 22:58:24 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (_tf.imports_graphics)
|
2000-05-23 22:58:24 +00:00
|
|
|
|
{
|
|
|
|
|
[ret addObject: NSRTFDPboardType];
|
|
|
|
|
//[ret addObject: NSTIFFPboardType];
|
2000-06-26 22:23:11 +00:00
|
|
|
|
[ret addObject: NSFileContentsPboardType];
|
2000-05-23 22:58:24 +00:00
|
|
|
|
}
|
|
|
|
|
if (_tf.is_rich_text)
|
|
|
|
|
[ret addObject: NSRTFPboardType];
|
|
|
|
|
|
|
|
|
|
[ret addObject: NSStringPboardType];
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-23 22:58:24 +00:00
|
|
|
|
- (NSArray*) writablePasteboardTypes
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
2000-05-23 22:58:24 +00:00
|
|
|
|
// the selected text can be written to the pasteboard with which types.
|
|
|
|
|
return [self readablePasteboardTypes];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) writeSelectionToPasteboard: (NSPasteboard*)pboard
|
|
|
|
|
type: (NSString*)type
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
Writes the current selection to pboard using the given type. Returns YES
|
|
|
|
|
if the data was successfully written. You can override this method to add
|
|
|
|
|
support for writing new types of data to the pasteboard. You should invoke
|
|
|
|
|
super's implementation of the method to handle any types of data your
|
|
|
|
|
overridden version does not.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
return [self writeSelectionToPasteboard: pboard
|
|
|
|
|
types: [NSArray arrayWithObject: type]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) writeSelectionToPasteboard: (NSPasteboard*)pboard
|
|
|
|
|
types: (NSArray*)types
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/* Writes the current selection to pboard under each type in the types
|
|
|
|
|
array. Returns YES if the data for any single type was written
|
|
|
|
|
successfully.
|
|
|
|
|
|
|
|
|
|
You should not need to override this method. You might need to invoke this
|
|
|
|
|
method if you are implementing a new type of pasteboard to handle services
|
|
|
|
|
other than copy/paste or dragging. */
|
|
|
|
|
BOOL ret = NO;
|
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
NSString *type;
|
|
|
|
|
|
|
|
|
|
if (types == nil)
|
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
|
|
[pboard declareTypes: types owner: self];
|
|
|
|
|
|
|
|
|
|
enumerator = [types objectEnumerator];
|
|
|
|
|
while ((type = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([type isEqualToString: NSStringPboardType])
|
|
|
|
|
{
|
|
|
|
|
ret = ret || [pboard setString: [[self string] substringWithRange: _selected_range]
|
|
|
|
|
forType: NSStringPboardType];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([type isEqualToString: NSRTFPboardType])
|
|
|
|
|
{
|
|
|
|
|
ret = ret || [pboard setData: [self RTFFromRange: _selected_range]
|
|
|
|
|
forType: NSRTFPboardType];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([type isEqualToString: NSRTFDPboardType])
|
|
|
|
|
{
|
|
|
|
|
ret = ret || [pboard setData: [self RTFDFromRange: _selected_range]
|
|
|
|
|
forType: NSRTFDPboardType];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([type isEqualToString: NSColorPboardType])
|
|
|
|
|
{
|
|
|
|
|
NSColor *color = [self textColor];
|
|
|
|
|
|
|
|
|
|
if (color != nil)
|
|
|
|
|
{
|
|
|
|
|
[color writeToPasteboard: pboard];
|
|
|
|
|
ret = YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([type isEqualToString: NSFontPboardType])
|
|
|
|
|
{
|
2000-06-26 19:55:01 +00:00
|
|
|
|
NSDictionary *dict = [_textStorage fontAttributesInRange: _selected_range];
|
|
|
|
|
|
|
|
|
|
if (dict != nil)
|
2000-05-23 22:58:24 +00:00
|
|
|
|
{
|
2000-06-26 19:55:01 +00:00
|
|
|
|
[pboard setPropertyList: dict forType: NSFontPboardType];
|
2000-05-23 22:58:24 +00:00
|
|
|
|
ret = YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([type isEqualToString: NSRulerPboardType])
|
|
|
|
|
{
|
2000-06-26 19:55:01 +00:00
|
|
|
|
NSDictionary *dict = [_textStorage rulerAttributesInRange: _selected_range];
|
2000-05-23 22:58:24 +00:00
|
|
|
|
|
2000-06-26 19:55:01 +00:00
|
|
|
|
if (dict != nil)
|
2000-05-23 22:58:24 +00:00
|
|
|
|
{
|
2000-06-26 19:55:01 +00:00
|
|
|
|
[pboard setPropertyList: dict forType: NSRulerPboardType];
|
2000-05-23 22:58:24 +00:00
|
|
|
|
ret = YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSText(GNUstepPrivate)
|
|
|
|
|
|
|
|
|
|
+ (void) setSelectionWordGranularitySet: (NSCharacterSet*) aSet
|
|
|
|
|
{
|
|
|
|
|
ASSIGN(selectionWordGranularitySet, aSet);
|
2000-04-23 22:31:25 +00:00
|
|
|
|
ASSIGN(invSelectionWordGranularitySet, [aSet invertedSet]);
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void) setSelectionParagraphGranularitySet: (NSCharacterSet*) aSet
|
|
|
|
|
{
|
|
|
|
|
ASSIGN(selectionParagraphGranularitySet, aSet);
|
2000-04-23 22:31:25 +00:00
|
|
|
|
ASSIGN(invSelectionParagraphGranularitySet, [aSet invertedSet]);
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-20 16:55:08 +00:00
|
|
|
|
+ (NSDictionary*) defaultTypingAttributes
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
|
|
|
|
return [NSDictionary dictionaryWithObjectsAndKeys:
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[NSParagraphStyle defaultParagraphStyle], NSParagraphStyleAttributeName,
|
|
|
|
|
[NSFont userFontOfSize: 12], NSFontAttributeName,
|
|
|
|
|
[NSColor textColor], NSForegroundColorAttributeName,
|
2000-03-16 14:16:46 +00:00
|
|
|
|
nil];
|
|
|
|
|
}
|
2000-03-19 07:33:26 +00:00
|
|
|
|
|
2000-06-26 19:55:01 +00:00
|
|
|
|
- (void) setAttributes: (NSDictionary*) attributes range: (NSRange) aRange
|
|
|
|
|
{
|
|
|
|
|
NSString *type;
|
|
|
|
|
id val;
|
|
|
|
|
NSEnumerator *enumerator = [attributes keyEnumerator];
|
|
|
|
|
|
|
|
|
|
if (aRange.location != NSNotFound)
|
|
|
|
|
return;
|
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
|
replacementString: nil])
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
|
while ((type = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
val = [attributes objectForKey: type];
|
|
|
|
|
[_textStorage addAttribute: type
|
|
|
|
|
value: val
|
|
|
|
|
range: aRange];
|
|
|
|
|
}
|
|
|
|
|
[_textStorage endEditing];
|
|
|
|
|
[self didChangeText];
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-19 07:33:26 +00:00
|
|
|
|
- (void) _illegalMovement: (int) textMovement
|
|
|
|
|
{
|
|
|
|
|
// This is similar to [self resignFirstResponder],
|
|
|
|
|
// with the difference that in the notification we need
|
|
|
|
|
// to put the NSTextMovement, which resignFirstResponder
|
|
|
|
|
// does not. Also, if we are ending editing, we are going
|
|
|
|
|
// to be removed, so it's useless to update any drawing.
|
|
|
|
|
NSNumber *number;
|
|
|
|
|
NSDictionary *uiDictionary;
|
|
|
|
|
|
|
|
|
|
if (([self isEditable])
|
|
|
|
|
&& ([_delegate respondsToSelector:
|
|
|
|
|
@selector(textShouldEndEditing:)])
|
|
|
|
|
&& ([_delegate textShouldEndEditing: self] == NO))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Add any clean-up stuff here
|
|
|
|
|
|
|
|
|
|
number = [NSNumber numberWithInt: textMovement];
|
|
|
|
|
uiDictionary = [NSDictionary dictionaryWithObject: number
|
|
|
|
|
forKey: @"NSTextMovement"];
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
|
postNotificationName: NSTextDidEndEditingNotification
|
|
|
|
|
object: self
|
|
|
|
|
userInfo: uiDictionary];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
// begin: dragging of colors and files---------------
|
|
|
|
|
- (unsigned int) draggingEntered: (id <NSDraggingInfo>)sender
|
|
|
|
|
{
|
|
|
|
|
return NSDragOperationGeneric;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (unsigned int) draggingUpdated: (id <NSDraggingInfo>)sender
|
|
|
|
|
{
|
|
|
|
|
return NSDragOperationGeneric;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) draggingExited: (id <NSDraggingInfo>)sender
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) prepareForDragOperation: (id <NSDraggingInfo>)sender
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) performDragOperation: (id <NSDraggingInfo>)sender
|
|
|
|
|
{
|
2000-05-23 22:58:24 +00:00
|
|
|
|
return [self readSelectionFromPasteboard: [sender draggingPasteboard]];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) concludeDragOperation: (id <NSDraggingInfo>)sender
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
// end: drag accepting---------------------------------
|
|
|
|
|
|
|
|
|
|
// central text deletion/backspace method
|
|
|
|
|
// (takes care of optimized redraw/ cursor positioning)
|
|
|
|
|
- (void) deleteRange: (NSRange) aRange
|
|
|
|
|
backspace: (BOOL) flag
|
1996-05-30 20:03:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSRange deleteRange;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-06-26 19:55:01 +00:00
|
|
|
|
if (aRange.location == NSNotFound)
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
2000-06-26 19:55:01 +00:00
|
|
|
|
if (!aRange.length && !(flag && aRange.location))
|
2000-03-16 14:16:46 +00:00
|
|
|
|
return;
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (aRange.length)
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
deleteRange = aRange;
|
|
|
|
|
}
|
|
|
|
|
else
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
deleteRange = NSMakeRange (MAX (0, aRange.location - 1), 1);
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-06-26 19:55:01 +00:00
|
|
|
|
if (![self shouldChangeTextInRange: deleteRange
|
2000-05-20 16:55:08 +00:00
|
|
|
|
replacementString: @""])
|
|
|
|
|
return;
|
2000-04-02 05:58:50 +00:00
|
|
|
|
[_textStorage beginEditing];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[_textStorage deleteCharactersInRange: deleteRange];
|
2000-04-02 05:58:50 +00:00
|
|
|
|
[_textStorage endEditing];
|
2000-05-20 16:55:08 +00:00
|
|
|
|
[self didChangeText];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
|
|
|
|
// ScrollView interaction
|
|
|
|
|
[self sizeToFit];
|
|
|
|
|
|
|
|
|
|
// move cursor <!> [self selectionRangeForProposedRange: ]
|
|
|
|
|
[self setSelectedRange: NSMakeRange (deleteRange.location, 0)];
|
|
|
|
|
|
|
|
|
|
// remember x for row - stable cursor movements
|
|
|
|
|
_currentCursor = [self rectForCharacterIndex:
|
|
|
|
|
_selected_range.location].origin;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (unsigned) characterIndexForPoint: (NSPoint) point
|
|
|
|
|
{
|
|
|
|
|
return [_layoutManager characterIndexForPoint: point];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSRect) rectForCharacterIndex: (unsigned) index
|
|
|
|
|
{
|
|
|
|
|
return [_layoutManager rectForCharacterIndex: index];
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-19 07:33:26 +00:00
|
|
|
|
- (void) _buildUpLayout
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
|
|
|
|
if (_layoutManager == nil)
|
|
|
|
|
_layoutManager = [[GSSimpleLayoutManager alloc]
|
2000-04-02 05:58:50 +00:00
|
|
|
|
initForText: self];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-04-02 05:58:50 +00:00
|
|
|
|
[_textStorage addLayoutManager: _layoutManager];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns the currently used bounds for all the text
|
|
|
|
|
- (NSRect) _textBounds
|
|
|
|
|
{
|
|
|
|
|
return [_layoutManager _textBounds];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) drawRect: (NSRect) rect
|
|
|
|
|
withSelection: (NSRange) selectedCharacterRange
|
|
|
|
|
{
|
|
|
|
|
NSRange drawnRange;
|
|
|
|
|
NSRange newRange;
|
|
|
|
|
|
|
|
|
|
if (_tf.draws_background)
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
|
|
|
|
// clear area under text
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[[self backgroundColor] set];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
NSRectFill(rect);
|
|
|
|
|
}
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
|
|
|
|
drawnRange = [_layoutManager drawRectCharacters: rect];
|
|
|
|
|
|
|
|
|
|
// We have to redraw the part of the selection that is inside
|
|
|
|
|
// the redrawn lines
|
|
|
|
|
newRange = NSIntersectionRange(selectedCharacterRange, drawnRange);
|
|
|
|
|
// Was there any overlapping with the selection?
|
|
|
|
|
if ((selectedCharacterRange.length &&
|
|
|
|
|
NSLocationInRange(newRange.location, selectedCharacterRange)) ||
|
|
|
|
|
(selectedCharacterRange.location == newRange.location))
|
|
|
|
|
[self drawSelectionAsRange: newRange];
|
1999-06-22 23:37:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
- (void) drawInsertionPointAtIndex: (unsigned) index
|
|
|
|
|
color: (NSColor*) color
|
|
|
|
|
turnedOn: (BOOL) flag
|
2000-03-08 08:43:15 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSRect drawRect = [self rectForCharacterIndex: index];
|
|
|
|
|
|
|
|
|
|
drawRect.size.width = 1;
|
2000-03-19 07:33:26 +00:00
|
|
|
|
if (drawRect.size.height == 0)
|
|
|
|
|
drawRect.size.height = 12;
|
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
if (flag && color == nil)
|
2000-05-13 14:28:02 +00:00
|
|
|
|
color = _caret_color;
|
2000-03-16 14:16:46 +00:00
|
|
|
|
|
2000-03-08 08:43:15 +00:00
|
|
|
|
[self drawInsertionPointInRect: drawRect
|
2000-03-16 14:16:46 +00:00
|
|
|
|
color: color
|
2000-03-08 08:43:15 +00:00
|
|
|
|
turnedOn: flag];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-08 08:43:15 +00:00
|
|
|
|
- (void) drawSelectionAsRangeNoCaret: (NSRange) aRange
|
|
|
|
|
{
|
|
|
|
|
if (aRange.length)
|
2000-03-16 14:16:46 +00:00
|
|
|
|
{
|
2000-03-08 08:43:15 +00:00
|
|
|
|
NSRect startRect = [self rectForCharacterIndex: aRange.location];
|
|
|
|
|
NSRect endRect = [self rectForCharacterIndex: NSMaxRange (aRange)];
|
2000-03-16 14:16:46 +00:00
|
|
|
|
float maxWidth = _frame.size.width;
|
|
|
|
|
|
|
|
|
|
if (startRect.origin.y == endRect.origin.y)
|
|
|
|
|
{
|
2000-03-08 08:43:15 +00:00
|
|
|
|
// single line selection
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSHighlightRect (NSMakeRect (startRect.origin.x, startRect.origin.y,
|
|
|
|
|
endRect.origin.x - startRect.origin.x,
|
2000-03-08 08:43:15 +00:00
|
|
|
|
startRect.size.height));
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
else if (startRect.origin.y == endRect.origin.y - endRect.size.height)
|
|
|
|
|
{
|
2000-03-08 08:43:15 +00:00
|
|
|
|
// two line selection
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
2000-03-08 08:43:15 +00:00
|
|
|
|
// first line
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSHighlightRect (NSMakeRect (startRect.origin.x, startRect.origin.y,
|
|
|
|
|
maxWidth - startRect.origin.x,
|
|
|
|
|
startRect.size.height));
|
2000-03-08 08:43:15 +00:00
|
|
|
|
// second line
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSHighlightRect (NSMakeRect (0, endRect.origin.y, endRect.origin.x,
|
|
|
|
|
endRect.size.height));
|
1999-11-11 17:17:14 +00:00
|
|
|
|
|
2000-03-16 14:16:46 +00:00
|
|
|
|
}
|
2000-03-08 08:43:15 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// 3 Rects: multiline selection
|
1998-09-02 15:05:13 +00:00
|
|
|
|
|
2000-03-08 08:43:15 +00:00
|
|
|
|
// first line
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSHighlightRect (NSMakeRect (startRect.origin.x, startRect.origin.y,
|
|
|
|
|
maxWidth - startRect.origin.x,
|
2000-03-08 08:43:15 +00:00
|
|
|
|
startRect.size.height));
|
|
|
|
|
// intermediate lines
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSHighlightRect (NSMakeRect (0, NSMaxY(startRect),
|
|
|
|
|
maxWidth,
|
|
|
|
|
endRect.origin.y - NSMaxY (startRect)));
|
2000-03-08 08:43:15 +00:00
|
|
|
|
// last line
|
2000-03-16 14:16:46 +00:00
|
|
|
|
NSHighlightRect (NSMakeRect (0, endRect.origin.y, endRect.origin.x,
|
|
|
|
|
endRect.size.height));
|
2000-03-08 08:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1998-09-02 15:05:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-08 08:43:15 +00:00
|
|
|
|
- (void) drawSelectionAsRange: (NSRange) aRange
|
|
|
|
|
{
|
|
|
|
|
if (aRange.length)
|
|
|
|
|
{
|
|
|
|
|
[self drawSelectionAsRangeNoCaret: aRange];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[self drawInsertionPointAtIndex: aRange.location
|
2000-05-13 14:28:02 +00:00
|
|
|
|
color: _caret_color
|
2000-03-08 08:43:15 +00:00
|
|
|
|
turnedOn: YES];
|
|
|
|
|
}
|
1998-09-02 15:05:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-08 08:43:15 +00:00
|
|
|
|
// low level selection setting including delegation
|
|
|
|
|
- (void) setSelectedRangeNoDrawing: (NSRange)range
|
1999-11-11 17:17:14 +00:00
|
|
|
|
{
|
2000-03-16 14:16:46 +00:00
|
|
|
|
//<!> ask delegate for selection validation
|
|
|
|
|
_selected_range = range;
|
|
|
|
|
[self updateFontPanel];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
#if 0
|
2000-03-16 14:16:46 +00:00
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
|
postNotificationName: NSTextViewDidChangeSelectionNotification
|
|
|
|
|
object: self
|
|
|
|
|
userInfo: [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
|
NSStringFromRange (_selected_range),
|
|
|
|
|
NSOldSelectedCharacterRange, nil]];
|
2000-03-08 08:43:15 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
@end
|