• 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: Mouse tracking an NSCell in my control
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mouse tracking an NSCell in my control


  • Subject: Re: Mouse tracking an NSCell in my control
  • From: Aaron Burghardt <email@hidden>
  • Date: Tue, 24 Jun 2003 13:36:12 -0400

I posted some code recently that was related. I wanted an NSTableView to leave the selection unchanged when the user clicked on a custom NSPopUpButtonCell or checkbox. I found the trackMouse: call you are making does cause the cell to change state (i.e., it is getting the mouse event and reacting), it just doesn't display it visually. Also, the cells didn't work reliably and sometimes failed. To fix the problem, I bracketed the trackMouse: with highlight: calls such as:


[cell highlight:YES withFrame:frame inView:self];

if ([cell trackMouse:theEvent inRect:frame ofView:self untilMouseUp:NO]) {
[[self dataSource] tableView:self
setObjectValue:[NSNumber numberWithInt:[cell indexOfSelectedItem]]
forTableColumn:[self tableColumnWithIdentifier:@"popup"]
row:row];
}

[cell highlight:NO withFrame:frame inView:self];


If using checkboxes, and possibly other cells, this doesn't work exactly as a standard checkbox control. On a standard NSButton, if you click and hold the mouse button on the control it highlights. While holding the button, if you move off the control the highlight turns off. If you then mouse back over the control, it highlights again. The technique above does not highlight again once the highlight goes off. To achieve that, I think you have to request mouse events from the window and process them accordingly. There is an example of this in the developer documentation under the Events programming topic:

file:///Developer/Documentation/Cocoa/TasksAndConcepts/ ProgrammingTopics/BasicEventHandling/Tasks/HandlingMouseEvents.html

I'm pretty new, so take this with a grain of salt, but it seems to work reliably for me.

Cheers,
----
Aaron Burghardt
email@hidden

On Tuesday, June 24, 2003, at 12:39 PM, Uli Kusterer wrote:

Hi,

I'm currently working on an control that does something similar as NSMatrix, i.e. it displays NSCell objects in a certain arrangement. Now, drawing them works fine, but I can't seem to get mouse tracking to work. Here's what I'm doing:

- (void)mouseDown:(NSEvent *)event
{
NSPoint lastPos = [event locationInWindow];
UKDistViewItem* mouseCell = [self getItemAtPoint: lastPos];

if( [[mouseCell cell] trackMouse: event inRect:[mouseCell bounds] ofView:self untilMouseUp:YES] )
{
NSLog(@"Cell was clicked.");
}

[self setNeedsDisplay:YES];
}

I've verified that my getItemAtPoint: method returns the correct cell from my list, and mouseDown is called, however the pushbutton cell doesn't actually highlight or track the mouse in any way.

I also tried calling startTrackingAt:inView: directly and calling continueTracking: and stopTracking: from mouseDragged: and mouseUp:, but so far, no cookie.

Any clues, pointers to mamasam discussions etc. would be greatly appreciated.

Cheers,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Mouse tracking an NSCell in my control
      • From: "M. Uli Kusterer" <email@hidden>
References: 
 >Mouse tracking an NSCell in my control (From: Uli Kusterer <email@hidden>)

  • Prev by Date: Re: cfsocket / upd monitoring
  • Next by Date: Re: Safari SDK
  • Previous by thread: Mouse tracking an NSCell in my control
  • Next by thread: Re: Mouse tracking an NSCell in my control
  • Index(es):
    • Date
    • Thread