Problems with custom drawing in an NSTextView subclass
Problems with custom drawing in an NSTextView subclass
- Subject: Problems with custom drawing in an NSTextView subclass
- From: Keith Blount <email@hidden>
- Date: Fri, 8 Apr 2005 06:19:44 -0700 (PDT)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Hello,
I have an NSTextView subclass that draws highlight
rectangles around text with a certain attribute and
also provides tool tips for these rectangles. I have
done all of this according to the docs and according
to Douglas Davidson's very helpful past posts on this
sort of thing on this list: in
drawViewBackgroundInRect, I calculate the characters
being drawn using glyphRangeForBoundingRect: and
characterRangeForGlyphRange:, then I cycle through
this range looking for the attribute I want to
highlight. Then I use rectArrayForCharacterRange: on
the returned effectiveRanges and colour in the
backgrounds of these rects.
Also, in resetCursorRects, I call a custom method,
resetToolTipRects, which does something similar but
instead of drawing, uses addToolTipRect: for the
returned rectangles to set up tool tips (note that I
am not using NSToolTipAttributeName because the tool
tips used by NSAttributedString are the old-styles
ones that do not wrap, which are no good for my
purposes).
All of this works fine, so long as I don't edit the
text. But if I edit the text, the tool tip areas are
not updated because resetCursorRects is not called
unless the frame changes. Also, selection rectangles
are not updated properly because
drawViewBackgroundInRect: is only called for areas of
text marked as dirty, meaning that if you start typing
inside a highlighted area, when you drop into a new
line, the highlight in the lines above doesn't get
updated - this would be fine if I was just drawing
simple rectangles, but as I am drawing an irregular
bubble, it looks terrible.
Does anybody know what I can do to rectify this?
I tried registering my text view subclass as an
observer of NSTextDidChangeNotifications and calling
the following method when receiving such a message:
-
(void)receivedTextDidChangeNotification:(NSNotification
*)notification
{
if ([[notification object] textStorage] == [self
textStorage])
{
[self resetToolTipRects];
[self setNeedsDisplayInRect:[self visibleRect]];
}
}
(Note that I check for changes in the text storage
instead of just overriding didChangeText because the
text view will also need to update if another text
view using the same text storage has changed the
text.)
This works so that everything is updated perfectly,
but it causes a noticeable slowdown in typing which is
unacceptable.
I would be very grateful to anybody who has any ideas
of how I can ensure selection bubbles and tool tips
are updated properly without causing slowdown.
Many thanks in advance for any help or advice,
Keith
__________________________________________________
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