Listbox Mousedown and DoubleClick Event

I am Returning true in a listbox mousedown event because I want to use the MouseUp to handle my code. However by doing so the listbox double-click event is not firing. How can I overcome this as I still need the double click event

I guess I could measure the number of ticks between two mousedown events and then RaiseEvent DoubleClick if it is some preset period of time.

How can I get the system double click period (OSX) but XPlat would be nice.

Depending on what you’re trying to do, you could just put the MouseUp code in the MouseDown event instead so that you do not need to return true, and then DoubleClick will also fire.

Separately you could track the clicks and create your own double-click event. There are declares to determine the system’s double-click speed. I just don’t remember what they are or which project of mine I had them in…

Thanks Tom, yes as I expected. No I can’t use the mousedown, need to use the mouse up so I will go with calculating my own double click.

I can find a carbon declare which works

   Declare Function GetDblTime Lib "Carbon" () as Integer

Is it ok to use carbon declares in a cocoa build?

Nope those will break your app. I think that’s why I had to transition everything away from it.

From what I can remember, I was using those declares to create a doubleclick event for canvases before it was built in to the canvas control. That’s probably why I don’t have the declares anymore.

Interestingly enough, though, the double-click event still fires for a canvas even if you return true from a MouseDown event. That’s probably because a listbox has to select a row before it can successfully fire the doubleclick event, and returning true from mousedown will prevent the row’s selection and any possible double click.

If you really have to do it this way you could just use a fixed double-click time. It’s hackish but most people wouldn’t notice if the double-click time for that control was off by a few milliseconds from their system’s set double-click time.

Found it (just used a fixed amount on Cocoa). I’m assuming this will still work but I haven’t used it in a long time. You just need to create a mLastClickTicks integer on the class. Call it in the MouseUp event and then fire your custom DoubleClick event.

[code]Protected Function WasDoubleClick() As boolean
dim doubleClickTime as Integer

#if TargetCocoa then
#elseif TargetCarbon then
#if not TargetMachO then
Declare Function GetDblTime Lib “CarbonLib” () as Integer
doubleClickTime = GetDblTime()
Declare Function GetDblTime Lib “Carbon” () as Integer
doubleClickTime = GetDblTime()
#elseif TargetMacOS then
Declare Function GetDblTime Lib “InterfaceLib” () as Integer
doubleClickTime = GetDblTime()
#elseif TargetWin32 then
Declare Function GetDoubleClickTime Lib “User32.DLL” () as Integer
doubleClickTime = GetDoubleClickTime() / 1000 * 60

if (Ticks - mLastClickTicks) <= doubleClickTime then
return true
end if
mLastClickTicks = Ticks

End Function

Thanks Tom, thats 2 you’ve solve for me tonight. Very much appreciated.

You’re welcome, glad to help.

This hit the sweet spot, Tom, thanks for helping me solve an annoying issue!

Thanks for sharing Tom… you’re solution works great.

for cocoa

declare function NSClassFromString lib "Cocoa" (name as CFStringRef) as Ptr declare function getTime lib "AppKit" selector "doubleClickInterval" (id As Ptr) As Double doubleClickTime = getTime(NSClassFromString("NSEvent")) * 60