Real Software Forums
http://forums.realsoftware.com/

Double Click Revisited
http://forums.realsoftware.com/viewtopic.php?f=21&t=41595
Page 1 of 1

Author:  kbrunner [ Sun Nov 27, 2011 12:56 pm ]
Post subject:  Double Click Revisited

When I was trying to implement the double-click on Canvas example posted here, and had quite some trouble at the beginning. Now I have re-written the whole thing a little, to make it cross platform (Windows, OS-X). Now it should be better understandable, and it can easy adjusted for other controls as well.

A) Create a new Class and name it dcCanvas
B) Set the Super of this class to Canvas
C) Add Event Definition DoubleClick
D) Add private property mouseUpT as Integer
E) Add private property mouseUpX as Integer
F) Add private property mouseUpY as Integer
G) Define the MouseDown event:
return true

H) Define the MouseUp event:
if not IsContextualClick then
if x = me.mouseUpX and y = me.mouseUpY Then
if me.mouseUpT > ticks-me.doubleClickTime() then
RaiseEvent DoubleClick
end if
end if
me.mouseUpT = ticks
me.mouseUpX = X
me.mouseUpY = Y
end if

I) Create a private method doubleClickTime as integer:
#if targetMacOS then
#if targetMachO then
Declare Function GetDblTime Lib "Carbon" () as Integer
#elseif targetCarbon then
Declare Function GetDblTime Lib "CarbonLib" () as Integer
#elseif targetMacOSClassic then
Declare Function GetDblTime Lib "InterfaceLib" () as Integer Inline68K("2EB802F0")
#endif
return GetDblTime()
#endif

#if targetWin32 then
Declare Function GetDoubleClickTime Lib "User32.DLL" () as Integer
return GetDoubleClickTime() * 6 / 100
#endif

return 30


Alternatively the doubleClickTime could be defined globally, making it available for all the "moded" classes. Also in my research if found that windows "GetDoubleClickTime" returns ms and not ticks as on OS-X. So far the examples I found, did not address that. In addition I reduced how many times the OS is called, requesting the double click time. This is not a perfect solution, but it works so far. I already used the above to modify other controls, but I yet have to test on Windows.

Edit(11/29/2011): Made some changes to the above. Now measuring the time between MouseUp and MouseDown. This improves the reaction, when the application window does not have focus.
Edit(12/1/2011): Finally got to test on Windows: The conversion from ms to ticks was wrong. Corrected the above.
Edit(12/2/2011): Changed back to measuring two mouse-downs

Author:  torrid [ Fri Jun 15, 2012 2:40 pm ]
Post subject:  Re: Double Click Revisited

Why is this not just built into Real Basic?

In Visual Basic, for example, labels have a DblClick event built in.

Author:  charonn0 [ Fri Jun 15, 2012 4:47 pm ]
Post subject:  Re: Double Click Revisited

torrid wrote:
Why is this not just built into Real Basic?

In Visual Basic, for example, labels have a DblClick event built in.

It is built in. I'm not sure what problem this code is supposed to address.

Author:  torrid [ Sat Jun 16, 2012 12:00 am ]
Post subject:  Re: Double Click Revisited

Can u clarify?

I am looking at a Label right now and there is not any double click event.

i.e. Where is it?

Author:  charonn0 [ Sat Jun 16, 2012 12:52 am ]
Post subject:  Re: Double Click Revisited

Oops, I read "Canvas" instead of "Label". :shock:

Author:  kbrunner [ Mon Jun 18, 2012 7:03 pm ]
Post subject:  Re: Double Click Revisited

charonn0 wrote:
It is built in. I'm not sure what problem this code is supposed to address.


Sorry, that was not always the case with earlier versions of RB. There was a point in time, where Canvas had no double-click event. Anyhow you can adjust the above code for elements that do not have a double-click like Label. Therefore it still has some validity.

Author:  torrid [ Mon Jul 23, 2012 6:29 pm ]
Post subject:  Re: Double Click Revisited

Yes LABEL, not canvas, is where I am looking for a double click event... I still don't understand why it does not have it. I may indeed take this code on later but for now am moving the code to some other event... that will get me by for now.

Author:  Jason_Adams [ Mon Jul 23, 2012 8:38 pm ]
Post subject:  Re: Double Click Revisited

You're right, and it is a bit odd that the DoubleClick event isn't from the RectControl super. I recommend checking Feedback to see if it has a feature request — if there isn't one, make one. :)

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/