• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Buttons inside an NSTextView / NSTextStorage?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Buttons inside an NSTextView / NSTextStorage?


  • Subject: Re: Buttons inside an NSTextView / NSTextStorage?
  • From: Douglas Davidson <email@hidden>
  • Date: Wed, 26 Oct 2005 11:23:03 -0700


On Oct 25, 2005, at 3:11 PM, Keith Blount wrote:

I am currently trying to implement inline comments in
an NSTextView in a similar way to how LyX does it. I
would like an NSButton to appear inline in the text
wherever a note occurs. If the user clicks on the
button, the note will appear next to it. If the user
clicks on the button again, the text will disappear. I
can get the text to appear and disappear using the
usual text replacement methods and some custom text
attributes, but my problem is, how do I get an
NSButton to appear inside the text and react to
clicks? I am pretty sure that I need to use
NSTextAttachment and NSTextAttachmentCell, but upon
searching the net, the archives, the docs and
CocoaDev, it seems that there is not much out there on
how I would go about this (there are a *lot* of
questions out there in the ether, just no real answers
as far as I can find; the only stuff out there on
NSTextAttachments relate to inserting images, which is
a lot easier and involves none of the tough
subclassing/protocol stuff...).


NSTextAttachment holds the contents of an attachment; it is the value of the NSAttachmentAttributeName attribute for the NSAttachmentCharacter in the attributed string. The contents are usually given by an NSFileWrapper, but this is not required; you can create an empty NSTextAttachment with a nil file wrapper.


NSTextAttachmentCell handles display and user interaction for the attachment. By default an NSTextAttachment will create an NSTextAttachmentCell to display itself, depending on the contents of the attachment; in the generic case this will just be an image cell displaying an icon.

If you wish, however, you can supply a custom NSTextAttachmentCell for your attachment. It need not be an member of the class NSTextAttachmentCell; it only needs to conform to the NSTextAttachmentCell protocol. Actually, even that is not strictly necessary; it only needs to implement a few of the basic methods for sizing and drawing. Most cells already do this.

You will, however, need to deal with mouse events yourself. The methods you'll probably want to implement would be wantsToTrackMouseForEvent:inRect:ofView:atCharacterIndex: and trackMouse:inRect:ofView:atCharacterIndex:. The character index here should let you determine which portion of the text is relevant.

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
  • Follow-Ups:
    • Re: Buttons inside an NSTextView / NSTextStorage?
      • From: Keith Blount <email@hidden>
References: 
 >RE: Buttons inside an NSTextView / NSTextStorage? (From: Keith Blount <email@hidden>)

  • Prev by Date: How to receive notifications while in modal loop?
  • Next by Date: Access to argc & argv
  • Previous by thread: RE: Buttons inside an NSTextView / NSTextStorage?
  • Next by thread: Re: Buttons inside an NSTextView / NSTextStorage?
  • Index(es):
    • Date
    • Thread