Post by Eyal Redler
1. In Classic the procedure was to set the highlight bit and call
InvertRect, without redrawing the text under the selection (and you
could do the same again to erase the highlight) I assume this is not
the case with Quartz. Right? My guess is that the proper way to do this
is to get the highlight color from somewhere and draw the selection
over the text with some transparency (if so, how transparent should it
be? and where do I get the highlight color from?
2. With the caret I have two additional questions
a. How do I trigger the blinking (NSTimer?) and where can I find
the value for the time interval?
b. How do I trigger the actual drawing (what is the equivalent to
For what it's worth, the default time interval for blinking the Cocoa
text system's insertion point caret is currently 0.56 seconds (I believe
that's a half-cycle time, not a full cycle). You would want to do
something like this to start the timer
timer = [[NSTimer timerWithTimeInterval:blinkTime target:someTarget
[[NSRunLoop currentRunLoop] addTimer:timer
and then something like this to stop it.
timer = nil;
There are a few subtleties here--for example, you will notice that the
Cocoa text system keeps the caret drawn without blinking it while the
user is actually typing.
With regard to actually drawing the blinking caret, there are several
ways to do it, but probably the simplest is to give your view the
ability to draw with either the caret shown or not shown. When you flip
the switch, you then just tell your view setNeedsDisplayInRect:rect
where rect is some rectangle that contains the caret.
Highlighted text in the Cocoa text system is just a specific instance of
background color--in fact, it's configurable by setting the NSTextView's
selectedTextAttributes. The default is a control color, [NSColor
selectedTextBackgroundColor], whose actual color value may vary. When
we draw a region, we first fill in the background color, then draw the
text on top of it. Again, when we change the highlighted region, we
call setNeedsDisplayInRect: with some rect that contains the areas that