• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: Changing the IBeamCursor colour in an NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Changing the IBeamCursor colour in an NSTextView


  • Subject: RE: Changing the IBeamCursor colour in an NSTextView
  • From: Keith Blount <email@hidden>
  • Date: Mon, 28 Feb 2005 09:14:55 -0800 (PST)
  • Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys

Well, I've found a sort of workaround, though it's an
ugly hack. I'm setting the window's
setAcceptsMouseMovedEvents to YES and then doing this:

- (void)mouseMoved:(NSEvent *)theEvent
{
	if ([NSCursor currentCursor] == [NSCursor
IBeamCursor])
		[iBeamColor set];
}

This way, if the cursor does change back to the
default black I-beam cursor, my app immediately
switches it back to the coloured version. Not very
graceful, though - it would be much better if my
overridden text view didn't insist on keep switching
the cursor back to the default one despite my own
cursor rects in the first place...

If anyone does know of a better solution for changing
the colour of a text view's cursor, I would be very
grateful to hear it.

Thanks and all the best,
Keith

--- Original message ---

Hello,

I am working on a fullscreen text editing mode for my
app and, because the user can customise the background
colour of the text view so that it is black (for
instance) in full screen, I would like to be able to
change the colour of the I-beam cursor within the text
view. ie. If the text view is black, the I-beam cursor
will be almost invisible unless its colour is changed.

I thought this would be relatively straightforward,
but I can't get it to work. I started by subclassing
NSTextView and overriding -resetCursorRects as
follows, in an effort (as a test) to replace the
default I-beam cursor with a blue one:

- (void)resetCursorRects
{
  NSCursor *iBeam = [NSCursor IBeamCursor];
  NSImage *iBeamImg = [iBeam image];
  NSRect imgRect = {NSZeroPoint, [iBeamImg size]};
  [iBeamImg lockFocus];
  [[NSColor blueColor] set];

NSRectFillUsingOperation(imgRect,NSCompositeSourceAtop);
  [iBeamImg unlockFocus];
  NSCursor *iBeamColor = [[NSCursor alloc]
initWithImage:iBeamImg hotSpot:[iBeam hotSpot]];
  [self addCursorRect:[self visibleRect]
cursor:iBeamColor];
  [iBeamColor setOnMouseEntered:YES];
  [iBeamColor release]; // I have tried not releasing
here, with no effect
}

However, this does not work as expected. The blue
I-beam cursor sometimes appears - if moving very
slowly into the view from the top or bottom, for
instance - but it always reverts to the black default
I-beam cursor.

Because this didn't work, I tried overriding
addCursorRect:cursor: so that it always changed the
passed-in cursor to blue, but this had no effect.

It seems that NSTextView is doing something other than
just calling resetCursorRects to set the I-beam
cursor, but I can't find anything in the docs about
this. Does anyone know how I can successfully change
the colour of the I-beam cursor in an NSTextView?

Many thanks in advance for any help,
Keith



__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail
 _______________________________________________
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

  • Prev by Date: Changing the image for a NSButtonCell (radio button style)
  • Next by Date: Re: Changing the image for a NSButtonCell (radio button style)
  • Previous by thread: RE: Changing the IBeamCursor colour in an NSTextView
  • Next by thread: Re: Tiger seeds download problems
  • Index(es):
    • Date
    • Thread