NSTextAttachment, MouseOver, GlyphPosition

  • Hi,

    I have subclassed NSTextAttachment/NSAttachemntCell pair and I need to implement mouseOver.
    NSTextAttachment are inserted programatically to NSTextField's NSAttributedString object, displayed correctly
    and I can manipulate them.
    I have found not very elegant way how to create and track NSTrackingArea for each NSTextAttachment character in
    NSTextField, but I am not happy with the way how I am getting NSRect representing NSTextAttachment.

    What is a proper way to get cellFrame for NSTextAttachmentCell (or to be more general, position of glyph in NSAttributedString) that is inserted to NSAttributedString or drawn by NSTextFieldCell?

    I think could use NSLayoutManager that could return a glyph position I could use as origin to calculate cellFrame, but
    I have no idea how to get NSLayoutManager from NSTextField | NStextFieldCell | NSAttributted object.

    Thank you.

    Peter
  • Hi,

    one of the ways could be to use own NSLayoutManager and use it to draw NSAttributed string
    in my subclass of NSTextAttachmentCell and its draw method.
    NSLayoutManager has boundingRectForGlyphRange:inTextContainer: method from which I could obtain bounds of glyph representing
    NSTextAttachment at position I am interested in.
    I can use this method to get rectangles of all attachments in my updateTrackingAreas method.

    Does anybody see this as the right way ?

    Peter
  • On Feb 19, 2011, at 12:49 PM, Peter Krajčík wrote:

    > What is a proper way to get cellFrame for NSTextAttachmentCell (or to be more general, position of glyph in NSAttributedString) that is inserted to NSAttributedString or drawn by NSTextFieldCell?

    If you have subclassed NSTextAttachmentCell, and everything is working correctly, I would think you could get the value you need by overriding  cellFrameForTextContainer:proposedLineFragment:glyphPosition:characterIndex to call super and noting the returned value.
previous month february 2011 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28            
Go to today