[Implemented] CanvasGadget - Double click event

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: CanvasGadget - Double click event

Post by Shardik »

Polo wrote:If it's not possible, then a function to get the doubleclick time (like GetDoubleClickTime_() but crossplatform) :)
A cross-platform procedure to obtain the double click time: :P

Code: Select all

EnableExplicit

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
  ImportC ""
    GetDblTime()
  EndImport
CompilerEndIf

Procedure.I GetDoubleClickTime()
  Protected DoubleClickTime.I

  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux
      Protected GValue.GValue
      Protected *Settings.GtkSettings

      GValue\g_type = 6 << 2
      *Settings = gtk_settings_get_default_()
      
      If *Settings
        g_object_get_property_(*Settings, "gtk-double-click-time", @GValue)
      EndIf

      DoubleClickTime = g_value_get_int_(@GValue)
    CompilerCase #PB_OS_MacOS
      DoubleClickTime = Int(GetDblTime() * 16.666667)
    CompilerCase #PB_OS_Windows
      DoubleClickTime = GetDoubleClickTime_()
  CompilerEndSelect

  ProcedureReturn DoubleClickTime
EndProcedure

MessageRequester("Info", "Double click time = " + Str(GetDoubleClickTime()) + " ms")
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: CanvasGadget - Double click event

Post by TomS »

Shardik wrote:

Code: Select all

CompilerCase #PB_OS_MacOS
      DoubleClickTime = Int(GetDblTime() * 16.666667)
16.6?
I have no Mac, but this seems odd.
I read somewhere that some languages return the DoubleClickTime in CPU ticks rather than milliseconds.
If that's the case for the MacOS Api, 16.6 is an experimental value that may very well be different on another system. But in that case it rather be "divided by" and the number had to be higher.
Still this seems like an experimanel value.
Are you certain that is correct on each Mac?

If not the (Window)Timer for the actual double click event needs OS dependent code as well.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: CanvasGadget - Double click event

Post by Polo »

Yes the MacOSX multiplication is correct and works (I already had a double click cross platform system in place, I just would like to have this feature directly available in Purebasic :) )
I actually do * 100 / 6, but it's the same.

The reason why I'd love to have this directly from the Purebasic event is the possible switch from Carbon to Cocoa on MacOSX, which will happen one day I guess, thus why I avoid using API when i can :)
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: CanvasGadget - Double click event

Post by Shardik »

TomS wrote:16.6?
I have no Mac, but this seems odd.
I read somewhere that some languages return the DoubleClickTime in CPU ticks rather than milliseconds.
If that's the case for the MacOS Api, 16.6 is an experimental value that may very well be different on another system. But in that case it rather be "divided by" and the number had to be higher.
Still this seems like an experimanel value.
Are you certain that is correct on each Mac?
Apple's Carbon Event Manager Programming Guide wrote:The Classic Event Manager function GetDblTime returns the current value of this interval, expressed in ticks (sixtieths of a second, the time unit used by earlier versions of Mac OS).
1 Tick = 1/60 sec = 16.666667 ms

Don't you trust me, TomS ? :lol:

I even made the effort to verify different double click times with a stop watch on my Mac after changing them repeatedly in the System Settings! :twisted:
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: CanvasGadget - Double click event

Post by Polo »

Shardik wrote:I even made the effort to verify different double click times with a stop watch on my Mac after changing them repeatedly in the System Settings! :twisted:
:mrgreen:
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: CanvasGadget - Double click event

Post by freak »

I added the double click events and a native DoubleClickTime() function as well :)
quidquid Latine dictum sit altum videtur
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: CanvasGadget - Double click event

Post by Polo »

freak wrote:I added the double click events and a native DoubleClickTime() function as well :)
Thanks! :)
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: CanvasGadget - Double click event

Post by kenmo »

Awesome, thanks for the addition freak!
Post Reply