diff --git a/Headers/gnustep/gui/NSTextAttachment.h b/Headers/gnustep/gui/NSTextAttachment.h index 711bcf133..387c4fb1a 100644 --- a/Headers/gnustep/gui/NSTextAttachment.h +++ b/Headers/gnustep/gui/NSTextAttachment.h @@ -48,6 +48,7 @@ @class NSTextContainer; @class NSFileWrapper; @class NSTextAttachment; +@class NSLayoutManager; enum { NSAttachmentCharacter = 0xfffc /* To denote attachments. */ @@ -64,6 +65,10 @@ enum { - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView characterIndex:(unsigned)charIndex; +- (void)drawWithFrame:(NSRect)cellFrame + inView:(NSView *)controlView + characterIndex:(unsigned)charIndex + layoutManager:(NSLayoutManager *)layoutManager; - (void)highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView:(NSView *)controlView; @@ -74,6 +79,10 @@ enum { glyphPosition:(NSPoint)position characterIndex:(unsigned)charIndex; - (BOOL)wantsToTrackMouse; +- (BOOL)wantsToTrackMouseForEvent:(NSEvent *)theEvent + inRect:(NSRect)cellFrame + ofView:(NSView *)controlView + atCharacterIndex:(unsigned)charIndex; - (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView diff --git a/Source/NSTextAttachment.m b/Source/NSTextAttachment.m index cc617f3c2..07d47bdce 100644 --- a/Source/NSTextAttachment.m +++ b/Source/NSTextAttachment.m @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -53,6 +54,16 @@ inView: controlView]; } +- (void)drawWithFrame:(NSRect)cellFrame + inView:(NSView *)controlView + characterIndex:(unsigned)charIndex + layoutManager:(NSLayoutManager *)layoutManager +{ + [self drawWithFrame: cellFrame + inView: controlView + characterIndex: charIndex]; +} + - (NSPoint)cellBaselineOffset { return NSZeroPoint; @@ -76,12 +87,67 @@ return YES; } +- (BOOL)wantsToTrackMouseForEvent:(NSEvent *)theEvent + inRect:(NSRect)cellFrame + ofView:(NSView *)controlView + atCharacterIndex:(unsigned)charIndex +{ + return [self wantsToTrackMouse]; +} + - (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)flag { - // FIXME: This is not the correct behaviour + if ([controlView respondsToSelector: @selector(delegate)]) + { + NSTextView *textView = (NSTextView*)controlView; + id delegate = [textView delegate]; + NSEventType type = [theEvent type]; + + if (type == NSLeftMouseUp) + { + if ([theEvent clickCount] == 2) + { + if (delegate != nil && + [delegate respondsToSelector: + @selector(textView:doubleClickedOnCell:inRect:)]) + { + [delegate textView: textView + doubleClickedOnCell: self + inRect: cellFrame]; + return YES; + } + } + else + { + if (delegate != nil && + [delegate respondsToSelector: + @selector(textView:clickedOnCell:inRect:)]) + { + [delegate textView: textView + clickedOnCell: self + inRect: cellFrame]; + return YES; + } + } + } + else if (type == NSLeftMouseDragged) + { + if (delegate != nil && + [delegate respondsToSelector: + @selector(textView:draggedCell:inRect:event:)]) + { + [delegate textView: textView + draggedCell: self + inRect: cellFrame + event: theEvent]; + return YES; + } + } + } + return [super trackMouse: theEvent inRect: cellFrame ofView: controlView @@ -94,7 +160,57 @@ atCharacterIndex:(unsigned)charIndex untilMouseUp:(BOOL)flag { - // FIXME: This is not the correct behaviour + if ([controlView respondsToSelector: @selector(delegate)]) + { + NSTextView *textView = (NSTextView*)controlView; + id delegate = [textView delegate]; + NSEventType type = [theEvent type]; + + if (type == NSLeftMouseUp) + { + if ([theEvent clickCount] == 2) + { + if (delegate != nil && + [delegate respondsToSelector: + @selector(textView:doubleClickedOnCell:inRect:atIndex:)]) + { + [delegate textView: textView + doubleClickedOnCell: self + inRect: cellFrame + atIndex: charIndex]; + return YES; + } + } + else + { + if (delegate != nil && + [delegate respondsToSelector: + @selector(textView:clickedOnCell:inRect:atIndex:)]) + { + [delegate textView: textView + clickedOnCell: self + inRect: cellFrame + atIndex: charIndex]; + return YES; + } + } + } + else if (type == NSLeftMouseDragged) + { + if (delegate != nil && + [delegate respondsToSelector: + @selector(textView:draggedCell:inRect:event:atIndex:)]) + { + [delegate textView: textView + draggedCell: self + inRect: cellFrame + event: theEvent + atIndex: charIndex]; + return YES; + } + } + } + return [self trackMouse: theEvent inRect: cellFrame ofView: controlView @@ -180,6 +296,8 @@ - (void)setFileWrapper:(NSFileWrapper *)fileWrapper { ASSIGN(_fileWrapper, fileWrapper); + // Reset the cell, so it shows the new attachment + [_cell setAttachment: self]; } - (NSFileWrapper *)fileWrapper