Ignore OnClick before OnDblClick - lazarus

I have a TDBgrid with an OnCellClick event that toggles a Boolean.
I want to be able to launch another Form with a OnDblClick but do not want the OnCellClick to change the Boolean.
Short of programatically calling the OnCellClick to revert the Boolean as part of the OnDblClick handling, is there any way to ignore the OnCellClick when double-clicking?
I do not want a Popup menu or Right-click as this is mostly going to be on touch screen devices.

Here's what TurboPower did in the VisualPlanIt components:
Remove the OnClick handler. Add a timer. Its interval length should be slightly longer than the duration of the double-click, i.e. a few tenths of a second. In the MouseDown event start the timer. In the timer's OnTimer handler disable the timer and perform the action that should occur in the regular OnClick event. If a second click occurs while the timer is active it must be a double-click.
This sequence separates the single from the double click. To me, however, it is a bit disturbing because a normal mouse click sees a reaction only after a short delay.

Or put your form opening on CTRL-Click.

Related

Polymer 1.0 Unable to stop on-tap event propagation

I have a paper-button with the on-tap function that opens a paper-dialog that contains a "Accept" paper-button that will close it when clicked.
The problem i'm getting is if depending on my screen resolution, and the dialog's "Accept" button is over the initial button to open the dialog, when clicked, the dialog opens and closes. I'm assuming the on-tap event is being fired to both.
I've tried these 2 methods but they do not seem to help.
event.cancelBubble = true;
event.stopPropagation();
The problem is that a capacitive screens or even mouses can generate multiple tap event on the same spot within a few milisec.
The mouses because a quick change in a high and low voltage (logical 1 and 0) generating an AC signal wich can jump trough on a capacitator (which can be the button two contactor between the air) if the conditions matching. But the onclick event is already catching this case and you does not require to do anything to solve it.
The capacitve screens are capacitators and just rolling your finger should trigger multiple tap events because your skin has different depth of insulation and hard to mark the tap begin and end in some cases.
This physical problem should be solved by the platform, but it is not in every situation currently (but most of the devices are filtering this). Im usally solving this isse with a transparent overlay element wich can catch the pointer events for a little duration so I could catch the "prelling" of a button or the capacitive screen for a few ms.
If a 10-20ms is enough for you then wait a frame in your on-tap function with requestAnimationFrame and then show the dialog. Cheap trick, but it does what it has to, but ultimately you can wait a fix timeout to show the dialog, because you have 100ms to respond a user interaction.
You cannot fix this by manipulating the browser events options though because as I know you dont have option to how much time need to pass until the next same event should happend. But if you wait a frame thats could behave like you add a delay between the events.

Doing something during a button is pressed in Windows Phone

How can I do something (I want to increment a variable and display it on the screen) during someone pressed the button. Actually there is no event called OnPressed for a button in Windows Phone.
The Button has a Click event that you can handle and use to perform your logic.
In order to execute logic for the duration of the press, handle the ManipulationStarted and ManipulationEnded events.
In addition to the click event, you can use Tap event.
The problem is that your button will handle the event and prevent it from bubbling - if that wasn't the case you could use MouseLeftButtonDown/Up events to do this.
However there is a way to get around this and still get the event by using the more tedious UIElement.AddHandler method.
Ex:
myButton.AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(myMouseEventHandlerMethod), true);
The last bit ('true') is important since this overrides the event bubbling. 'myMouseEventHandlerMethod' is the method that you usually would use for handling a MouseLeftButtonDown event.
Handling 'Up' is the same thing. You probably also want to handle "Leave", or use CaptureMouse() when down triggers.

What does it mean if an event is Signaled or not?

In Windows especially, is it true that the thread will exit if the event is signaled. What does it mean when an event is signaled?
First of all, you must understand what an event is. Any performance of UI or programmatic action can be called as event. For eg, clicking a mouse button or pressing a keyboard key, etc.
Now, an event is signalled means the occurance of such an event.

How do GUI toolkits discriminate between a single and a double click?

As you can see in my previous question, I am currently struggling with single and double click events – I wanted to perform an action after a click and a completely different action after a double click. The problem is that the low-level events only tell me things like this was a mouse down or this was a mouse up and the total click count is == 2. It’s hard to discriminate between a single and a double click this way, since when the mouse comes up after a single click, I have to wait a while to make sure there’s not a second click coming.
Now I am wondering how different GUI toolkits handle this, as there’s no magical way around. You can’t have separate high-level single-click and double-click events without having the single-click event delayed or something, can you?
(It looks like the usual way to solve this is to have the single and double click actions related, like selection on the first click and app launch on the second. That way it does not matter that the single-click action is triggered along with the double-click one. Am I right?)
You always need some sort of timer to distinguish between single and double click. Think about it: you cannot predict whether a second click will happen once the first occurred, you just have to wait and see.
On iOS, you can have gesture recognizers. And if you only register a single tap recognizer it fires right away, but as soon you also register a double tap recognizer you notice that a single tap doesn't fire right away but only after a noticeable delay. Made me change to a a single tap with two fingers in one app because the delay is really annoying.
You could work around the delay if your single click action is undoable or cancelable: do the action when click count == 1, and if click count == 2, revert the action of the single click. Might result in undesired/unexpected UI behavior, though (from a user perspective).

Detecting a single mouse click in MFC

In MFC a double-mouse click event triggers the following sequence of messages
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBCLK
WM_LBUTTONUP
So responding to the WM_LBUTTONDBCLK message allows you to detect a double-click. But if I just want to detect a single-click how to I distinguish it?
But just looking at the WM_LBUTTONUP message isn't enough as it could be a single-click or it could be the first click of a double-click.
How can I successfully identify just a single-click?
(Please allow me to call these events Mouse Up and Mouse Down. My MFC is a little rusty. And there's this stuff called .NET who's been messing up my terminology lately ;-)
Short story: You don't simply want to know about Mouse Click. You need more.
Long story:
Although this is counter-intuitive, it appears that simply wanting a mouse-click is fairly uncommon. Most often, you'll want to perform some processing on Mouse Down and do some further processing on Mouse Up. The trick is that simply tracking Mouse Up messages is not enough: Mouse Down may not have happened in your window. Do you consider it a valid click then? Especially considering that the Mouse Down processing (such as selecting an item) did not occur.
Going further up the reasoning, you should not rely on receiving a Mouse Up after you processed Mouse Down: User may have moved the mouse and released the button somewhere else (think drag'n'drop), in which case, you don't receive the MouseUp event... unless you capture the mouse on MouseDown to make sure you get mouse event up to Mouse Up even if the mouse left your window.
All in all, you end up tracking Mouse Down, capture the mouse and when you receive Mouse Up, just check if you own the capture. If not, the mouse was either double-clicked (no 2nd mouse down) or Mouse Down happened somewhere else hence you most likely don't care about this Mouse Up.
In conclusion: There's no MouseClick message simply because you wouldn't go very far with it: You need to handle more messages and implement more mechanics anyway.
Oh! And if your dealing with an existing control which already handles all this items and selection stuff, such as a listview, chances are it provides with a similar custom notification such as Item Activate or Item Selection Changed.
I just tried this in Delphi, the behavior is the same: even when a double click is happening, a single click event is issued right after the first one of the two.
I solved it using a timer, which works like this:
deactivate timer on WM_LBUTTONDBLCLK (and set bDbl to true)
activate timer on WM_LBUTTONUP if bDbl==false
deactivate on WM_LBUTTONUP if bDbl==true (and reset bDbl)
I set the interval of the timer to the time returned by GetDoubleClickTime.
MSDN says:
The 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.
If the timer happens to fire then you have the real click. In my case the double click interval is 500ms, so any "real click" will be delayed this long.
You could check WM_LBUTTONDOWN has not been called more than once before WM_LBUTTONUP. In practice Windows does this for you, in that if you get a WM_LBUTTONDBCLK you tend not to get a WM_LBUTTONUP.
You can use PreTranslateMessage() to count the messages as they appear. If you've received only the mouse messages corresponding to a single-click, and the system-configured time for double-clicking has expired, you can safely assume it's a single-click.
As far as I know there is no way to know that this is the case as it is happening, which makes sense -- until the time is expired, there's no way to know that a second click is or isn't coming.
that's a little tricky.
I would detect the WM_LBUTTONDOWN & WM_LBUTTONUP combo, store that event somewhere and set a timeout for a second or so. If there isn't a WM_LBUTTONDBCLK during that timeout then you have a single click.
This might imply you need to have another thread running but I think you could accomplish it with one thread.
I think the solution is to start a timer after the first click & then check the elapsed time after at the next immediate click, this will tell you if it is a single click or double click.
You typically look at #MLButtonUp and you would not have single click and double click behavior on the same mouse button.

Resources