Work on drawing insertion point

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@8407 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
nico 2000-12-22 16:57:21 +00:00
parent 5f6e350654
commit b8172d5f2c

View file

@ -125,6 +125,7 @@ static NSNotificationCenter *nc;
- (unsigned) characterIndexForPoint: (NSPoint)point; - (unsigned) characterIndexForPoint: (NSPoint)point;
- (NSRect) rectForCharacterIndex: (unsigned)index; - (NSRect) rectForCharacterIndex: (unsigned)index;
- (NSRect) rectForCharacterRange: (NSRange)aRange; - (NSRect) rectForCharacterRange: (NSRange)aRange;
- (NSRect) rectForInsertionPointAtIndex: (unsigned)index;
/* /*
* various GNU extensions * various GNU extensions
@ -137,10 +138,6 @@ static NSNotificationCenter *nc;
- (void) setAttributes: (NSDictionary *) attributes range: (NSRange) aRange; - (void) setAttributes: (NSDictionary *) attributes range: (NSRange) aRange;
- (void) _illegalMovement: (int) notNumber; - (void) _illegalMovement: (int) notNumber;
- (void) deleteRange: (NSRange)aRange backspace: (BOOL)flag; - (void) deleteRange: (NSRange)aRange backspace: (BOOL)flag;
- (void) drawInsertionPointAtIndex: (unsigned)index
color: (NSColor *)color
turnedOn: (BOOL)flag;
@end @end
@implementation NSTextView @implementation NSTextView
@ -330,7 +327,7 @@ static NSNotificationCenter *nc;
* on the internals of the NSTextView * on the internals of the NSTextView
*/ */
- (void) replaceCharactersInRange: (NSRange)aRange - (void) replaceCharactersInRange: (NSRange)aRange
withString: (NSString*)aString withString: (NSString *)aString
{ {
if (aRange.location == NSNotFound) if (aRange.location == NSNotFound)
return; return;
@ -1132,7 +1129,8 @@ static NSNotificationCenter *nc;
- (void) setNeedsDisplayInRect: (NSRect)aRect - (void) setNeedsDisplayInRect: (NSRect)aRect
avoidAdditionalLayout: (BOOL)flag avoidAdditionalLayout: (BOOL)flag
{ {
// FIXME: This is here until the layout manager is working /* FIXME: This is here until the layout manager is working */
/* This is very important */
[super setNeedsDisplayInRect: aRect]; [super setNeedsDisplayInRect: aRect];
} }
@ -1148,12 +1146,24 @@ static NSNotificationCenter *nc;
return (_selected_range.length == 0) && _tf.is_editable; return (_selected_range.length == 0) && _tf.is_editable;
} }
/*
* It only makes real sense to call this method with `flag == YES'.
* If you want to delete the insertion point, what you want is rather
* to redraw what was under the insertion point - which can't be done
* here - you need to set the rect as needing redisplay (without
* additional layout) instead. NB: You need to flush the window after
* calling this method if you want the insertion point to appear on
* the screen immediately. This could only be needed to implement
* blinking insertion point - but even there, it could probably be
* done without. */
- (void) drawInsertionPointInRect: (NSRect)rect - (void) drawInsertionPointInRect: (NSRect)rect
color: (NSColor*)color color: (NSColor*)color
turnedOn: (BOOL)flag turnedOn: (BOOL)flag
{ {
if (!_window) if (_window == nil)
return; {
return;
}
if (flag) if (flag)
{ {
@ -1161,17 +1171,13 @@ static NSNotificationCenter *nc;
color = _caret_color; color = _caret_color;
[color set]; [color set];
NSRectFill(rect); NSRectFill (rect);
} }
else else
{ {
[_background_color set]; [_background_color set];
NSRectFill(rect); NSRectFill (rect);
// FIXME: We should redisplay the character the cursor was on.
//[self setNeedsDisplayInRect: rect];
} }
[_window flushWindow];
} }
- (void) setConstrainedFrameSize: (NSSize)desiredSize - (void) setConstrainedFrameSize: (NSSize)desiredSize
@ -1350,9 +1356,11 @@ static NSNotificationCenter *nc;
[self setSelectedRange: charRange]; [self setSelectedRange: charRange];
} }
/* Override in subclasses to change the default selection affinity */
- (NSSelectionAffinity) selectionAffinity - (NSSelectionAffinity) selectionAffinity
{ {
return _selectionAffinity; /* FIXME: which one should be the default ? */
return NSSelectionAffinityDownstream;
} }
- (void) setSelectionGranularity: (NSSelectionGranularity)granularity - (void) setSelectionGranularity: (NSSelectionGranularity)granularity
@ -1382,12 +1390,12 @@ static NSNotificationCenter *nc;
// restart blinking timer. // restart blinking timer.
} }
- (void) setSelectedTextAttributes: (NSDictionary*)attributes - (void) setSelectedTextAttributes: (NSDictionary *)attributes
{ {
ASSIGN(_selectedTextAttributes, attributes); ASSIGN (_selectedTextAttributes, attributes);
} }
- (NSDictionary*) selectedTextAttributes - (NSDictionary *) selectedTextAttributes
{ {
return _selectedTextAttributes; return _selectedTextAttributes;
} }
@ -2166,10 +2174,10 @@ afterString in order over charRange. */
if ([self shouldDrawInsertionPoint]) if ([self shouldDrawInsertionPoint])
{ {
[self lockFocus]; NSRect rect;
[self drawInsertionPointAtIndex: _selected_range.location
color: nil turnedOn: NO]; rect = [self rectForInsertionPointAtIndex: _selected_range.location];
[self unlockFocus]; [self setNeedsDisplayInRect: rect avoidAdditionalLayout: YES];
//<!> stop timed entry //<!> stop timed entry
} }
@ -2216,6 +2224,7 @@ afterString in order over charRange. */
- (void) drawRect: (NSRect)rect - (void) drawRect: (NSRect)rect
{ {
/* TODO: Only do relayout if needed */
NSRange drawnRange = [_layoutManager glyphRangeForBoundingRect: rect NSRange drawnRange = [_layoutManager glyphRangeForBoundingRect: rect
inTextContainer: _textContainer]; inTextContainer: _textContainer];
if (_tf.draws_background) if (_tf.draws_background)
@ -2234,7 +2243,10 @@ afterString in order over charRange. */
if (NSLocationInRange (location, drawnRange) if (NSLocationInRange (location, drawnRange)
|| location == NSMaxRange (drawnRange)) || location == NSMaxRange (drawnRange))
{ {
[self drawInsertionPointAtIndex: location color: _caret_color NSRect rect;
rect = [self rectForInsertionPointAtIndex: location];
[self drawInsertionPointInRect: rect color: _caret_color
turnedOn: YES]; turnedOn: YES];
} }
} }
@ -3027,17 +3039,15 @@ other than copy/paste or dragging. */
inTextContainer: _textContainer]; inTextContainer: _textContainer];
} }
- (void) drawInsertionPointAtIndex: (unsigned) index - (NSRect) rectForInsertionPointAtIndex: (unsigned)index
color: (NSColor*) color
turnedOn: (BOOL) flag
{ {
NSRect drawRect = [self rectForCharacterIndex: index]; NSRect rect = [self rectForCharacterIndex: index];
rect.size.width = 1;
drawRect.size.width = 1;
if (drawRect.size.height == 0) if (rect.size.height == 0)
drawRect.size.height = 12; rect.size.height = 12;
[self drawInsertionPointInRect: drawRect color: color turnedOn: flag]; return rect;
} }
@end @end