FROM : Dustin Wenz
DATE : Mon Apr 30 23:39:54 2007
On Apr 27, 2007, at 5:17 PM, Dustin Wenz wrote:
> I've run into this problem twice this year; and have no idea how to
> solve it properly.
>
> Basically, I have a NSTableView with a column of NSSwitchButtons
> (check boxes). It looks good, and the user can click to toggle the
> buttons just fine. The problem occurrs when a user clicks on a
> checkbox, and then drags the mouse cursor over a checkbox in a
> different row, and then releases the mouse. The second checkbox is
> toggled, even though no mouse-down event occurred on it. This is
> really undesirable behavior, especially when I'm implementing a
> multiple-selection table, or in a table with drag-reordering of rows.
>
> This problem can be seen in the sample code for
> DragNDropOutlineView, by drag-selecting rows in the checkbox column.
>
> I haven't been able to find any mention of this behavior in the
> archives... Has anyone else run up against this?
I was able to get the desired button behavior in the table by
providing the NSButton with a subclassed NSButtonCell. The subclass
overrides the parent with this method:
- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame
ofView:(NSView *)controlView untilMouseUp:(BOOL)untilMouseUp
{
return [theEvent type] == NSLeftMouseDown ? [super
trackMouse:theEvent inRect:cellFrame ofView:controlView
untilMouseUp:untilMouseUp] : NO;
}
Now, the button only tracks mouse events when they are a direct left-
click on the cell, and it does not track for all other events (such
as a drag into a cell).
- .Dustin
DATE : Mon Apr 30 23:39:54 2007
On Apr 27, 2007, at 5:17 PM, Dustin Wenz wrote:
> I've run into this problem twice this year; and have no idea how to
> solve it properly.
>
> Basically, I have a NSTableView with a column of NSSwitchButtons
> (check boxes). It looks good, and the user can click to toggle the
> buttons just fine. The problem occurrs when a user clicks on a
> checkbox, and then drags the mouse cursor over a checkbox in a
> different row, and then releases the mouse. The second checkbox is
> toggled, even though no mouse-down event occurred on it. This is
> really undesirable behavior, especially when I'm implementing a
> multiple-selection table, or in a table with drag-reordering of rows.
>
> This problem can be seen in the sample code for
> DragNDropOutlineView, by drag-selecting rows in the checkbox column.
>
> I haven't been able to find any mention of this behavior in the
> archives... Has anyone else run up against this?
I was able to get the desired button behavior in the table by
providing the NSButton with a subclassed NSButtonCell. The subclass
overrides the parent with this method:
- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame
ofView:(NSView *)controlView untilMouseUp:(BOOL)untilMouseUp
{
return [theEvent type] == NSLeftMouseDown ? [super
trackMouse:theEvent inRect:cellFrame ofView:controlView
untilMouseUp:untilMouseUp] : NO;
}
Now, the button only tracks mouse events when they are a direct left-
click on the cell, and it does not track for all other events (such
as a drag into a cell).
- .Dustin
| Related mails | Author | Date |
|---|---|---|
| Dustin Wenz | Apr 28, 00:17 | |
| Dustin Wenz | Apr 30, 23:39 |






Cocoa mail archive

