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/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/NSControl.h>
|
1998-09-01 13:23:23 +00:00
|
|
|
#include <AppKit/NSLayoutManager.h>
|
|
|
|
#include <AppKit/NSTextStorage.h>
|
2000-05-23 22:59:36 +00:00
|
|
|
#include <AppKit/NSColorPanel.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
|
|
|
{
|
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-05-23 22:59:36 +00:00
|
|
|
NSArray *types;
|
2000-02-19 00:40:47 +00:00
|
|
|
|
2000-05-23 22:59:36 +00:00
|
|
|
types = [NSArray arrayWithObjects: NSStringPboardType, NSRTFPboardType, NSRTFDPboardType, nil];
|
2000-02-19 00:40:47 +00:00
|
|
|
|
2000-05-23 22:59:36 +00:00
|
|
|
[[NSApplication sharedApplication] registerServicesMenuSendTypes: types
|
|
|
|
returnTypes: types];
|
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];
|
2000-05-23 22:59:36 +00:00
|
|
|
[self setUsesFontPanel: YES];
|
|
|
|
[self setUsesRuler: 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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
NSTextContainer *aTextContainer =
|
|
|
|
[[NSTextContainer alloc] initWithContainerSize: frameRect.size];
|
|
|
|
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
|
1999-07-15 17:32:38 +00:00
|
|
|
|
2000-05-13 14:28:02 +00:00
|
|
|
[layoutManager addTextContainer: aTextContainer];
|
|
|
|
RELEASE(aTextContainer);
|
1999-08-19 23:18:25 +00:00
|
|
|
|
2000-05-13 14:28:02 +00:00
|
|
|
_textStorage = [[NSTextStorage alloc] init];
|
|
|
|
[_textStorage addLayoutManager: layoutManager];
|
2000-02-19 00:40:47 +00:00
|
|
|
RELEASE(layoutManager);
|
1999-06-30 03:10:38 +00:00
|
|
|
|
2000-05-13 14:28:02 +00:00
|
|
|
return [self initWithFrame: frameRect textContainer: aTextContainer];
|
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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
ASSIGN(_textContainer, aTextContainer);
|
2000-05-23 22:59:36 +00:00
|
|
|
// FIXME: Could also get a reference to the layout manager
|
|
|
|
ASSIGN(_textStorage, [[aTextContainer layoutManager] textStorage]);
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
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
|
|
|
{
|
2000-05-13 14:28:02 +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
|
|
|
|
2000-05-13 14:28:02 +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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
_textContainerInset = inset;
|
2000-06-16 17:12:25 +00:00
|
|
|
[self invalidateTextContainerOrigin];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
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
|
|
|
{
|
2000-05-13 14:28:02 +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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _textContainerOrigin;
|
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) invalidateTextContainerOrigin
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
// recompute the textContainerOrigin
|
|
|
|
// use bounds, inset, and used rect.
|
2000-06-16 17:12:25 +00:00
|
|
|
/*
|
|
|
|
NSRect bRect = [self bounds];
|
|
|
|
NSRect uRect = [[self layoutManager] usedRectForTextContainer: _textContainer];
|
|
|
|
|
|
|
|
if ([self isFlipped])
|
|
|
|
_textContainerOrigin = ;
|
|
|
|
else
|
|
|
|
_textContainerOrigin = ;
|
|
|
|
*/
|
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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return [_textContainer layoutManager];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _textStorage;
|
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) setBackgroundColor: (NSColor*)aColor
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
ASSIGN(_background_color, 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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _background_color;
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
1998-09-01 13:23:23 +00:00
|
|
|
|
2000-06-29 14:25:07 +00:00
|
|
|
- (void) setAllowsUndo: (BOOL)flag
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) allowsUndo
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setDrawsBackground: (BOOL)flag
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
_tf.draws_background = flag;
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _tf.draws_background;
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return [super shouldDrawInsertionPoint];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
[super drawInsertionPointInRect: aRect
|
|
|
|
color: aColor
|
|
|
|
turnedOn: flag];
|
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-06-16 17:12:25 +00:00
|
|
|
- (unsigned int) dragOperationForDraggingInfo: (id <NSDraggingInfo>)dragInfo
|
|
|
|
type: (NSString *)type
|
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
return NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setEditable: (BOOL)flag
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
|
|
|
if (flag)
|
2000-05-13 14:28:02 +00:00
|
|
|
_tf.is_selectable = flag;
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-05-13 14:28:02 +00:00
|
|
|
_tf.is_editable = flag;
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) isEditable
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _tf.is_editable;
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setSelectable: (BOOL)flag
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
_tf.is_selectable = flag;
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (BOOL) isSelectable
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _tf.is_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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
_tf.is_field_editor = flag;
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _tf.is_field_editor;
|
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)
|
2000-05-13 14:28:02 +00:00
|
|
|
_tf.imports_graphics = flag;
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-05-13 14:28:02 +00:00
|
|
|
_tf.is_rich_text = flag;
|
2000-05-23 22:59:36 +00:00
|
|
|
[self updateDragTypeRegistration];
|
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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _tf.is_rich_text;
|
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)
|
2000-05-13 14:28:02 +00:00
|
|
|
_tf.is_rich_text = flag;
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-05-13 14:28:02 +00:00
|
|
|
_tf.imports_graphics = flag;
|
2000-05-23 22:59:36 +00:00
|
|
|
[self updateDragTypeRegistration];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _tf.imports_graphics;
|
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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
_tf.uses_font_panel = 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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _tf.uses_font_panel;
|
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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
_tf.uses_ruler = 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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _tf.uses_ruler;
|
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
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
[super setRulerVisible: 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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _tf.is_ruler_visible;
|
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
|
|
|
*/
|
2000-05-13 14:28:02 +00:00
|
|
|
_selected_range = 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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _selected_range;
|
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) setSelectedRange: (NSRange)charRange
|
|
|
|
affinity: (NSSelectionAffinity)affinity
|
|
|
|
stillSelecting: (BOOL)flag
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
// Use affinity to determine the insertion point
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-05-20 16:57:04 +00:00
|
|
|
if (flag)
|
|
|
|
{
|
|
|
|
_selected_range = charRange;
|
|
|
|
[self setSelectionGranularity: NSSelectByCharacter];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[self setSelectedRange: charRange];
|
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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
_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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
ASSIGN(_caret_color, 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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _caret_color;
|
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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
// _caretLocation =
|
1999-07-24 22:24:14 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
ASSIGN(_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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
ASSIGN(_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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _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
|
|
|
{
|
2000-05-23 22:59:36 +00:00
|
|
|
return [super preferredPasteboardTypeFromArray: availableTypes
|
|
|
|
restrictedToTypesFromArray: allowedTypes];
|
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.
|
|
|
|
*/
|
2000-05-23 22:59:36 +00:00
|
|
|
return [super readSelectionFromPasteboard: pboard];
|
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
|
|
|
|
2000-05-23 22:59:36 +00:00
|
|
|
return [super readSelectionFromPasteboard: pboard
|
|
|
|
type: type];
|
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?
|
2000-05-23 22:59:36 +00:00
|
|
|
return [super readablePasteboardTypes];
|
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-05-23 22:59:36 +00:00
|
|
|
return [super writablePasteboardTypes];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2000-05-23 22:59:36 +00:00
|
|
|
return [super writeSelectionToPasteboard: pboard
|
|
|
|
type: type];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
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. */
|
2000-05-23 22:59:36 +00:00
|
|
|
return [super writeSelectionToPasteboard: pboard
|
|
|
|
types: types];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) alignJustified: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
[self setAlignment: NSJustifiedTextAlignment
|
|
|
|
range: [self rangeForUserParagraphAttributeChange]];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) changeColor: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
NSColor *aColor = (NSColor*)[sender color];
|
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
|
|
|
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
return;
|
1998-09-01 13:23:23 +00:00
|
|
|
|
1999-07-24 22:24:14 +00:00
|
|
|
// sets the color for the selected range.
|
2000-05-20 16:57:04 +00:00
|
|
|
[self setTextColor: aColor
|
|
|
|
range: aRange];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setAlignment: (NSTextAlignment)alignment
|
|
|
|
range: (NSRange)aRange
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
[super setAlignment: alignment
|
|
|
|
range: aRange];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setTypingAttributes: (NSDictionary*)attributes
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
[super setTypingAttributes: attributes];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
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
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
return [super typingAttributes];
|
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) 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.
|
2000-05-20 16:57:04 +00:00
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
|
|
|
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
replacementString: nil])
|
|
|
|
return;
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
[_textStorage removeAttribute: NSKernAttributeName
|
|
|
|
range: aRange];
|
|
|
|
[_textStorage endEditing];
|
|
|
|
[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) lowerBaseline: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
id value;
|
|
|
|
float sValue;
|
|
|
|
NSRange effRange;
|
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
|
|
|
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
replacementString: nil])
|
|
|
|
return;
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
// We take the value form the first character and use it for the whole range
|
|
|
|
value = [_textStorage attribute: NSBaselineOffsetAttributeName
|
|
|
|
atIndex: aRange.location
|
|
|
|
effectiveRange: &effRange];
|
|
|
|
|
|
|
|
if (value != nil)
|
|
|
|
sValue = [value floatValue] + 1.0;
|
1999-07-24 22:24:14 +00:00
|
|
|
else
|
2000-05-20 16:57:04 +00:00
|
|
|
sValue = 1.0;
|
|
|
|
|
|
|
|
[_textStorage addAttribute: NSBaselineOffsetAttributeName
|
|
|
|
value: [NSNumber numberWithFloat: sValue]
|
|
|
|
range: aRange];
|
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
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
id value;
|
|
|
|
float sValue;
|
|
|
|
NSRange effRange;
|
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
|
|
|
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
replacementString: nil])
|
|
|
|
return;
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
// We take the value form the first character and use it for the whole range
|
|
|
|
value = [_textStorage attribute: NSBaselineOffsetAttributeName
|
|
|
|
atIndex: aRange.location
|
|
|
|
effectiveRange: &effRange];
|
|
|
|
|
|
|
|
if (value != nil)
|
|
|
|
sValue = [value floatValue] - 1.0;
|
1999-07-24 22:24:14 +00:00
|
|
|
else
|
2000-05-20 16:57:04 +00:00
|
|
|
sValue = -1.0;
|
|
|
|
|
|
|
|
[_textStorage addAttribute: NSBaselineOffsetAttributeName
|
|
|
|
value: [NSNumber numberWithFloat: sValue]
|
|
|
|
range: aRange];
|
|
|
|
[_textStorage endEditing];
|
|
|
|
[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) turnOffKerning: (id)sender
|
1998-09-01 13:23:23 +00:00
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
|
|
|
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
replacementString: nil])
|
|
|
|
return;
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
[_textStorage addAttribute: NSKernAttributeName
|
|
|
|
value: [NSNumber numberWithFloat: 0.0]
|
|
|
|
range: aRange];
|
|
|
|
[_textStorage endEditing];
|
|
|
|
[self didChangeText];
|
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
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
|
|
|
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
replacementString: nil])
|
|
|
|
return;
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
// FIXME: Should use the current kerning and work relative to point size
|
|
|
|
[_textStorage addAttribute: NSKernAttributeName
|
|
|
|
value: [NSNumber numberWithFloat: 1.0]
|
|
|
|
range: aRange];
|
|
|
|
[_textStorage endEditing];
|
|
|
|
[self didChangeText];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) tightenKerning: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
|
|
|
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
replacementString: nil])
|
|
|
|
return;
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
// FIXME: Should use the current kerning and work relative to point size
|
|
|
|
[_textStorage addAttribute: NSKernAttributeName
|
|
|
|
value: [NSNumber numberWithFloat: -1.0]
|
|
|
|
range: aRange];
|
|
|
|
[_textStorage endEditing];
|
|
|
|
[self didChangeText];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) useStandardLigatures: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
|
|
|
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
replacementString: nil])
|
|
|
|
return;
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
[_textStorage addAttribute: NSLigatureAttributeName
|
|
|
|
value: [NSNumber numberWithInt: 1]
|
|
|
|
range: aRange];
|
|
|
|
[_textStorage endEditing];
|
|
|
|
[self didChangeText];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) turnOffLigatures: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
|
|
|
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
replacementString: nil])
|
|
|
|
return;
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
[_textStorage addAttribute: NSLigatureAttributeName
|
|
|
|
value: [NSNumber numberWithInt: 0]
|
|
|
|
range: aRange];
|
|
|
|
[_textStorage endEditing];
|
|
|
|
[self didChangeText];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) useAllLigatures: (id)sender
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
|
|
|
|
|
|
|
if (aRange.location == NSNotFound)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (![self shouldChangeTextInRange: aRange
|
|
|
|
replacementString: nil])
|
|
|
|
return;
|
|
|
|
[_textStorage beginEditing];
|
|
|
|
[_textStorage addAttribute: NSLigatureAttributeName
|
|
|
|
value: [NSNumber numberWithInt: 2]
|
|
|
|
range: aRange];
|
|
|
|
[_textStorage endEditing];
|
|
|
|
[self didChangeText];
|
1999-07-24 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
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-06-16 17:12:25 +00:00
|
|
|
click in its textView: clickedOnLink: atIndex: method. */
|
|
|
|
if (_delegate != nil &&
|
|
|
|
[_delegate respondsToSelector: @selector(textView:clickedOnLink:atIndex:)])
|
|
|
|
[_delegate textView: self clickedOnLink: link atIndex: charIndex];
|
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-05-23 22:59:36 +00:00
|
|
|
[self readSelectionFromPasteboard: [NSPasteboard generalPasteboard]
|
|
|
|
type: NSStringPboardType];
|
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-05-23 22:59:36 +00:00
|
|
|
[self readSelectionFromPasteboard: [NSPasteboard generalPasteboard]
|
|
|
|
type: NSRTFPboardType];
|
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-05-20 16:57:04 +00:00
|
|
|
[super updateFontPanel];
|
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-05-23 22:59:36 +00:00
|
|
|
return [self readablePasteboardTypes];
|
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-05-23 22:59:36 +00:00
|
|
|
// FIXME: Should change registration for all our text views
|
|
|
|
if (_tf.is_editable && _tf.is_rich_text)
|
|
|
|
[self registerForDraggedTypes: [self acceptableDragTypes]];
|
|
|
|
else
|
|
|
|
[self unregisterDraggedTypes];
|
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
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
return [super selectionRangeForProposedRange: proposedSelRange
|
|
|
|
granularity: granularity];
|
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
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
return [super rangeForUserCharacterAttributeChange];
|
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
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
return [super rangeForUserParagraphAttributeChange];
|
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
|
|
|
{
|
2000-05-20 16:57:04 +00:00
|
|
|
return [super rangeForUserTextChange];
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-05-23 22:59:36 +00:00
|
|
|
|
|
|
|
- (id) validRequestorForSendType: (NSString*)sendType
|
|
|
|
returnType: (NSString*)returnType
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return [super validRequestorForSendType: sendType
|
|
|
|
returnType: returnType];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) spellCheckerDocumentTag
|
|
|
|
{
|
|
|
|
return [super spellCheckerDocumentTag];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) insertText: (NSString*)aString
|
|
|
|
{
|
|
|
|
[super insertText: aString];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) sizeToFit
|
|
|
|
{
|
|
|
|
[super sizeToFit];
|
|
|
|
}
|
|
|
|
|
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. */
|
|
|
|
|
2000-05-20 16:57:04 +00:00
|
|
|
return YES;
|
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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
_tf.smart_insert_delete = 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
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
return _tf.smart_insert_delete;
|
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
|
|
|
{
|
2000-05-23 22:59:36 +00:00
|
|
|
// FIXME.
|
1999-07-24 22:24:14 +00:00
|
|
|
return proposedCharRange;
|
1998-09-01 13:23:23 +00:00
|
|
|
}
|
|
|
|
|
2000-05-23 22:59:36 +00:00
|
|
|
- (NSString *)smartInsertAfterStringForString: (NSString *)aString
|
|
|
|
replacingRange: (NSRange)charRange
|
|
|
|
{
|
|
|
|
// FIXME.
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)smartInsertBeforeStringForString: (NSString *)aString
|
|
|
|
replacingRange: (NSRange)charRange
|
|
|
|
{
|
|
|
|
// FIXME.
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) smartInsertForString: (NSString*)aString
|
|
|
|
replacingRange: (NSRange)charRange
|
2000-05-23 22:59:36 +00:00
|
|
|
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. */
|
2000-05-23 22:59:36 +00:00
|
|
|
if (beforeString)
|
|
|
|
*beforeString = [self smartInsertBeforeStringForString: aString
|
|
|
|
replacingRange: charRange];
|
1999-07-24 22:24:14 +00:00
|
|
|
|
2000-05-23 22:59:36 +00:00
|
|
|
if (afterString)
|
|
|
|
*afterString = [self smartInsertAfterStringForString: aString
|
|
|
|
replacingRange: 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
|
|
|
- (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-05-13 14:28:02 +00:00
|
|
|
- (void)rulerView:(NSRulerView *)ruler
|
|
|
|
didAddMarker:(NSRulerMarker *)marker
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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-03-16 14:16:46 +00:00
|
|
|
if ([_delegate respondsToSelector: @selector(textView##notif_name: )]) \
|
|
|
|
[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) drawRect: (NSRect)aRect
|
1999-07-24 22:24:14 +00:00
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
NSRange glyphRange;
|
2000-05-13 14:28:02 +00:00
|
|
|
NSLayoutManager *layoutManager = [self layoutManager];
|
2000-02-19 00:40:47 +00:00
|
|
|
|
2000-05-13 14:28:02 +00:00
|
|
|
if (_background_color != nil)
|
1999-08-19 23:18:25 +00:00
|
|
|
{
|
2000-05-13 14:28:02 +00:00
|
|
|
[_background_color set];
|
2000-02-19 00:40:47 +00:00
|
|
|
NSRectFill(aRect);
|
|
|
|
}
|
2000-05-13 14:28:02 +00:00
|
|
|
glyphRange = [layoutManager glyphRangeForTextContainer: _textContainer];
|
2000-02-19 00:40:47 +00:00
|
|
|
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
|
2000-05-13 14:28:02 +00:00
|
|
|
|
|
|
|
@implementation NSTextView(NSTextInput)
|
|
|
|
// This are all the NSTextInput methods that are not implemented on NSTextView
|
|
|
|
// or one of its super classes.
|
|
|
|
|
|
|
|
- (void)setMarkedText:(NSString *)aString selectedRange:(NSRange)selRange
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)hasMarkedText
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)unmarkText
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)validAttributesForMarkedText
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (long)conversationIdentifier
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)firstRectForCharacterRange:(NSRange)theRange
|
|
|
|
{
|
|
|
|
return NSZeroRect;
|
|
|
|
}
|
|
|
|
@end
|