Skip navigation.
 
mlReplacing the standard NSTextAttachmentCell in an NSTextView
FROM : listposter
DATE : Tue Nov 06 15:34:23 2007

Hello,

I'm currently researching how to provide a custom NSCell to replace 
the current NSTextAttachentCell in an NSTextView.
The reason is that I want to have a different type of attachment not 
just for images or file objects, but for actual objects in my 
application.
IOW, something similar to NSTokens (actually I'm using an 
NSTokenFieldCell subclass) that can represent  actual "objects" in a 
text field...

So, I have insertion working, and the cell fulfills the basic protocol 
for NSTextAttachment.
The problem is, when cutting and pasting my object back into the text 
field, it reverts to a standard NSTextAttachmentCell....
How can I override this to insert my special cell?
The problem I am running into is that the NSTextAttachment requires an 
NSFileWrapper, but since I am not representing a file object, I tested 
it out using:
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] 
initWithFileWrapper:nil];
In the above case, paste then doesn't even work....

Also, when reading the .h for NSTextAttachment, its states for the 
NSTextAttachmentCell:

/* Simple class to provide basic attachment cell functionality. By 
default this class causes NSTextView to send out delegate messages 
when the attachment is clicked on or dragged.
  */

How can I get this functionality in my custom cell?
I'm assuming that through this method:

- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:
(NSView *)controlView atCharacterIndex:(NSUInteger)charIndex 
untilMouseUp:(BOOL)flag;

How can I get the aforementioned double-click functionality in my 
custom cell? I know its not "legal" to do something like [[(NSTextView 
*)controlView delegate] SOME_DELEGATE_METHOD] so I'm curious what is 
the best way to go about doing this.... I would like the delegate to 
have a chance to do something as well when double clicked or edited....

Especially the case of pasted text containing values originally 
representing my special cell, I would like the pasted text to use that 
special cell, currently I can't get that working...

Thanks for any pointers.

Andre

Related mailsAuthorDate
mlReplacing the standard NSTextAttachmentCell in an NSTextView listposter Nov 6, 15:34
mlRe: Replacing the standard NSTextAttachmentCell in an NSTextView Douglas Davidson Nov 6, 18:10
mlRe: Replacing the standard NSTextAttachmentCell in an NSTextView Andre Nov 7, 01:22