[comp.sys.mac.programmer] Double Click in Think C

dmmg1176@uxa.cso.uiuc.edu (David M Marcovitz) (04/10/91)

Is there an easy way to implement double clicking in Think C?  That
is, I have an object that I want to do something special when I double
click on it (and something else when I single click on it).  Actually,
the function I want is similar to what happens to an icon in the
finder:  a single click (and holding the cursor down) allows you to
drag an icon around the screen; a double click allows you to edit the
icon's name.

I assume I can do something with TickCount and GetDblTime in my
object's DoClick method, but I would rather have a DoDoubleClick
method that gets a message when I double click (and not have the
DoClick method get a message).  Is this done for me somewhere in TCL,
or do I have to do it myself in my DoClick method?

--
David M. Marcovitz                     |  internet: marcovitz@uiuc.edu
Computer-based Education Research Lab  |            dmmg1176@uxa.cso.uiuc.edu
University of Illinois                 |  novanet:  marco / cca / cerl

rmh@apple.com (Rick Holzgrafe) (04/10/91)

In article <1991Apr9.203739.29376@ux1.cso.uiuc.edu> 
dmmg1176@uxa.cso.uiuc.edu (David M Marcovitz) writes:
> I assume I can do something with TickCount and GetDblTime in my
> object's DoClick method, but I would rather have a DoDoubleClick
> method that gets a message when I double click (and not have the
> DoClick method get a message).

It's poor practice to do as you suggest. It requires your application to 
wait the full double-click time before deciding what to do about a 
mouseDown. This delay is noticable to the user and will make your app seem 
sluggish.

Proper behavior is for the double-click action to be an action taken in 
addition to (rather than instead of) the single-click action. For example, 
in the Finder, the first click selects and highlights the icon, the second 
(if it occurs within GetDblTime()) opens all selected icons. This lets the 
Finder react instantly to the first click.

There is a global variable in the Think Class Library which counts clicks. 
It's called "gClicks". In your DoClick method:

    if (gClicks < 2)
        { /* Do single-click action */ }
    else
        { /* Do double-click action */ }

> a single click (and holding the cursor down) allows you to
> drag an icon around the screen; a double click allows you to edit the
> icon's name.

You might put a little "stickiness" on the drag: the user must move the 
mouse at least two pixels before the icon begins following the mouse. That 
way, a slightly sloppy double-click won't jiggle the icon out of position, 
when all the user really wants is to edit the name. It should help 
preserve the illusion that click-and-drag does something completely 
different from double-click.

Hope this helps.

==========================================================================
Rick Holzgrafe              |    {sun,voder,nsc,mtxinu,dual}!apple!rmh
Software Engineer           | AppleLink HOLZGRAFE1          rmh@apple.com
Apple Computer, Inc.        |  "All opinions expressed are mine, and do
20525 Mariani Ave. MS: 3-PK |    not necessarily represent those of my
Cupertino, CA 95014         |        employer, Apple Computer Inc."

dmmg1176@uxa.cso.uiuc.edu (David M Marcovitz) (04/15/91)

This is a "summary" of the responses I got about how to do a
double-click in THINK C.

The main issue is that a double click is two distinct clicks.  The
first click should be treated like a normal click, and the second
click should be handled in a special way (if you want).  Thus, in a
double click, the first click is processed assuming there may or may
not be a second click.  If the firts click highlights something and
the second opens it, a double click should not just open the object;
it should highlight it first.

Given this, the method I suggested in the first note (saving the time
of the last click and checking to see if the new click is less than
GetDblTime() away from that) will work.  However, in THINK C, there is
a variable gClicks that will count how many clicks it took to get you
to the current event.  These variables can be checked in the
DoMouseDown method of the object.


--
David M. Marcovitz                     |  internet: marcovitz@uiuc.edu
Computer-based Education Research Lab  |            dmmg1176@uxa.cso.uiuc.edu
University of Illinois                 |  novanet:  marco / cca / cerl