image ResEx Logo
ResExcellence www : Powered by Google
Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Articles
   3D
   Audio
   Custom Controls
   General RB
   Graphics
   Hacks
   Mac OS X
   Menus
   Novelty
   Printing
   REALbasic 2005
   REALbasic 2006
   Registration
   Resources
   Reviews
   Serial
   Speech
   Sockets
   XML
   Video
Resource Links
News
   Current News
   February 2006
   January 2006
   December 2005
   November 2005
   October 2005
   September 2005
   August 2005
   July 2005
   June 2005
   May 2005
   April 2005
   March 2005









REALbasic for Dummies
by Erick Tejkowski


Learning REALbasic through Applications
by Clayton E., Crooks II


REALbasic for Macintosh
by Michael Swaine


REALbasic Cross-Platform Application Development
by Mark S. Choate





Older files are in Stuffit 5 or greater format. Newer files are ".Zip". Download StuffIt Expander
Tell us about a bad link. Thank You!

DoubleClickListbox by Seth Willits
06-05-04

Printer Version




DoubleClickListbox
I started writing an application today, a database viewer program for REAL Databases in v5.5, and I found myself looking back to my own tutorials for help! One of the classes I needed in my program was a Listbox that allowed me to double click on a cell and be notified of it. I was a little startled to see that there wasn't a tutorial for this, so I've decided to write one. The code in this class is based on that from the DoubleClickCanvas class, so you can see that tutorial for more information. The only real difference is I've updated it a bit for v5.5 to incluce Mach-O and (limited) Linux compatibility, but it's still the same simple principle.

Setup
Start out by creating a new Listbox subclass, DoubleClickCanvas. Next, create the three properties shown in the image below, as well as create the events listed here:

  • Open
  • CellClick(row as integer, column as integer, x as integer, y as integer) as Boolean
  • CellDoubleClick(row as integer, column as integer)

The Open Event
Well as you can see, the Open event is pretty simple. We simply set the two variables which are keeping track of the cell last clicked on (mLastClickRow and mLastClickColumn) to -1 in order to signify that no cell has been clicked yet, then we call the Open event of our subclass or instance, whichever it happens to be.

The CellClick Event
This is where all of the magic happens. The majority of the code is simply setting up Declares to get the users' specified double click time in ticks. On the Mac, GetDblTime returns the maximum number of ticks that can pass between double clicks, on Windows it returns milliseconds so we convert it to ticks, and on Linux, well I'm not sure what the Declare is so I cheated and used 30.

Function CellClick(row as Integer, column as Integer, x as Integer, y as Integer) As Boolean
   dim doubleClickTime as Integer
   
   #if TargetCarbon then
      #if TargetMachO then
         Declare Function GetDblTime Lib "Carbon" () as Integer
      #else
         Declare Function GetDblTime Lib "CarbonLib" () as Integer
      #endif
      doubleClickTime = GetDblTime()
   #else
      #if TargetMacOS then
         Declare Function GetDblTime Lib "InterfaceLib" () as Integer
         doubleClickTime = GetDblTime()
      #endif
   #endif
   #if TargetWin32 then
      Declare Function GetDoubleClickTime Lib "User32.DLL" () as Integer
      doubleClickTime = GetDoubleClickTime() / 1000 * 60
   #endif
   #if TargetLinux then
      doubleClickTime = 30 //???
   #endif



And below, here we deterine a) whether the difference in time between the two clicks is within the maximum limit of a valid double click, and b) whether the last click and the current click were clicks on the same cell. If they were, we just call the CellDoubleClick event.

   
   // If the two clicks happened close enough together in time
   if ((Ticks - mLastClickTicks) <= doubleClickTime) and (row = mLastClickRow) and (column = mLastClickColumn) then
      CellDoubleClick row, column
   end if
   mLastClickTicks = Ticks
   mLastClickRow = row
   mLastClickColumn = column
End Function



After that, we reset the current click time and cell clicked.

Finished
So that's it. It works like a charm. The most often use of this is probably to allow editing of a cell when it is double clicked. Rather than setting the cell or column type to "3" (editable), you can leave the cell selectable, but when it is double clicked, use Listbox.EditCell(row, column) in the CellDoubleClick event to make the cell editable. I hope you find a use for this; I know I have! As always, you can download the project here.




Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Maintained by the Staff of ResExcellence. This entire site ©1997-2006 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement. [an error occurred while processing this directive]