I’ve made a new control for my Mac app Find Any File that mimick the way the OS X Finder displays file icons in a 2-dimensional grid.
It’s written purely in REALbasic code, using a ContainerControl. You can embed this as a control into your windows quite similarly to a ListBox. It should work on all platforms, though I only tested it on OS X.
The only major difference to a Listbox is that this control does not manage the data like this Listbox does, so there’s no AddRow etc. Instead, you have to implement the CellPaint event from which you then draw your content.
The control supports multi-selection handling, including selection by dragging the mouse.
I’ve made it free. Get it here, it comes with a demo that shows off most of its abilities:
I’m trying to run it in REAL2011r3, and after adjusting for (no four segments to a Color const) (necessary 3rd parameter in New Picture method), I still get an error with the “areas” Realbasic.Rect parameter in handlePaint. I don’t show it declared anywhere, I would declare it but I don’t know what it’s for.
Markus, the WinAPI docs say that GetDoubleClickTime returns the time in ms (milliseconds). The code you quoted doesn’t seem to match that, because GetDblTime() certainly returns not ms but Tick units, right?
Markus, what I meant was: I have found code that seems to blindly use that code you quoted and seems to take the result (doubleClickTime) as if its unit were Ticks. Meaning that if the code was tested on a Mac to work right, it would certainly misbehave on Windows because the value isn’t corrected accordingly.
Would you agree that the correct code would rather be like this:
Dim doubleClickTimeInTicks as Integer
#if TargetMacOS
Declare Function GetDblTime Lib "Carbon" () as Integer
doubleClickTimeInTicks = GetDblTime()
#elseif TargetWin32
Declare Function GetDoubleClickTime Lib "User32.DLL" () as Integer
doubleClickTimeInTicks = GetDoubleClickTime() / 1000.0 * 60
#endif
MsgBox "Double click time in ticks: " + Str(doubleClickTimeInTicks)
The MS documentation states that the function returns milliseconds.
[quote]GetDoubleClickTime function
Retrieves the current double-click time for the mouse. A double-click is a series of two clicks of the mouse button, the second occurring within a specified time after the first. The double-click time is the maximum number of milliseconds that may occur between the first and second click of a double-click. The maximum double-click time is 5000 milliseconds.
Syntax
C++
UINT WINAPI GetDoubleClickTime(void);
Parameters
This function has no parameters.
Return value
Type: UINT
The return value specifies the current double-click time, in milliseconds. The maximum return value is 5000 milliseconds.[/quote]
Oh, indeed! The same given in the docs is obviously wrong, actually very bad
I found some similar code in CustomEditField (not written by me) which has the same bug. It also comes with code for Linux, and so I’ve taken the effort to test the code on Window and Linux. Now here’s the correct code for all 3 desktop platforms, returning the double click time in units of seconds:
Function DoubleClickIntervalInSeconds() As Double
#if TargetMacOS
declare function NSClassFromString lib "Cocoa" (className as CFStringRef) as Ptr
declare function doubleClickInterval lib "Cocoa" selector "doubleClickInterval" _
(classRef as Ptr) as double
static ref as Ptr = NSClassFromString("NSEvent")
return doubleClickInterval(ref)
#elseif TargetWin32
declare function GetDoubleClickTime lib "User32.DLL" () as Integer
return GetDoubleClickTime() / 1000.0
#elseif TargetLinux
Declare Function gtk_settings_get_default lib "libgtk-x11-2.0.so" as Ptr
Declare Sub g_object_get lib "libgtk-x11-2.0.so" (Obj as Ptr, _
propName as CString, byref result as Integer, n as Integer)
dim gtkSettings as MemoryBlock
gtkSettings = gtk_settings_get_default()
dim doubleClickTime as Integer
g_object_get(gtkSettings,"gtk-double-click-time",doubleClickTime, 0)
return doubleClickTime / 1000.0
#else
return 0.4 // 400ms as a fallback
#endif
End Function
Surprisingly, I am still able to made edits to the docs after all! I just cannot login thru Xojo’s own LR web browser, but with Safari it works. So I’ve fixed it. Please double check, everyone:
#if TargetCocoa
declare function NSClassFromString lib "Cocoa" (className as CFStringRef) as Ptr
declare function doubleClickInterval lib "Cocoa" selector "doubleClickInterval" _
(classRef as Ptr) as double
static ref as Ptr = NSClassFromString("NSEvent")
return doubleClickInterval(ref)
#elseif TargetCarbon
Declare Function GetDblTime Lib "Carbon" () as Integer
doubleClickTime = GetDblTime()
#elseIf TargetWin32 then
would be better (after all at some point Carbon is going to be deprecated, even if it is in 5 years) but I might be wrong
Done. I’ve done some more cleanup as well. Wow, these code examples are so awful. Apparently written by beginners instead of those who know best. I must admit that I have not tested the code though. I just wrote it as I believe it’s correct. Let me know if you spot errors.