[comp.sys.next] NeXTstep programming question

garnett@cs.utexas.edu (John William Garnett) (01/18/91)

Here's the scenario.  I have used IB to create a window with a slider
object.  I have been able to connect the output of the slider to a
custom object.  What I would like to be able to do is be able to
detect each mouseDown event that corresponds to the beginning of
a movement of the slider.  Similarly, I wish to be able to detect
the mouseUp event that signifies the end of a given slider movement.

It appears that the slider object is absorbing the mouse events
that are being sent to my application.  Does (should?, can?) the
slider object forward the mouse event message so that other
program fragments can act on it?  I've attempted to figure out
how to do this from reading the online NeXT docs but have yet
to have any success.

Thanks for any help,

John Garnett

ps.  If you need more info in order to help, please feel free to
send email to me.
-- 
John Garnett
                              University of Texas at Austin
garnett@cs.utexas.edu         Department of Computer Science
                              Austin, Texas

preston@LL.MIT.EDU (Steven Preston) (01/18/91)

In article <1048@nada.cs.utexas.edu> garnett@cs.utexas.edu (John William Garnett) writes:
>I have used IB to create a window with a slider object.  I have been
>able to connect the output of the slider to a custom object.  What I
>would like to be able to do is be able to detect each mouseDown event
>that corresponds to the beginning of a movement of the slider.
>Similarly, I wish to be able to detect the mouseUp event that
>signifies the end of a given slider movement.

You can obtain the event that caused the slider to send its message
using this code inside your custom object target method:

    NXEvent *ev;
    int event_type;
    ...
    ev = [NXApp currentEvent];
    event_type = ev->type;
    switch (event_type)
    {
     case NX_LMOUSEDOWN:
      ...
      break;
     case NX_LMOUSEDRAGGED:
      ...
      break;
    }

There are also many other Application methods for obtaining or peeking
at the next event.  See the appkit/Application.h or the class specs.
--
Steve Preston

wjs@milton.u.washington.edu (William Jon Shipley) (01/19/91)

The Slider object keeps the mouse events for itself, as it should.
If you want to detect mouseUp and mouseDown, rather than try to intercept
the events yourself, you should probably be doing it in a subclass of Slider,
and write covers for the startTrackingAt:inView: and
stopTracking:at:inView:mouseIsUp: methods-- see the documentation on Cell
and Slider for more details on these.

-w

PS: This PS put here so that this post isn't just one big sentence.

scott@mephistopheles.gac.edu (Scott Hess) (01/19/91)

In article <1048@nada.cs.utexas.edu> garnett@cs.utexas.edu (John William Garnett) writes:
   Here's the scenario.  I have used IB to create a window with a slider
   object.  I have been able to connect the output of the slider to a
   custom object.  What I would like to be able to do is be able to
   detect each mouseDown event that corresponds to the beginning of
   a movement of the slider.  Similarly, I wish to be able to detect
   the mouseUp event that signifies the end of a given slider movement.

The suggestion I read earlier about how the receiver can interpret
stuff like this was valid, but I still submit my version as an
alternate:

My thought was to subclass Slider.  Then, you simply catch the starting
mouseDown:, send someone that indication, then send it one to your
superclass.  When the superclass' mouseDown: returns, you send the
indication of mouseUp to whoever needs it.  To get this version
working, just use a CustomView and set the class to your subclass,
and away you go.

That will work fine for Slider controls.  It will not work for Sliders
in a Matrix.  Another method is to create your own SliderCell class.
Override the startTrackingAt:inView: and stopTracking:at:inView:
mouseIsUp: methods to send the appropriate message to whoever needs
it.  This will also work in a Slider Control.  I'm _not_ sure how you'd
go about getting this set up, though.  A simple method would be
to create a new SliderCell subclass and a corrosponding Slider
subclass, and then combine them for a new view in a Custom InterfaceBuilder
palette.  This would also be decent for connecting things - you could
supply another outlet to send the mouseUp and Down messages to,
as opposed to the target.

But, I think that my methods are a little more complex than needed.
It really depends on what you need in your program . . .
--
scott hess                      scott@gac.edu
Independent NeXT Developer	GAC Undergrad
<I still speak for nobody>
"Tried anarchy, once.  Found it had too many constraints . . ."
"Buy `Sweat 'n wit '2 Live Crew'`, a new weight loss program by
Richard Simmons . . ."

dennisg@kgw2.bwi.WEC.COM (Dennis Glatting) (01/19/91)

In article <1048@nada.cs.utexas.edu>, garnett@cs.utexas.edu (John William Garnett) writes:
|> Here's the scenario.  I have used IB to create a window with a slider
|> object.  I have been able to connect the output of the slider to a
|> custom object.  What I would like to be able to do is be able to
|> detect each mouseDown event that corresponds to the beginning of
|> a movement of the slider.  Similarly, I wish to be able to detect
|> the mouseUp event that signifies the end of a given slider movement.
|> 
|> It appears that the slider object is absorbing the mouse events
|> that are being sent to my application.  Does (should?, can?) the
|> slider object forward the mouse event message so that other
|> program fragments can act on it?  I've attempted to figure out
|> how to do this from reading the online NeXT docs but have yet
|> to have any success.
|> 

slider is a subclass of Responder.  what i would do here is to 
subclass slider and overload the Responder methods of interest.
For example,

- mouseUp:( NXEvent * )event {

    [ super mouseUp:event ];

         ....
    your code here
         ...

    return self;
}


--
 ..!uunet!kgw2!dennisg  | Dennis P. Glatting
 dennisg@Xetron.COM     | X2NeXT developer