[comp.sys.next] programming question: Views and Mouse Events

laughlin@fornax.UUCP (Bob Laughlin) (03/05/91)

     Mail to next-prog@cpac.washington.edu bounces otherwise I would 
have sent this there.

     I have a View subclass that fills part of a window. I would like the
View's mouseDown: method to be called when the window first becomes
activated with a mouse click (assuming the mouse click was also in the View).
How do I do this?  Right now the first mouse click is trapped by the window
to activate itself and never gets passed onto the subview. 

     I also have a matrix of sliders that continuously sends action 
messages as a slider is moved. In addition to this, I would like to
know when the last message comes in, i.e. the user has released the
mouse button. A test for whether the mouse button is currently down
in the window that the matrix is in would do as well. How can I get
this information?

    A related question: Under 1.0 this matrix of sliders would track
mouse drags over different sliders. Under 2.0 the same matrix
(created in IB) only tracks the slider that was initially activated
on the mouseDown:. If you drag the mouse over a different slider
it does not get activated. Has this been disabled in 2.0 or is it
just a different default?

    A quick look at the online Class docs did not answer these questions
for me although I'm sure they're there. Has anybody received the
2.0 technical manuals?
-- 
 Bob Laughlin  laughlin@cs.sfu.ca 

aozer@next.com (Ali Ozer) (03/07/91)

In article <2229@fornax.UUCP> laughlin@fornax.UUCP (Bob Laughlin) writes:
>... I have a View subclass that fills part of a window. I would like the
>View's mouseDown: method to be called when the window first becomes
>activated with a mouse click (assuming the mouse click was also in the View).

Give your view an acceptsFirstMouse method and have it return YES.  When a
window becomes activated by a mouse down, the view under the mouse is
interrogated to see if it would like to get that event:

	- (BOOL)acceptsFirstMouse
	{
	    return YES;
	}

>... Under 1.0 this matrix of sliders would track
>mouse drags over different sliders. Under 2.0 the same matrix
>(created in IB) only tracks the slider that was initially activated
>on the mouseDown:. If you drag the mouse over a different slider
>it does not get activated. Has this been disabled in 2.0 or is it
>just a different default?

In 2.0 the tracking behaviour of sliders in a matrix of sliders
was changed so that the initial slider is the active one until the
mouse up.  This prevents neighboring sliders from taking over as you
drag the mouse.  Typically users want to grab a slider and drag it
while looking elsewhere; losing the control of the slider just
because they moved a bit too much to the side is confusing.

I don't believe there were any 1.0 applications out there that depended
on this tracking behaviour.  In fact, a few applications ended up creating
many individual sliders rather than a matrix just to avoid this tracking
problem.

However, for those developers who wish their sliders to track as they did in
1.0, there's a hook: The prefersTrackingUntilMouseUp factory method in Cell
determines if a cell in a matrix tracks until mouse up is received or
until the mouse is dragged over a neighboring cell. The method in Cell
(which most subclasses of Cell inherit) returns NO; thus matrices of 
buttons act as they did in 1.0. SliderCell overrides this method to
return YES; thus it grabs on to the mouse until it's released. Subclassing 
SliderCell and having this method return NO should restore the 1.0
behaviour.

Ali, Ali_Ozer@NeXT.com