Re: Custom Objects in an NSTextView
Re: Custom Objects in an NSTextView
- Subject: Re: Custom Objects in an NSTextView
- From: Douglas Davidson <email@hidden>
- Date: Wed, 4 Jan 2006 11:59:03 -0800
On Jan 4, 2006, at 11:54 AM, Douglas Davidson wrote:
On Jan 4, 2006, at 10:33 AM, Manfred Schubert wrote:
I'm not understanding it yet, but NSTextAttachment(Cell) might be
what I'm looking for. If anybody knows some sample code that uses
this, I would be grateful though. I'm still new to Cocoa and learn
best by seeing examples.
Here is some old and rather rudimentary sample code I happened to
have around.
It looks like that didn't come through. Here is just the code:
#import <AppKit/AppKit.h>
@interface Controller : NSObject {
id myTextView;
}
- (void)insertAttachment:(id)sender;
@end
@interface MyAttachmentCell : NSTextAttachmentCell {
}
@end
@implementation Controller
- (void)insertAttachment:(id)sender {
NSTextAttachment *attachment = [[NSTextAttachment alloc]
initWithFileWrapper:nil];
MyAttachmentCell *cell = [[MyAttachmentCell alloc] init];
[attachment setAttachmentCell:cell];
[myTextView insertText:[NSAttributedString
attributedStringWithAttachment:attachment]];
[cell release];
[attachment release];
}
@end
@implementation MyAttachmentCell
- (NSRect)cellFrameForTextContainer:(NSTextContainer *)textContainer
proposedLineFragment:(NSRect)lineFrag glyphPosition:(NSPoint)position
characterIndex:(unsigned)charIndex {
NSLog(@"line frag %@", NSStringFromRect(lineFrag));
return NSMakeRect(0, 0, lineFrag.size.width, 1);
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
characterIndex:(unsigned)charIndex layoutManager:(NSLayoutManager *)
layoutManager {
[[NSColor blackColor] set];
NSLog(@"cell frame %@", NSStringFromRect(cellFrame));
NSRectFill(cellFrame);
}
@end
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden