Re: Tool tip tracking rects in an NSTextView subclass (was: Forcing drawViewBackgroundInRect...)
Re: Tool tip tracking rects in an NSTextView subclass (was: Forcing drawViewBackgroundInRect...)
- Subject: Re: Tool tip tracking rects in an NSTextView subclass (was: Forcing drawViewBackgroundInRect...)
- From: Keith Blount <email@hidden>
- Date: Wed, 6 Apr 2005 13:20:10 -0700 (PDT)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Many thanks for your help once again, Douglas, much
appreciated.
Sorry to have wasted your time on that one - it turned
out that the problem was a silly mistake I had made in
my drawing method. I had assumed that
rectArrayForCharacterRange... would return rectangles
of the same width for lines other than the top or
bottom ones in the range, which is of course a silly
assumption and it led to the odd drawing I was seeing.
However, I am experiencing a related problem (as you
are the expert in NSTextView I hope you don't mind me
asking it here). As well as setting up custom drawing
around these ranges of text, I am tring to set up tool
tip tips for them, and for this purpose I am using
addToolTipRect:... to add tool tips to ranges of text
using the rectArrayForCharacterRange method to get the
rects in exactly the same way as I am using it in my
drawing method to draw the selections. (The reason I
am not using NSToolTipAttributeName on the text
storage, which would be infinitely easier, is that
NSAttributedString's tool tips do not wrap and are
rather ugly - they seem still to be locked into the
old-style of tool tips, and this is no good for my
purpose as each tip may consist of a few lines of
annotation.)
I have a method, resetToolTipRects, that does all of
the rect calculations fine, but the trouble is, where
to call it? I tried putting it inside
-resetCursorRects, but this is only called on view
size changes, not when text is changed, meaning that I
can make edits and the tool tips don't move with the
text until the view is resized. (I see that TextLinks
suffers the same problem.)
If I place -resetToolTipRects inside drawRect: or
drawViewBackgroundInRect:, everything works fine, but
I feel that I shouldn't be setting up tool tip rects
inside a drawing method.
Where is the best place to do this? If anyone can put
me right, I would be very grateful.
Many thanks again,
Keith
--- Douglas Davidson <email@hidden> wrote:
>
> On Apr 6, 2005, at 10:25 AM, Keith Blount wrote:
>
> > Hello,
> >
> > I have an NSTextView subclass that uses
> > drawViewBackgroundInRect: to draw rectangles with
> > corners around ranges of text with certain
> attributes.
> >
> > To do this, in my drawViewBackgroundInRect:
> override
> > method, I get the ranges I need to draw around,
> and
> > then get the rects for these ranges using
> > NSLayoutManager's rectArrayForCharacterRange:...
> > method. Then I go about merging these rects and
> > rounding the corners of the resulting shape -
> which
> > will obviously be an irregular shape if the range
> > stretches across several lines, with its start and
> end
> > part way through lines.
> >
> > The trouble is, when I type before or inside these
> > ranges of text, the background drawing doesn't
> update
> > properly. The selection follows the text okay, but
> > when text drops off to the next line, the drawing
> at
> > the edges isn't updated - strange, as
> > drawViewBackgroundInRect does seem to get called.
> I
> > tried forcing drawViewBackgroundInRect to update
> [self
> > visibleRect] instead of just the passed-in rect,
> but
> > this made no difference.
> >
> > The only way I have found to force the display to
> > update properly on edits is by overriding
> > didChangeText and calling [self
> setNeedsDisplay:YES],
> > but this seems rather brute force and not the
> optimal
> > way of doing things.
>
> I'm not sure I entirely understand, but the first
> thing I would take
> a look at is whether the rect you are being passed
> includes the
> entire region that you want to draw.
> drawViewBackgroundInRect: is
> called from within drawRect:, and its drawing will
> generally be
> clipped to the rect being drawn. NSTextView will
> automatically mark
> itself dirty in regions needed to display any text
> that has changed,
> but if you are drawing outside of the text then you
> may need to call
> setNeedsDisplayInRect: on your view with any rects
> that need updating.
>
> Douglas Davidson
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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