Re: NSTextAttachment behavior
Re: NSTextAttachment behavior
- Subject: Re: NSTextAttachment behavior
- From: Douglas Davidson <email@hidden>
- Date: Fri, 14 Jan 2005 10:07:03 -0800
On Jan 14, 2005, at 9:53 AM, Gwynne wrote:
Initializes a newly allocated NSTextAttachment to contain aWrapper and
use an NSTextAttachmentCell as its attachment cell. If aWrapper
contains an image file that the receiver can interpret as an NSImage
object, sets the attachment cell’s image to the NSImage rather than to
the icon of aWrapper.
This is _almost_ what I want. But I want it to always use the file's
icon, even if the file is an image. Is there a simple way to do this
without sitting here reimplementing the entire NSTextAttachmentCell
machinery?
Certainly. Here's how it works: in order to display itself in the
text, an NSTextAttachment needs an NSTextAttachmentCell (well, really
an <NSTextAttachmentCell>). When it needs one, if you haven't supplied
one, it will create one automatically based on its own notion of the
contents of the file. If you don't want that to happen, just assign it
a cell of your own choosing, using setAttachmentCell:. You can create
an instance of NSTextAttachmentCell using the usual NSCell APIs like
initImageCell:. NSWorkspace will supply you with an icon for your file
if you don't already have one.
That should suffice for what you describe, but there are additional
ways to customize this if you have more specialized needs. For
example, you can create a completely custom <NSTextAttachmentCell> that
will size and position itself and do any sort of drawing you like
inline in the text; take a look at the protocol to see what all you can
do with it.
Douglas Davidson
_______________________________________________
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