diff --git a/AppKit/CPText.j b/AppKit/CPText.j index 490053047..09e23ef2f 100644 --- a/AppKit/CPText.j +++ b/AppKit/CPText.j @@ -84,6 +84,18 @@ CPCenterTextAlignment = 2; CPJustifiedTextAlignment = 3; CPNaturalTextAlignment = 4; +@typedef CPUnderlineStyle +CPUnderlineStyleNone = 0; +CPUnderlineStyleSingle = 1; +CPUnderlineStyleThick = 2; +CPUnderlineStyleDouble = 3; +CPUnderlineStylePatternSolid = 4; +CPUnderlineStylePatternDot = 5; +CPUnderlineStylePatternDash = 6; +CPUnderlineStylePatternDashDot = 7; +CPUnderlineStylePatternDashDotDot = 8; +CPUnderlineStyleByWord = 9; + /* CPText notifications */ diff --git a/AppKit/CPTextView/CPLayoutManager.j b/AppKit/CPTextView/CPLayoutManager.j index 7bcffcefc..4343aaa40 100644 --- a/AppKit/CPTextView/CPLayoutManager.j +++ b/AppKit/CPTextView/CPLayoutManager.j @@ -495,16 +495,6 @@ _oncontextmenuhandler = function () { return false; }; } -- (void)drawUnderlineForGlyphRange:(CPRange)glyphRange - underlineType:(int)underlineVal - baselineOffset:(float)baselineOffset - lineFragmentRect:(CGRect)lineFragmentRect - lineFragmentGlyphRange:(CPRange)lineGlyphRange - containerOrigin:(CGPoint)containerOrigin -{ -// FIXME -} - - (void)drawGlyphsForGlyphRange:(CPRange)aRange atPoint:(CGPoint)aPoint { var lineFragments = _objectsInRange(_lineFragments, aRange); @@ -1094,6 +1084,11 @@ var _objectsInRange = function(aList, aRange) #pragma mark Init methods - (id)createDOMElementWithText:(CPString)aString andFont:(CPFont)aFont andColor:(CPColor)aColor +{ + return [self createDOMElementWithText:aString andFont:aFont andColor:aColor andUnderline:nil]; +} + +- (id)createDOMElementWithText:(CPString)aString andFont:(CPFont)aFont andColor:(CPColor)aColor andUnderline:(CPUnderlineStyle)aUnderline { #if PLATFORM(DOM) var style, @@ -1110,6 +1105,30 @@ var _objectsInRange = function(aList, aRange) style.whiteSpace = "pre"; style.backgroundColor = "transparent"; style.font = [aFont cssString]; + + if (aUnderline) + { + style.textDecoration = "underline"; + + switch (aUnderline) + { + case CPUnderlineStyleSingle: + style.textDecorationStyle = "solid"; + break; + + case CPUnderlineStyleDouble: + style.textDecorationStyle = "double"; + break; + + case CPUnderlineStylePatternDot: + style.textDecorationStyle = "dotted"; + break; + + case CPUnderlineStylePatternDash: + style.textDecorationStyle = "dashed"; + break; + } + } if (aColor) style.color = [aColor cssString]; @@ -1148,14 +1167,14 @@ var _objectsInRange = function(aList, aRange) effectiveRange = attributes ? CPIntersectionRange(aRange, effectiveRange) : aRange; var string = [textStorage._string substringWithRange:effectiveRange], - font = [textStorage font] || [CPFont systemFontOfSize:12.0]; + font = [textStorage font] || [CPFont systemFontOfSize:12.0], + underline = [attributes objectForKey:CPUnderlineStyleAttributeName] || CPUnderlineStyleNone ; if ([attributes containsKey:CPFontAttributeName]) font = [attributes objectForKey:CPFontAttributeName]; var color = [attributes objectForKey:CPForegroundColorAttributeName], - elem = [self createDOMElementWithText:string andFont:font andColor:color], - run = {_range:CPMakeRangeCopy(effectiveRange), color:color, font:font, elem:nil, string:string}; + run = {_range:CPMakeRangeCopy(effectiveRange), color:color, font:font, elem:nil, string:string, underline:underline}; _runs.push(run); @@ -1248,7 +1267,7 @@ var _objectsInRange = function(aList, aRange) if (!run.elem && CPRectIntersectsRect([_textContainer._textView exposedRect], _fragmentRect)) { - run.elem=[self createDOMElementWithText:run.string andFont:run.font andColor:run.color]; + run.elem=[self createDOMElementWithText:run.string andFont:run.font andColor:run.color andUnderline:run.underline]; } if (run.DOMactive && !run.DOMpatched) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index c71544bf3..5e7ebab28 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -1922,14 +1922,14 @@ Sets the selection to a range of characters in response to user action. if ([attrib containsKey:CPUnderlineStyleAttributeName] && [[attrib objectForKey:CPUnderlineStyleAttributeName] intValue]) [_textStorage removeAttribute:CPUnderlineStyleAttributeName range:_selectionRange]; else - [_textStorage addAttribute:CPUnderlineStyleAttributeName value:[CPNumber numberWithInt:1] range:CPMakeRangeCopy(_selectionRange)]; + [_textStorage addAttribute:CPUnderlineStyleAttributeName value:CPUnderlineStyleSingle range:CPMakeRangeCopy(_selectionRange)]; } else { if ([_typingAttributes containsKey:CPUnderlineStyleAttributeName] && [[_typingAttributes objectForKey:CPUnderlineStyleAttributeName] intValue]) - [_typingAttributes setObject:[CPNumber numberWithInt:0] forKey:CPUnderlineStyleAttributeName]; + [_typingAttributes setObject:CPUnderlineStyleNone forKey:CPUnderlineStyleAttributeName]; else - [_typingAttributes setObject:[CPNumber numberWithInt:1] forKey:CPUnderlineStyleAttributeName]; + [_typingAttributes setObject:CPUnderlineStyleSingle forKey:CPUnderlineStyleAttributeName]; } [_layoutManager textStorage:_textStorage edited:0 range:CPMakeRangeCopy(_selectionRange) changeInLength:0 invalidatedRange:CPMakeRangeCopy(_selectionRange)]; diff --git a/Tests/AppKit/CPTextViewTest.j b/Tests/AppKit/CPTextViewTest.j index 61149e6dc..40777e9fa 100644 --- a/Tests/AppKit/CPTextViewTest.j +++ b/Tests/AppKit/CPTextViewTest.j @@ -27,6 +27,12 @@ [textView setDelegate:self]; [[theWindow contentView] addSubview:textView]; + + var button = [[CPButton alloc] initWithFrame:CGRectMake(400,10,75,25)]; + [button setTitle:@"Underline"]; + [button setTarget:textView]; + [button setAction:@selector(underline:)]; + [[theWindow contentView] addSubview:button]; delegateSpy = spy(self); } @@ -184,4 +190,4 @@ } -@end \ No newline at end of file +@end