New: Free Grid control

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:

http://files.tempel.org/RB/Grid_Control.zip

Enjoy

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.

NSEventMBS is OS X only

Garth, The areas array is a new parameter that gets passed to Paint events.

Change the code in Paint from this:

handlePaint g, areas

to:

dim areas() as REALbasic.Rect handlePaint g, areas

Does that work?

Does someone know how to get the double click interval time on Linux and Windows?

For now, just use a fixed value if you cannot compile it. E.g, use 0.5 for NSEventMBS.doubleClickInterval

From the docs:

[code]Dim DoubleClickTime as Integer
#if TargetMacOS
Declare Function GetDblTime Lib “Carbon” () as Integer
doubleClickTime = GetDblTime()
#endif

#if TargetWin32
Declare Function GetDoubleClickTime Lib “User32.DLL” () as Integer
doubleClickTime = GetDoubleClickTime()
#endif
MsgBox Str(doubleclicktime)[/code]

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?

So yes. I would presume the ms are converted to ticks.

60 ticks = 1sec so 1tick = 16.666 ms

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

Argh, once again I cannot edit a post I just made. When I wrote “The same given in the docs” I meant to write: “The sample given in the docs”.

I would go ahead and fix this damn error in the docs but I cannot - any more. I used to have access to the docs wiki at one point but it’s gone. Sigh.

Isee. And agree (though I currently have no access to a PC, not even in emulation)

I found the following: https://www.declaresub.com/ideclare/gettingstarted.html

Which agrees with you.

And obviously it is known since 2004 - see

http://www.monkeybreadsoftware.eu/listarchive-realbasic-nug/2004-06-30-2.shtml

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:

http://documentation.xojo.com/index.php/Declare#Defining_Double-clicks

Okay - new version of my grid code. Now free of MBS use. I also changed the selection method thru mouse-dragging a bit to suit my own needs better.

http://files.tempel.org/RB/Grid_Control.zip

Shouldn’t there maybe be a “if TargetCocoa” in there too?

Why? TargetMacOS includes Cocoa, doesn’t it?

But it uses the Carbon lib.

I would have thought

#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 …

Oh, I see what you mean. I’ll update the docs.

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.

Sigh. This isn’t what I signed up for :wink: