Skip navigation.
 
mlRe: Custom mouse cursor in NSTextView
FROM : Douglas Davidson
DATE : Mon Jun 23 21:45:57 2008

On Jun 13, 2008, at 8:58 AM, Todd Ransom wrote:

> I have a fullscreen text view in my app that allows the user to set 
> a foreground and background color. Problem is, for some 
> configurations the default I-beam mouse cursor does not show up very 
> well so I want to provide a custom I-beam cursor in the same color 
> as the text.
>
> I put together a bezier path to draw the I-beam and overrode 
> resetCursorRects like this:
>
> - (void)resetCursorRects
> {
>     [self addCursorRect: [self visibleRect] cursor: [self 
> bigIBeamCursor]];
> }
>
>
> This works great as long as I use it in an NSView subclass. But as 
> soon as I change my class to inherit from NSTextView it stops 
> working. resetCursorRects is still called, but the text view is 
> doing some kind of magic to change the cursor itself. I have also 
> tried overriding - (void)addCursorRect:(NSRect)aRect cursor:
> (NSCursor *)aCursor to replace the generic ibeam with my own, but 
> that only seems to get called if I override resetCursorRects and it 
> does not affect the cursor appearance in the text view either.
>
> Has anyone else out there successfully changed the mouse cursor on a 
> text view? What did you need to do?


NSTextView sets the cursor over itself dynamically, based on 
considerations including the text under the cursor.  It does so in -
mouseEntered:, -mouseMoved:, and -cursorUpdate:, so those would be 
points to consider overriding.

Douglas Davidson

Related mailsAuthorDate
mlCustom mouse cursor in NSTextView Todd Ransom Jun 13, 17:58
mlRe: Custom mouse cursor in NSTextView Douglas Davidson Jun 23, 21:45