mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 20:50:38 +00:00
Added basic code for the character formating methods and call super
implementation for methods that moved up into NSText. Later we may remove the implementation of these methods here. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6603 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
dcc14de701
commit
ef4a38f178
1 changed files with 196 additions and 166 deletions
|
@ -139,7 +139,7 @@
|
||||||
{
|
{
|
||||||
// recompute the textContainerOrigin
|
// recompute the textContainerOrigin
|
||||||
// use bounds, inset, and used rect.
|
// use bounds, inset, and used rect.
|
||||||
NSRect bRect = [self bounds];
|
//NSRect bRect = [self bounds];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSLayoutManager*) layoutManager
|
- (NSLayoutManager*) layoutManager
|
||||||
|
@ -193,26 +193,9 @@
|
||||||
color: (NSColor*)aColor
|
color: (NSColor*)aColor
|
||||||
turnedOn: (BOOL)flag
|
turnedOn: (BOOL)flag
|
||||||
{
|
{
|
||||||
[self lockFocus];
|
[super drawInsertionPointInRect: aRect
|
||||||
|
color: aColor
|
||||||
NSDebugLLog(@"NSText",
|
turnedOn: flag];
|
||||||
@"drawInsertionPointInRect: (%f, %f)", aRect.size.width, aRect.size.height);
|
|
||||||
|
|
||||||
aRect.size.width = 1;
|
|
||||||
|
|
||||||
if (flag)
|
|
||||||
{
|
|
||||||
[aColor set];
|
|
||||||
NSRectFill(aRect);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
[[self backgroundColor] set];
|
|
||||||
NSRectFill(aRect);
|
|
||||||
}
|
|
||||||
|
|
||||||
[self unlockFocus];
|
|
||||||
[_window flushWindow];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setConstrainedFrameSize: (NSSize)desiredSize
|
- (void) setConstrainedFrameSize: (NSSize)desiredSize
|
||||||
|
@ -307,7 +290,7 @@
|
||||||
|
|
||||||
- (void) setRulerVisible: (BOOL)flag
|
- (void) setRulerVisible: (BOOL)flag
|
||||||
{
|
{
|
||||||
_tf.is_ruler_visible = flag;
|
[super setRulerVisible: flag];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) isRulerVisible
|
- (BOOL) isRulerVisible
|
||||||
|
@ -339,12 +322,15 @@
|
||||||
affinity: (NSSelectionAffinity)affinity
|
affinity: (NSSelectionAffinity)affinity
|
||||||
stillSelecting: (BOOL)flag
|
stillSelecting: (BOOL)flag
|
||||||
{
|
{
|
||||||
NSDebugLLog(@"NSText", @"setSelectedRange stillSelecting.");
|
// Use affinity to determine the insertion point
|
||||||
|
|
||||||
_selected_range = charRange;
|
if (flag)
|
||||||
[self setSelectionGranularity: NSSelectByCharacter];
|
{
|
||||||
|
_selected_range = charRange;
|
||||||
// FIXME, more.
|
[self setSelectionGranularity: NSSelectByCharacter];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
[self setSelectedRange: charRange];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSSelectionAffinity) selectionAffinity
|
- (NSSelectionAffinity) selectionAffinity
|
||||||
|
@ -482,121 +468,242 @@ 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
|
method if you are implementing a new type of pasteboard to handle services
|
||||||
other than copy/paste or dragging. */
|
other than copy/paste or dragging. */
|
||||||
|
|
||||||
return NO;
|
NSArray *mytypes;
|
||||||
|
NSString *string;
|
||||||
|
|
||||||
|
if ([types containsObject: NSStringPboardType] == NO)
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
mytypes = [NSArray arrayWithObjects: NSStringPboardType, nil];
|
||||||
|
[pboard declareTypes: mytypes owner: nil];
|
||||||
|
string = [self string];
|
||||||
|
string = [string substringWithRange: _selected_range];
|
||||||
|
return [pboard setString: string forType: NSStringPboardType];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) alignJustified: (id)sender
|
- (void) alignJustified: (id)sender
|
||||||
{
|
{
|
||||||
/*
|
[self setAlignment: NSJustifiedTextAlignment
|
||||||
if (!_tf.is_rich_text)
|
range: [self rangeForUserParagraphAttributeChange]];
|
||||||
// if plain all text is jsutified.
|
|
||||||
else
|
|
||||||
// selected range is fully justified.
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) changeColor: (id)sender
|
- (void) changeColor: (id)sender
|
||||||
{
|
{
|
||||||
// NSColor *aColor = [sender color];
|
NSColor *aColor = (NSColor*)[sender color];
|
||||||
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
||||||
|
|
||||||
|
if (aRange.location == NSNotFound)
|
||||||
|
return;
|
||||||
|
|
||||||
// sets the color for the selected range.
|
// sets the color for the selected range.
|
||||||
|
[self setTextColor: aColor
|
||||||
|
range: aRange];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setAlignment: (NSTextAlignment)alignment
|
- (void) setAlignment: (NSTextAlignment)alignment
|
||||||
range: (NSRange)aRange
|
range: (NSRange)aRange
|
||||||
{
|
{
|
||||||
/*
|
[super setAlignment: alignment
|
||||||
Sets the alignment of the paragraphs containing characters in aRange to
|
range: aRange];
|
||||||
alignment. alignment is one of:
|
|
||||||
|
|
||||||
NSLeftTextAlignment
|
|
||||||
NSRightTextAlignment
|
|
||||||
NSCenterTextAlignment
|
|
||||||
NSJustifiedTextAlignment
|
|
||||||
NSNaturalTextAlignment
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setTypingAttributes: (NSDictionary*)attributes
|
- (void) setTypingAttributes: (NSDictionary*)attributes
|
||||||
{
|
{
|
||||||
// more?
|
[super setTypingAttributes: attributes];
|
||||||
|
|
||||||
ASSIGN(_typingAttributes, attributes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary*) typingAttributes
|
- (NSDictionary*) typingAttributes
|
||||||
{
|
{
|
||||||
return _typingAttributes;
|
return [super typingAttributes];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) useStandardKerning: (id)sender
|
- (void) useStandardKerning: (id)sender
|
||||||
{
|
{
|
||||||
// rekern for selected range if rich text, else rekern entire document.
|
// rekern for selected range if rich text, else rekern entire document.
|
||||||
|
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];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) lowerBaseline: (id)sender
|
- (void) lowerBaseline: (id)sender
|
||||||
{
|
{
|
||||||
/*
|
id value;
|
||||||
if (_tf.is_rich_text)
|
float sValue;
|
||||||
// lower baseline by one point for selected text
|
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;
|
||||||
else
|
else
|
||||||
// lower baseline for entire document.
|
sValue = 1.0;
|
||||||
*/
|
|
||||||
|
[_textStorage addAttribute: NSBaselineOffsetAttributeName
|
||||||
|
value: [NSNumber numberWithFloat: sValue]
|
||||||
|
range: aRange];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) raiseBaseline: (id)sender
|
- (void) raiseBaseline: (id)sender
|
||||||
{
|
{
|
||||||
/*
|
id value;
|
||||||
if (_tf.is_rich_text)
|
float sValue;
|
||||||
// raise baseline by one point for selected text
|
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;
|
||||||
else
|
else
|
||||||
// raise baseline for entire document.
|
sValue = -1.0;
|
||||||
*/
|
|
||||||
|
[_textStorage addAttribute: NSBaselineOffsetAttributeName
|
||||||
|
value: [NSNumber numberWithFloat: sValue]
|
||||||
|
range: aRange];
|
||||||
|
[_textStorage endEditing];
|
||||||
|
[self didChangeText];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) turnOffKerning: (id)sender
|
- (void) turnOffKerning: (id)sender
|
||||||
{
|
{
|
||||||
/*
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
||||||
if (_tf.is_rich_text)
|
|
||||||
// turn off kerning in selection.
|
if (aRange.location == NSNotFound)
|
||||||
else
|
return;
|
||||||
// turn off kerning document wide.
|
|
||||||
*/
|
if (![self shouldChangeTextInRange: aRange
|
||||||
|
replacementString: nil])
|
||||||
|
return;
|
||||||
|
[_textStorage beginEditing];
|
||||||
|
[_textStorage addAttribute: NSKernAttributeName
|
||||||
|
value: [NSNumber numberWithFloat: 0.0]
|
||||||
|
range: aRange];
|
||||||
|
[_textStorage endEditing];
|
||||||
|
[self didChangeText];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) loosenKerning: (id)sender
|
- (void) loosenKerning: (id)sender
|
||||||
{
|
{
|
||||||
/*
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
||||||
if (_tf.is_rich_text)
|
|
||||||
// loosen kerning in selection.
|
if (aRange.location == NSNotFound)
|
||||||
else
|
return;
|
||||||
// loosen kerning document wide.
|
|
||||||
*/
|
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];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) tightenKerning: (id)sender
|
- (void) tightenKerning: (id)sender
|
||||||
{
|
{
|
||||||
/*
|
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
||||||
if (_tf.is_rich_text)
|
|
||||||
// tighten kerning in selection.
|
if (aRange.location == NSNotFound)
|
||||||
else
|
return;
|
||||||
// tighten kerning document wide.
|
|
||||||
*/
|
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];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) useStandardLigatures: (id)sender
|
- (void) useStandardLigatures: (id)sender
|
||||||
{
|
{
|
||||||
// well.
|
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];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) turnOffLigatures: (id)sender
|
- (void) turnOffLigatures: (id)sender
|
||||||
{
|
{
|
||||||
// sure.
|
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];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) useAllLigatures: (id)sender
|
- (void) useAllLigatures: (id)sender
|
||||||
{
|
{
|
||||||
// as you say.
|
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];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) clickedOnLink: (id)link
|
- (void) clickedOnLink: (id)link
|
||||||
|
@ -629,7 +736,7 @@ replacing the selection.
|
||||||
|
|
||||||
- (void) updateFontPanel
|
- (void) updateFontPanel
|
||||||
{
|
{
|
||||||
// [fontPanel setFont: [self fontFromRange]];
|
[super updateFontPanel];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) updateRuler
|
- (void) updateRuler
|
||||||
|
@ -649,52 +756,23 @@ replacing the selection.
|
||||||
- (NSRange) selectionRangeForProposedRange: (NSRange)proposedSelRange
|
- (NSRange) selectionRangeForProposedRange: (NSRange)proposedSelRange
|
||||||
granularity: (NSSelectionGranularity)granularity
|
granularity: (NSSelectionGranularity)granularity
|
||||||
{
|
{
|
||||||
NSRange retRange;
|
return [super selectionRangeForProposedRange: proposedSelRange
|
||||||
|
granularity: granularity];
|
||||||
switch (granularity)
|
|
||||||
{
|
|
||||||
case NSSelectByParagraph:
|
|
||||||
// we need to: 1, find how far to end of paragraph; 2, increase
|
|
||||||
// range.
|
|
||||||
case NSSelectByWord:
|
|
||||||
// we need to: 1, find how far to end of word; 2, increase range.
|
|
||||||
case NSSelectByCharacter:
|
|
||||||
default:
|
|
||||||
retRange = proposedSelRange;
|
|
||||||
}
|
|
||||||
|
|
||||||
return retRange;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSRange) rangeForUserCharacterAttributeChange
|
- (NSRange) rangeForUserCharacterAttributeChange
|
||||||
{
|
{
|
||||||
if (!_tf.is_editable || !_tf.uses_font_panel)
|
return [super rangeForUserCharacterAttributeChange];
|
||||||
return NSMakeRange(NSNotFound, 0);
|
|
||||||
|
|
||||||
if (_tf.is_rich_text)
|
|
||||||
return _selected_range;
|
|
||||||
else
|
|
||||||
return NSMakeRange(NSNotFound, 0); // should be entire contents.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSRange) rangeForUserParagraphAttributeChange
|
- (NSRange) rangeForUserParagraphAttributeChange
|
||||||
{
|
{
|
||||||
if (!_tf.is_editable)
|
return [super rangeForUserParagraphAttributeChange];
|
||||||
return NSMakeRange(NSNotFound, 0);
|
|
||||||
|
|
||||||
if (_tf.is_rich_text)
|
|
||||||
return [self selectionRangeForProposedRange: _selected_range
|
|
||||||
granularity: NSSelectByParagraph];
|
|
||||||
else
|
|
||||||
return NSMakeRange(NSNotFound, 0); // should be entire contents.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSRange) rangeForUserTextChange
|
- (NSRange) rangeForUserTextChange
|
||||||
{
|
{
|
||||||
if (!_tf.is_editable || !_tf.uses_ruler)
|
return [super rangeForUserTextChange];
|
||||||
return NSMakeRange(NSNotFound, 0);
|
|
||||||
|
|
||||||
return _selected_range;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) shouldChangeTextInRange: (NSRange)affectedCharRange
|
- (BOOL) shouldChangeTextInRange: (NSRange)affectedCharRange
|
||||||
|
@ -715,7 +793,7 @@ Text in the class description for more information. If you can't determine
|
||||||
the affected range or replacement string before beginning changes, pass
|
the affected range or replacement string before beginning changes, pass
|
||||||
(NSNotFound, 0) and nil for these values. */
|
(NSNotFound, 0) and nil for these values. */
|
||||||
|
|
||||||
return NO;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) didChangeText
|
- (void) didChangeText
|
||||||
|
@ -942,62 +1020,14 @@ container, returning the modified location. */
|
||||||
SET_DELEGATE_NOTIFICATION(WillChangeNotifyingTextView);
|
SET_DELEGATE_NOTIFICATION(WillChangeNotifyingTextView);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setString: (NSString*)string
|
|
||||||
{
|
|
||||||
NSAttributedString *aString;
|
|
||||||
|
|
||||||
aString = [NSAttributedString alloc];
|
|
||||||
aString = [aString initWithString: string
|
|
||||||
attributes: [self typingAttributes]];
|
|
||||||
AUTORELEASE(aString);
|
|
||||||
|
|
||||||
// [_textStorage replaceRange: NSMakeRange(0, [string length])
|
|
||||||
// withString: aString];
|
|
||||||
|
|
||||||
[_textStorage setAttributedString: aString];
|
|
||||||
|
|
||||||
//replaceCharactersInRange: NSMakeRange(0, [string length])
|
|
||||||
// withAttributedString: aString];
|
|
||||||
|
|
||||||
// [_textStorage insertAttributedString: aString atIndex: 0];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) setText: (NSString*)string
|
|
||||||
{
|
|
||||||
[self setString: string];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) insertText: (NSString*)aString
|
- (void) insertText: (NSString*)aString
|
||||||
{
|
{
|
||||||
NSDebugLLog(@"NSText", @"%@", aString);
|
[super insertText: aString];
|
||||||
|
|
||||||
if (![aString isKindOfClass: [NSAttributedString class]])
|
|
||||||
aString = [[NSAttributedString alloc] initWithString: aString
|
|
||||||
attributes: [self typingAttributes]];
|
|
||||||
|
|
||||||
[_textStorage replaceCharactersInRange: [self selectedRange]
|
|
||||||
withAttributedString: (NSAttributedString*)aString];
|
|
||||||
|
|
||||||
[self sizeToFit]; // ScrollView interaction
|
|
||||||
|
|
||||||
[self setSelectedRange: NSMakeRange([self
|
|
||||||
selectedRange].location+[aString length],0)];
|
|
||||||
|
|
||||||
[self display];
|
|
||||||
[_window update];
|
|
||||||
|
|
||||||
NSLog(@"%@", [_textStorage string]);
|
|
||||||
/*
|
|
||||||
* broadcast notification
|
|
||||||
*/
|
|
||||||
[[NSNotificationCenter defaultCenter]
|
|
||||||
postNotificationName: NSTextDidChangeNotification
|
|
||||||
object: self];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) sizeToFit
|
- (void) sizeToFit
|
||||||
{
|
{
|
||||||
NSLog(@"sizeToFit called.\n");
|
[super sizeToFit];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) drawRect: (NSRect)aRect
|
- (void) drawRect: (NSRect)aRect
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue