Re: Hightlight on mouseover a NSTextFieldCell inside a TableView
Re: Hightlight on mouseover a NSTextFieldCell inside a TableView
- Subject: Re: Hightlight on mouseover a NSTextFieldCell inside a TableView
- From: Graham Cox <email@hidden>
- Date: Tue, 1 Dec 2009 21:41:25 +1100
On 01/12/2009, at 9:06 PM, Gustavo Pizano wrote:
> Hello, I have been searching how to achieve this.
OK, usual blather about mouseovers being untypical UI on the Mac that is not encouraged by the HIG.
> I have a NSTableView and the NSTableCells are a subclass I made.
> Now I want to change the backgorund color of the table row when mouse over. In my SubClass of NSTextFieldCell I tried overriding these methods
> - (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView{
> NSLog(@"tracking.. %@",[self stringValue]);
> return YES;
> }
>
>
> - (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)untilMouseUp{
> NSLog(@"here");
> return YES;
> }
>
>
> off course I see nothing of the logs.. it was just a tryout. .. now i dunno how to make NSTextFieldCell respond to mouse events, i.e a mouse entered, this for NSResponder class and subclasses, so I was thinking in defining a NSTrackingArea, but because of NSTextField don't accept mouseEntered method then I dunno.
Those methods are there to deal with mouse down tracking.
> I thought then maybe to subclass NSTableView, and do something with the point f the mouse, and then get the row at point, form the NSTableView, but this method returns me a integer, so then I will multiply by the row height and create a NSREct and draw a background in that rect, but I dunno if this is a good approach.
Well, -rectOfRow: does all this for you, and presumably also deals with variable height rows.
NSTrackingArea is the standard approach for this, but for a table view might be tricky, because you'd need one per row and with that many and the likelihood of having to recompute them, might be a performance problem.
You can do it the manual way (but with rectOfRow:) if you enable mouseMoved events for the table view's window, and override mouseMOved: in your table subclass. Mouse moved events are not enabled by default because a) performance and b) the HIG doesn't encourage mouseovers.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden