Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!exodus!frisbee.Eng.Sun.COM!jcb From: jcb@frisbee.Eng.Sun.COM (Jim Becker) Newsgroups: comp.windows.open-look Subject: Re: Double Clicks in XView Message-ID: <4074@exodus.Eng.Sun.COM> Date: 6 Dec 90 19:03:00 GMT References: <4039@exodus.Eng.Sun.COM> Sender: news@exodus.Eng.Sun.COM Distribution: comp Lines: 84 In comp.windows.open-look Chris Kasso writes: In article zoo@aps1.spa.umn.edu writes: >Howdy. I'm trying to write an application that needs to be able to >distinguish between single clicks and double clicks of a mouse button. >I am using XView 2, and this processing will be in the event procedure >of a canvas. > >Does anyone have sample code for this? Thanks. > >david d [zoo] zuhn Univ. of Minnesota Dept. of Astronomy >zoo@aps1.spa.umn.edu Automated Plate Scanner Project You probably want to use an interval timer to distinguish between double and single clicks of the mouse. Here's some code that should do what you want: An easier method is simply to retain the `time' field in the XButtonEvent associated with the last ACTION_SELECT event. Then the `time' field associated with the next XButtonEvent in the following ACTION_SELECT can be tested in terms of the double click timing threshhold. Here's some snippets of code: /* * this does the check for multiclick and returns boolean */ static int txt_is_multiclick( textsw, tline, tindex ) Textob *textsw; int tline, tindex; { XButtonEvent *bevent = &textsw->xevent->xbutton; Time curtime = bevent->time; short is_multiclick = FALSE; if( tline == textsw->last_tline && tindex == textsw->last_tindex ) if( (curtime - textsw->last_time) <= textsw->click_timeout ) is_multiclick = TRUE; return is_multiclick; } static int text_notify_dispatch( textsw_pub, event, arg, type) Textsw textsw_pub; Event *event; Notify_arg arg; Notify_event_type type; { ... XEvent *aevent = event->ie_xevent; XButtonEvent *bevent = aevent->xbutton; ... textsw->click_timeout = HARDCODED_MILLISECONDS; /* init once */ textsw->xevent = aevent; ... if( txt_is_multiclick( textsw, line, index ) ) { /* inside the threshhold */ } else { /* outside the threshold */ } textsw->last_time = bevent->time; } -Jim -- -- Jim Becker / jcb%frisbee@sun.com / Sun Microsystems