2000-02-19 00:40:47 +00:00
|
|
|
/*
|
|
|
|
NSTextView.m
|
|
|
|
|
|
|
|
Copyright (C) 1999 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1999-07-24 22:24:14 +00:00
|
|
|
#include <gnustep/gui/config.h>
|
|
|
|
#include <Foundation/NSCoder.h>
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
#include <Foundation/NSException.h>
|
|
|
|
#include <Foundation/NSProcessInfo.h>
|
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
#include <Foundation/NSNotification.h>
|
|
|
|
#include <AppKit/NSMatrix.h>
|
|
|
|
#include <AppKit/NSApplication.h>
|
|
|
|
#include <AppKit/NSWindow.h>
|
|
|
|
#include <AppKit/NSEvent.h>
|
|
|
|
#include <AppKit/NSFont.h>
|
|
|
|
#include <AppKit/NSColor.h>
|
1998-08-19 09:00:26 +00:00
|
|
|
#include <AppKit/NSTextView.h>
|
1999-02-22 00:41:22 +00:00
|
|
|
#include <AppKit/NSRulerView.h>
|
1998-08-19 09:00:26 +00:00
|
|
|
#include <AppKit/NSPasteboard.h>
|
1998-08-20 09:56:26 +00:00
|
|
|
#include <AppKit/NSSpellChecker.h>
|
|
|
|
#include <AppKit/NSFontPanel.h>
|
|
|
|
#include <AppKit/NSControl.h>
|
1998-09-01 13:23:23 +00:00
|
|
|
#include <AppKit/NSLayoutManager.h>
|
|
|
|
#include <AppKit/NSTextStorage.h>
|
1998-08-19 09:00:26 +00:00
|
|
|
|
1998-08-20 09:56:26 +00:00
|
|
|
@implementation NSTextView
|
1998-08-19 09:00:26 +00:00
|
|
|
|
1999-07-24 22:24:14 +00:00
|
|
|
/* Class methods */
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
+ (void) initialize
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
[super initialize];
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
if ([self class] == [NSTextView class])
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
[self setVersion: 1];
|
1999-07-24 22:24:14 +00:00
|
|
|
[self registerForServices];
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
+ (void) registerForServices
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
NSArray *r;
|
|
|
|
NSArray *s;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME - should register for all types of data we support, not just string.
|
|
|
|
*/
|
|
|
|
r = [NSArray arrayWithObjects: NSStringPboardType, nil];
|
|
|
|
s = [NSArray arrayWithObjects: NSStringPboardType, nil];
|
|
|
|
|
|
|
|
[[NSApplication sharedApplication] registerServicesMenuSendTypes: s
|
|
|
|
returnTypes: r];
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
1999-07-24 22:24:14 +00:00
|
|
|
/* Initializing Methods */
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (id) initWithFrame: (NSRect)frameRect
|
|
|
|
textContainer: (NSTextContainer*)aTextContainer
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
self = [super initWithFrame: frameRect];
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
[self setTextContainer: aTextContainer];
|
|
|
|
[self setEditable: YES];
|
1999-07-24 22:24:14 +00:00
|
|
|
|
|
|
|
return self;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (id) initWithFrame: (NSRect)frameRect
|
1999-06-30 03:10:38 +00:00
|
|
|
{
|
1999-07-15 17:32:38 +00:00
|
|
|
textStorage = [[NSTextStorage alloc] init];
|
|
|
|
|
|
|
|
layoutManager = [[NSLayoutManager alloc] init];
|
1999-08-19 23:18:25 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
[textStorage addLayoutManager: layoutManager];
|
|
|
|
RELEASE(layoutManager);
|
1999-06-30 03:10:38 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
textContainer
|
|
|
|
= [[NSTextContainer alloc] initWithContainerSize: frameRect.size];
|
|
|
|
[layoutManager addTextContainer: textContainer];
|
|
|
|
RELEASE(textContainer);
|
1999-06-30 03:10:38 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
return [self initWithFrame: frameRect textContainer: textContainer];
|
1999-06-30 03:10:38 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setTextContainer: (NSTextContainer*)aTextContainer
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
ASSIGN(textContainer, aTextContainer);
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSTextContainer*) textContainer
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
return textContainer;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) replaceTextContainer: (NSTextContainer*)aTextContainer
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
// Notify layoutManager of change?
|
1998-09-01 13:23:23 +00:00
|
|
|
|
1999-07-24 22:24:14 +00:00
|
|
|
ASSIGN(textContainer, aTextContainer);
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setTextContainerInset: (NSSize)inset
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
textContainerInset = inset;
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSSize) textContainerInset
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
return textContainerInset;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSPoint) textContainerOrigin
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
// use bounds, inset, and used rect.
|
|
|
|
NSRect bRect = [self bounds];
|
|
|
|
|
|
|
|
return NSZeroPoint;
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) invalidateTextContainerOrigin
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
tv_resetTextContainerOrigin = YES;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSLayoutManager*) layoutManager
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
return [textContainer layoutManager];
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSTextStorage*) textStorage
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
return textStorage;
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setBackgroundColor: (NSColor*)aColor
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
ASSIGN(tv_backGroundColor, aColor);
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSColor*) backgroundColor
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
return tv_backGroundColor;
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setDrawsBackground: (BOOL)flag
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
tv_drawsBackground = flag;
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) drawsBackground
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
return tv_drawsBackground;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setNeedsDisplayInRect: (NSRect)aRect
|
|
|
|
avoidAdditionalLayout: (BOOL)flag
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
1999-08-19 23:18:25 +00:00
|
|
|
/*
|
2000-02-19 00:40:47 +00:00
|
|
|
NSRange glyphsToDraw;
|
1999-08-19 23:18:25 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
glyphsToDraw = [layoutManager glyphRangeForTextContainer: textContainer];
|
1999-08-19 23:18:25 +00:00
|
|
|
[self lockFocus];
|
2000-02-19 00:40:47 +00:00
|
|
|
[layoutManager drawGlyphsForGlyphRange: glyphsToDraw
|
|
|
|
atPoint: [self frame].origin];
|
1999-08-19 23:18:25 +00:00
|
|
|
[self unlockFocus];
|
|
|
|
*/
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We override NSView's setNeedsDisplayInRect: */
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setNeedsDisplayInRect: (NSRect)aRect
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
[self setNeedsDisplayInRect: aRect avoidAdditionalLayout: NO];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) shouldDrawInsertionPoint
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
return tv_shouldDrawInsertionPoint;
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) drawInsertionPointInRect: (NSRect)aRect
|
|
|
|
color: (NSColor*)aColor
|
|
|
|
turnedOn: (BOOL)flag
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
[self lockFocus];
|
|
|
|
|
1999-09-09 02:56:20 +00:00
|
|
|
NSDebugLLog(@"NSText",
|
|
|
|
@"drawInsertionPointInRect: (%f, %f)", aRect.size.width, aRect.size.height);
|
1999-07-24 22:24:14 +00:00
|
|
|
|
|
|
|
aRect.size.width = 1;
|
|
|
|
|
|
|
|
if (flag)
|
|
|
|
{
|
|
|
|
[aColor set];
|
|
|
|
NSRectFill(aRect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[[self backgroundColor] set];
|
|
|
|
NSRectFill(aRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
[self unlockFocus];
|
2000-01-10 02:30:45 +00:00
|
|
|
[_window flushWindow];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setConstrainedFrameSize: (NSSize)desiredSize
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
// some black magic here.
|
2000-02-19 00:40:47 +00:00
|
|
|
[self setFrameSize: desiredSize];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) cleanUpAfterDragOperation
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
// release drag information
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setEditable: (BOOL)flag
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
if (flag)
|
|
|
|
tv_selectable = flag;
|
|
|
|
|
|
|
|
tv_editable = flag;
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) isEditable
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
return tv_editable;
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setSelectable: (BOOL)flag
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
tv_selectable = flag;
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) isSelectable
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
return tv_selectable;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setFieldEditor: (BOOL)flag
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
tv_fieldEditor = flag;
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) isFieldEditor
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
return tv_fieldEditor;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setRichText: (BOOL)flag
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
if (!flag)
|
|
|
|
tv_acceptDraggedFiles = flag;
|
|
|
|
|
|
|
|
tv_richText = flag;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) isRichText
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
return tv_richText;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setImportsGraphics: (BOOL)flag
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
if (flag)
|
|
|
|
tv_richText = flag;
|
|
|
|
|
|
|
|
tv_acceptDraggedFiles = flag;
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) importsGraphics
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
return tv_acceptDraggedFiles;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setUsesFontPanel: (BOOL)flag
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
tv_usesFontPanel = flag;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) usesFontPanel
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
return tv_usesFontPanel;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setUsesRuler: (BOOL)flag
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
tv_usesRuler = flag;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) usesRuler
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
return tv_usesRuler;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setRulerVisible: (BOOL)flag
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
tv_rulerVisible = flag;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) isRulerVisible
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
return tv_rulerVisible;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setSelectedRange: (NSRange)charRange
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-08-19 23:18:25 +00:00
|
|
|
NSLog(@"setSelectedRange (%d, %d)", charRange.location, charRange.length);
|
1999-07-24 22:24:14 +00:00
|
|
|
/*
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
2000-02-19 00:40:47 +00:00
|
|
|
postNotificationName: NSTextViewDidChangeSelectionNotification
|
|
|
|
object: self];
|
1999-07-24 22:24:14 +00:00
|
|
|
*/
|
|
|
|
tv_selectedRange = charRange;
|
2000-02-19 00:40:47 +00:00
|
|
|
[self setSelectionGranularity: NSSelectByCharacter];
|
1999-07-24 22:24:14 +00:00
|
|
|
|
|
|
|
// Also removes the marking from
|
|
|
|
// marked text if the new selection is greater than the marked region.
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSRange) selectedRange
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
return tv_selectedRange;
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setSelectedRange: (NSRange)charRange
|
|
|
|
affinity: (NSSelectionAffinity)affinity
|
|
|
|
stillSelecting: (BOOL)flag
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-09-09 02:56:20 +00:00
|
|
|
NSDebugLLog(@"NSText", @"setSelectedRange stillSelecting.");
|
1999-07-24 22:24:14 +00:00
|
|
|
|
|
|
|
tv_selectedRange = charRange;
|
2000-02-19 00:40:47 +00:00
|
|
|
[self setSelectionGranularity: NSSelectByCharacter];
|
1999-07-24 22:24:14 +00:00
|
|
|
|
|
|
|
// FIXME, more.
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSSelectionAffinity) selectionAffinity
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
return tv_selectionAffinity;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setSelectionGranularity: (NSSelectionGranularity)granularity
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
tv_selectionGranularity = granularity;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSSelectionGranularity) selectionGranularity
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
return tv_selectionGranularity;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setInsertionPointColor: (NSColor*)aColor
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
ASSIGN(tv_caretColor, aColor);
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSColor*) insertionPointColor
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
return tv_caretColor;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) updateInsertionPointStateAndRestartTimer: (BOOL)flag
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
// tv_caretLocation =
|
|
|
|
|
|
|
|
// restart blinking timer.
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setSelectedTextAttributes: (NSDictionary*)attributes
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
ASSIGN(tv_selectedTextAttributes, attributes);
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSDictionary*) selectedTextAttributes
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
return tv_selectedTextAttributes;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSRange) markedRange
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
// calculate
|
|
|
|
|
|
|
|
return NSMakeRange(NSNotFound, 0);
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setMarkedTextAttributes: (NSDictionary*)attributes
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
ASSIGN(tv_markedTextAttributes, attributes);
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSDictionary*) markedTextAttributes
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
return tv_markedTextAttributes;
|
1998-08-19 09:00:26 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSString*) preferredPasteboardTypeFromArray: (NSArray*)availableTypes
|
|
|
|
restrictedToTypesFromArray: (NSArray*)allowedTypes
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
// No idea.
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) readSelectionFromPasteboard: (NSPasteboard*)pboard
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
/*
|
|
|
|
Reads the text view's preferred type of data from the pasteboard specified
|
|
|
|
by the pboard parameter. This method
|
2000-02-19 00:40:47 +00:00
|
|
|
invokes the preferredPasteboardTypeFromArray: restrictedToTypesFromArray:
|
1999-07-24 22:24:14 +00:00
|
|
|
method to determine the text view's
|
|
|
|
preferred type of data and then reads the data using the
|
2000-02-19 00:40:47 +00:00
|
|
|
readSelectionFromPasteboard: type: method. Returns YES if the
|
1999-07-24 22:24:14 +00:00
|
|
|
data was successfully read.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return NO;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1998-08-20 09:56:26 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) readSelectionFromPasteboard: (NSPasteboard*)pboard
|
|
|
|
type: (NSString*)type
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
1998-09-01 13:23:23 +00:00
|
|
|
|
1999-07-24 22:24:14 +00:00
|
|
|
return NO;
|
1998-08-19 09:00:26 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSArray*) readablePasteboardTypes
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
// get default types, what are they?
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSArray*) writablePasteboardTypes
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
// the selected text can be written to the pasteboard with which types.
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) writeSelectionToPasteboard: (NSPasteboard*)pboard
|
|
|
|
type: (NSString*)type
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
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 NO;
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) writeSelectionToPasteboard: (NSPasteboard*)pboard
|
|
|
|
types: (NSArray*)types
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
/* 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. */
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) alignJustified: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
if (!tv_richText)
|
|
|
|
// if plain all text is jsutified.
|
|
|
|
else
|
|
|
|
// selected range is fully justified.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) changeColor: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
// NSColor *aColor = [sender color];
|
1998-09-01 13:23:23 +00:00
|
|
|
|
1999-07-24 22:24:14 +00:00
|
|
|
// sets the color for the selected range.
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setAlignment: (NSTextAlignment)alignment
|
|
|
|
range: (NSRange)aRange
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Sets the alignment of the paragraphs containing characters in aRange to
|
2000-02-19 00:40:47 +00:00
|
|
|
alignment. alignment is one of:
|
1999-07-24 22:24:14 +00:00
|
|
|
|
|
|
|
NSLeftTextAlignment
|
|
|
|
NSRightTextAlignment
|
|
|
|
NSCenterTextAlignment
|
|
|
|
NSJustifiedTextAlignment
|
|
|
|
NSNaturalTextAlignment
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setTypingAttributes: (NSDictionary*)attributes
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
// more?
|
1998-09-01 13:23:23 +00:00
|
|
|
|
1999-07-24 22:24:14 +00:00
|
|
|
ASSIGN(tv_typingAttributes, attributes);
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSDictionary*) typingAttributes
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
return tv_typingAttributes;
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) useStandardKerning: (id)sender
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
// rekern for selected range if rich text, else rekern entire document.
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) lowerBaseline: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
if (tv_richText)
|
|
|
|
// lower baseline by one point for selected text
|
|
|
|
else
|
|
|
|
// lower baseline for entire document.
|
|
|
|
*/
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) raiseBaseline: (id)sender
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
/*
|
|
|
|
if (tv_richText)
|
|
|
|
// raise baseline by one point for selected text
|
|
|
|
else
|
|
|
|
// raise baseline for entire document.
|
|
|
|
*/
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) turnOffKerning: (id)sender
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
/*
|
|
|
|
if (tv_richText)
|
|
|
|
// turn off kerning in selection.
|
|
|
|
else
|
|
|
|
// turn off kerning document wide.
|
|
|
|
*/
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) loosenKerning: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
if (tv_richText)
|
|
|
|
// loosen kerning in selection.
|
|
|
|
else
|
|
|
|
// loosen kerning document wide.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) tightenKerning: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
if (tv_richText)
|
|
|
|
// tighten kerning in selection.
|
|
|
|
else
|
|
|
|
// tighten kerning document wide.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) useStandardLigatures: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
// well.
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) turnOffLigatures: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
// sure.
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) useAllLigatures: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
// as you say.
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) clickedOnLink: (id)link
|
|
|
|
atIndex: (unsigned int)charIndex
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
/* Notifies the delegate that the user clicked in a link at the specified
|
|
|
|
charIndex. The delegate may take any appropriate actions to handle the
|
2000-02-19 00:40:47 +00:00
|
|
|
click in its textView: clickedOnLink: atIndex: method.Notifies the delegate
|
1999-07-24 22:24:14 +00:00
|
|
|
that the user clicked in a link at the specified charIndex. The delegate
|
|
|
|
may take any appropriate actions to handle the click in its
|
2000-02-19 00:40:47 +00:00
|
|
|
textView: clickedOnLink: atIndex: method. */
|
1999-07-24 22:24:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
The text is inserted at the insertion point if there is one, otherwise
|
|
|
|
replacing the selection.
|
|
|
|
*/
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) pasteAsPlainText: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
[self insertText: [sender string]];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) pasteAsRichText: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
[self insertText: [sender string]];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) updateFontPanel
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
// [fontPanel setFont: [self fontFromRange]];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) updateRuler
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
// ruler!
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSArray*) acceptableDragTypes
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) updateDragTypeRegistration
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSRange) selectionRangeForProposedRange: (NSRange)proposedSelRange
|
|
|
|
granularity: (NSSelectionGranularity)granularity
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
NSRange retRange;
|
|
|
|
|
|
|
|
switch (granularity)
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
case NSSelectByParagraph:
|
1999-07-24 22:24:14 +00:00
|
|
|
// we need to: 1, find how far to end of paragraph; 2, increase
|
|
|
|
// range.
|
2000-02-19 00:40:47 +00:00
|
|
|
case NSSelectByWord:
|
1999-07-24 22:24:14 +00:00
|
|
|
// we need to: 1, find how far to end of word; 2, increase range.
|
2000-02-19 00:40:47 +00:00
|
|
|
case NSSelectByCharacter:
|
|
|
|
default:
|
1999-07-24 22:24:14 +00:00
|
|
|
retRange = proposedSelRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retRange;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSRange) rangeForUserCharacterAttributeChange
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
if (!tv_editable || !tv_usesFontPanel)
|
|
|
|
return NSMakeRange(NSNotFound, 0);
|
|
|
|
|
|
|
|
if (tv_richText)
|
|
|
|
return tv_selectedRange;
|
|
|
|
else
|
|
|
|
return NSMakeRange(NSNotFound, 0); // should be entire contents.
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSRange) rangeForUserParagraphAttributeChange
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
if (!tv_editable)
|
|
|
|
return NSMakeRange(NSNotFound, 0);
|
|
|
|
|
|
|
|
if (tv_richText)
|
2000-02-19 00:40:47 +00:00
|
|
|
return [self selectionRangeForProposedRange: tv_selectedRange
|
|
|
|
granularity: NSSelectByParagraph];
|
1999-07-24 22:24:14 +00:00
|
|
|
else
|
|
|
|
return NSMakeRange(NSNotFound, 0); // should be entire contents.
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSRange) rangeForUserTextChange
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
if (!tv_editable || !tv_usesRuler)
|
|
|
|
return NSMakeRange(NSNotFound, 0);
|
|
|
|
|
|
|
|
return tv_selectedRange;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) shouldChangeTextInRange: (NSRange)affectedCharRange
|
|
|
|
replacementString: (NSString*)replacementString
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
/*
|
|
|
|
This method checks with the delegate as needed using
|
|
|
|
textShouldBeginEditing: and
|
2000-02-19 00:40:47 +00:00
|
|
|
textView: shouldChangeTextInRange: replacementString: , returning YES to
|
1999-07-24 22:24:14 +00:00
|
|
|
allow the change, and NO to prohibit it.
|
|
|
|
|
|
|
|
This method must be invoked at the start of any sequence of user-initiated
|
|
|
|
editing changes. If your subclass of NSTextView implements new methods
|
|
|
|
that modify the text, make sure to invoke this method to determine whether
|
|
|
|
the change should be made. If the change is allowed, complete the change
|
|
|
|
by invoking the didChangeText method. See Notifying About Changes to the
|
|
|
|
Text in the class description for more information. If you can't determine
|
|
|
|
the affected range or replacement string before beginning changes, pass
|
|
|
|
(NSNotFound, 0) and nil for these values. */
|
|
|
|
|
|
|
|
return NO;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) didChangeText
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
2000-02-19 00:40:47 +00:00
|
|
|
postNotificationName: NSTextDidChangeNotification object: self];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setSmartInsertDeleteEnabled: (BOOL)flag
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
tv_smartInsertDelete = flag;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) smartInsertDeleteEnabled
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
return tv_smartInsertDelete;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSRange) smartDeleteRangeForProposedRange: (NSRange)proposedCharRange
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
// FIXME.
|
|
|
|
return proposedCharRange;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) smartInsertForString: (NSString*)aString
|
|
|
|
replacingRange: (NSRange)charRange
|
|
|
|
beforeString: (NSString*)beforeString
|
|
|
|
afterString: (NSString*)afterString
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
|
|
|
|
/* Determines whether whitespace needs to be added around aString to
|
|
|
|
preserve proper spacing and punctuation when it's inserted into the
|
|
|
|
receiver's text over charRange. Returns by reference in beforeString and
|
|
|
|
afterString any whitespace that should be added, unless either or both is
|
|
|
|
nil. Both are returned as nil if aString is nil or if smart insertion and
|
|
|
|
deletion is disabled.
|
|
|
|
|
|
|
|
As part of its implementation, this method calls
|
2000-02-19 00:40:47 +00:00
|
|
|
smartInsertAfterStringForString: replacingRange: and
|
|
|
|
smartInsertBeforeStringForString: replacingRange: .To change this method's
|
1999-07-24 22:24:14 +00:00
|
|
|
behavior, override those two methods instead of this one.
|
|
|
|
|
|
|
|
NSTextView uses this method as necessary. You can also use it in
|
|
|
|
implementing your own methods that insert text. To do so, invoke this
|
|
|
|
method with the proper arguments, then insert beforeString, aString, and
|
|
|
|
afterString in order over charRange. */
|
|
|
|
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) resignFirstResponder
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
/*
|
|
|
|
if (nextRsponder == NSTextView_in_NSLayoutManager)
|
|
|
|
return YES;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (![self textShouldEndEditing])
|
|
|
|
return NO;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
2000-02-19 00:40:47 +00:00
|
|
|
postNotificationName: NSTextDidEndEditingNotification object: self];
|
1999-07-24 22:24:14 +00:00
|
|
|
// [self hideSelection];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
return YES;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) becomeFirstResponder
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
/*
|
|
|
|
if (!nextRsponder == NSTextView_in_NSLayoutManager)
|
|
|
|
{
|
|
|
|
//draw selection
|
|
|
|
//update the insertion point
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
return YES;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (id) validRequestorForSendType: (NSString*)sendType
|
|
|
|
returnType: (NSString*)returnType
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Returns self if sendType specifies a type of data the text view can put on
|
|
|
|
the pasteboard and returnType contains a type of data the text view can
|
|
|
|
read from the pasteboard; otherwise returns nil.
|
|
|
|
*/
|
1998-09-01 13:23:23 +00:00
|
|
|
|
1999-07-24 22:24:14 +00:00
|
|
|
return nil;
|
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (int) spellCheckerDocumentTag
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
/*
|
|
|
|
if (!tv_spellTag)
|
|
|
|
tv_spellTag = [[NSSpellingServer sharedServer] uniqueSpellDocumentTag];
|
|
|
|
*/
|
|
|
|
return tv_spellTag;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) rulerView: (NSRulerView*)aRulerView
|
|
|
|
didMoveMarker: (NSRulerMarker*)aMarker
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
/*
|
|
|
|
NSTextView checks for permission to make the change in its
|
2000-02-19 00:40:47 +00:00
|
|
|
rulerView: shouldMoveMarker: method, which invokes
|
|
|
|
shouldChangeTextInRange: replacementString: to send out the proper request
|
1999-07-24 22:24:14 +00:00
|
|
|
and notifications, and only invokes this
|
|
|
|
method if permission is granted.
|
|
|
|
|
|
|
|
[self didChangeText];
|
|
|
|
*/
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) rulerView: (NSRulerView*)aRulerView
|
|
|
|
didRemoveMarker: (NSRulerMarker*)aMarker
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
/*
|
|
|
|
NSTextView checks for permission to move or remove a tab stop in its
|
2000-02-19 00:40:47 +00:00
|
|
|
rulerView: shouldMoveMarker: method, which invokes
|
|
|
|
shouldChangeTextInRange: replacementString: to send out the proper request
|
1999-07-24 22:24:14 +00:00
|
|
|
and notifications, and only invokes this method if permission is granted.
|
|
|
|
*/
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) rulerView: (NSRulerView*)aRulerView
|
|
|
|
handleMouseDown: (NSEvent*)theEvent
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
/*
|
|
|
|
This NSRulerView client method adds a left tab marker to the ruler, but a
|
|
|
|
subclass can override this method to provide other behavior, such as
|
|
|
|
creating guidelines. This method is invoked once with theEvent when the
|
|
|
|
user first clicks in the aRulerView's ruler area, as described in the
|
|
|
|
NSRulerView class specification.
|
|
|
|
*/
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) rulerView: (NSRulerView*)aRulerView
|
|
|
|
shouldAddMarker: (NSRulerMarker*)aMarker
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
1998-09-01 13:23:23 +00:00
|
|
|
|
1999-07-24 22:24:14 +00:00
|
|
|
/* This NSRulerView client method controls whether a new tab stop can be
|
|
|
|
added. The receiver checks for permission to make the change by invoking
|
2000-02-19 00:40:47 +00:00
|
|
|
shouldChangeTextInRange: replacementString: and returning the return value
|
1999-07-24 22:24:14 +00:00
|
|
|
of that message. If the change is allowed, the receiver is then sent a
|
2000-02-19 00:40:47 +00:00
|
|
|
rulerView: didAddMarker: message. */
|
1999-07-24 22:24:14 +00:00
|
|
|
|
|
|
|
return NO;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) rulerView: (NSRulerView*)aRulerView
|
|
|
|
shouldMoveMarker: (NSRulerMarker*)aMarker
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
/* This NSRulerView client method controls whether an existing tab stop
|
|
|
|
can be moved. The receiver checks for permission to make the change by
|
2000-02-19 00:40:47 +00:00
|
|
|
invoking shouldChangeTextInRange: replacementString: and returning the
|
1999-07-24 22:24:14 +00:00
|
|
|
return value of that message. If the change is allowed, the receiver is
|
2000-02-19 00:40:47 +00:00
|
|
|
then sent a rulerView: didAddMarker: message. */
|
1999-07-24 22:24:14 +00:00
|
|
|
|
|
|
|
return NO;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) rulerView: (NSRulerView*)aRulerView
|
|
|
|
shouldRemoveMarker: (NSRulerMarker*)aMarker
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
|
|
|
|
/* This NSRulerView client method controls whether an existing tab stop
|
|
|
|
can be removed. Returns YES if aMarker represents an NSTextTab, NO
|
|
|
|
otherwise. Because this method can be invoked repeatedly as the user drags
|
|
|
|
a ruler marker, it returns that value immediately. If the change is allows
|
|
|
|
and the user actually removes the marker, the receiver is also sent a
|
2000-02-19 00:40:47 +00:00
|
|
|
rulerView: didRemoveMarker: message. */
|
1999-07-24 22:24:14 +00:00
|
|
|
|
|
|
|
return NO;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (float) rulerView: (NSRulerView*)aRulerView
|
|
|
|
willAddMarker: (NSRulerMarker*)aMarker
|
|
|
|
atLocation: (float)location
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
|
|
|
|
/* This NSRulerView client method ensures that the proposed location of
|
|
|
|
aMarker lies within the appropriate bounds for the receiver's text
|
|
|
|
container, returning the modified location. */
|
|
|
|
|
|
|
|
return 0.0;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (float) rulerView: (NSRulerView*)aRulerView
|
|
|
|
willMoveMarker: (NSRulerMarker*)aMarker
|
|
|
|
toLocation: (float)location
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
1999-07-24 22:24:14 +00:00
|
|
|
|
|
|
|
/* This NSRulerView client method ensures that the proposed location of
|
|
|
|
aMarker lies within the appropriate bounds for the receiver's text
|
|
|
|
container, returning the modified location. */
|
|
|
|
|
|
|
|
return 0.0;
|
1998-08-20 09:56:26 +00:00
|
|
|
}
|
|
|
|
|
1999-02-17 09:13:43 +00:00
|
|
|
- (void) setDelegate: (id) anObject
|
|
|
|
{
|
1999-06-22 23:37:24 +00:00
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
1999-07-24 22:24:14 +00:00
|
|
|
|
1999-02-17 09:13:43 +00:00
|
|
|
[super setDelegate: anObject];
|
1999-06-22 23:37:24 +00:00
|
|
|
|
1999-02-17 09:13:43 +00:00
|
|
|
#define SET_DELEGATE_NOTIFICATION(notif_name) \
|
2000-02-19 00:40:47 +00:00
|
|
|
if ([delegate respondsToSelector: @selector(textView##notif_name: )]) \
|
1999-02-17 09:13:43 +00:00
|
|
|
[nc addObserver: delegate \
|
2000-02-19 00:40:47 +00:00
|
|
|
selector: @selector(textView##notif_name: ) \
|
1999-06-22 23:37:24 +00:00
|
|
|
name: NSTextView##notif_name##Notification \
|
|
|
|
object: self]
|
|
|
|
|
1999-02-17 09:13:43 +00:00
|
|
|
SET_DELEGATE_NOTIFICATION(DidChangeSelection);
|
|
|
|
SET_DELEGATE_NOTIFICATION(WillChangeNotifyingTextView);
|
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setString: (NSString*)string
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
NSAttributedString *aString;
|
|
|
|
|
|
|
|
aString = [NSAttributedString alloc];
|
|
|
|
aString = [aString initWithString: string
|
|
|
|
attributes: [self typingAttributes]];
|
|
|
|
AUTORELEASE(aString);
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
// [textStorage replaceRange: NSMakeRange(0, [string length])
|
|
|
|
// withString: aString];
|
1999-08-19 23:18:25 +00:00
|
|
|
|
|
|
|
[textStorage setAttributedString: aString];
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
//replaceCharactersInRange: NSMakeRange(0, [string length])
|
1999-08-19 23:18:25 +00:00
|
|
|
// withAttributedString: aString];
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
// [textStorage insertAttributedString: aString atIndex: 0];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setText: (NSString*)string
|
|
|
|
{
|
|
|
|
[self setString: string];
|
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) insertText: (NSString*)aString
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
1999-09-09 02:56:20 +00:00
|
|
|
NSDebugLLog(@"NSText", @"%@", aString);
|
1999-07-25 03:34:10 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
if (![aString isKindOfClass: [NSAttributedString class]])
|
|
|
|
aString = [[NSAttributedString alloc] initWithString: aString
|
|
|
|
attributes: [self typingAttributes]];
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
[textStorage replaceCharactersInRange: [self selectedRange]
|
|
|
|
withAttributedString: (NSAttributedString*)aString];
|
1999-07-25 03:34:10 +00:00
|
|
|
|
1999-09-07 08:59:35 +00:00
|
|
|
[self sizeToFit]; // ScrollView interaction
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
[self setSelectedRange: NSMakeRange([self
|
1999-07-25 03:34:10 +00:00
|
|
|
selectedRange].location+[aString length],0)];
|
|
|
|
|
1999-09-07 08:59:35 +00:00
|
|
|
[self display];
|
2000-01-10 02:30:45 +00:00
|
|
|
[_window update];
|
1999-09-07 08:59:35 +00:00
|
|
|
|
1999-07-25 03:34:10 +00:00
|
|
|
NSLog(@"%@", [textStorage string]);
|
2000-02-19 00:40:47 +00:00
|
|
|
/*
|
|
|
|
* broadcast notification
|
|
|
|
*/
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
postNotificationName: NSTextDidChangeNotification
|
|
|
|
object: self];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) sizeToFit
|
1999-09-07 08:59:35 +00:00
|
|
|
{
|
|
|
|
NSLog(@"sizeToFit called.\n");
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) drawRect: (NSRect)aRect
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
NSRange glyphRange;
|
|
|
|
|
|
|
|
if (tv_backGroundColor)
|
1999-08-19 23:18:25 +00:00
|
|
|
{
|
|
|
|
[tv_backGroundColor set];
|
2000-02-19 00:40:47 +00:00
|
|
|
NSRectFill(aRect);
|
|
|
|
}
|
|
|
|
glyphRange = [layoutManager glyphRangeForTextContainer: textContainer];
|
|
|
|
if (glyphRange.length > 0)
|
|
|
|
{
|
|
|
|
[layoutManager drawGlyphsForGlyphRange: glyphRange
|
|
|
|
atPoint: [self frame].origin];
|
1999-08-19 23:18:25 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
1997-12-04 01:58:57 +00:00
|
|
|
@end
|