I’m in the process of subclassing a TextField control. I’ve created a DoubleClick event. From this subclass control I will be subclassing it further in relation to database controls which will account for text, numbers, dates etc. I’m wanting the DoubleClick event to be available when I’m working with my database forms. The code is below but my main concern is this, are there any gotchas to be aware of, especially for further subclassed controls? I’ll be using the DoubleClick event for my date entry controls, opening up a date-picker window. I also want it available for stuff that I haven’t even thought of just yet but if not activated I want the mouse functions concerned with the control to default to their normal state; hence any gotchas?
I’m also open to suggestions if the below could be coded more efficiently or differently.
Created new class : TextField_DoubleClick (I don’t use this name, only for forum purpose) Super class is TextField
Create event definition : DoubleClick ( X as Integer, Y as Integer)
Create properties: lastClickTicks, lastClickX and lastClickY (all as Integer)
Function MouseDown(X As Integer, Y As Integer) As Boolean
dim doubleClickTime, currentClickTicks as Integer
#if targetWin32 then
Declare Function GetDoubleClickTime Lib "User32.DLL" () as Integer
doubleClickTime = GetDoubleClickTime() / 10
#endif
currentClickTicks = ticks
if not IsContextualClick then // not a right click
if (currentClickTicks - lastClickTicks) <= doubleClickTime then
//if the two clicks occured close enough together in space
if abs(X - lastClickX) <= 5 and abs(Y - LastClickY) <= 5 then
HighlightWord(X,Y) // My function - simply called to highlight selected word (same as default behaviour)
RaiseEvent DoubleClick(x,y)
return true // don't need to set lastClickTicks etc. as job done, they can be reset next first click.
end if
end if
// only a single click at this time, need to record timing info so second click can be compared to it.
lastClickTicks = currentClickTicks
lastClickX = X
lastClickY = Y
end if
return false // so as not to cancel out the mouse action.
End Function
In my testing, I’ve subclassed this control further and it all appears to work, that is, if the DoubleClick event is not activated then a double click in the control merely selects a word, if any, of the control. If code is entered in the DoubleClick event then that code is activated.
ps. I’ve removed references to the Mac & Linux code. Having said that, for this instance I don’t really see the point in calling operating system functions, one could merely assume that a double click speed is quick, less than one second, maybe two.