I am new to Purescript. I am working with MouseEvents from
"import DOM.HTML.Event.EventTypes" and I couldn't understand the difference between Mouseup, Mousedown,Mouseout and Mouseleave.
I searched for documentation but couldn't find an explanation for it.
I would like to know when each of it is getting triggered.
MouseDown occurs when a mouse button is pressed, MouseUp when the button is released. MouseLeave occurs when the mouse pointer leaves the element associated with the listener.
You can see documentation for a list of Web events here:
https://developer.mozilla.org/en-US/docs/Web/Events
As noted at https://developer.mozilla.org/en-US/docs/Web/Events/mouseleave:
mouseleave and mouseout are similar but differ in that mouseleave does not bubble and mouseout does. This means that mouseleave is fired when the pointer has exited the element and all of its descendants, whereas mouseout is fired when the pointer leaves the element or leaves one of the element's descendants (even if the pointer is still within the element).
There is also the click event that is usually the easiest to use.
Related
I have an ancestor form with some controls on it, some of them are associated with actions so they "acquire" their action's events (i.e. a button acquires the action's OnExecute event on its OnClick event).
Then I have another form that inherits from this one. I want one of the inherited buttons to behave differently from what's in the ancestor (yes I know, this is not good practice, but let's concentrate on the topic), so I create a new action and its OnExecute event, then set the button's action to the new one. Check if the button's OnClick event points to the new OnExecute event handler and it seems all fine.
Run the program, click on the button and surprise, the executed code is the one from the ancestor's action, not my new one!
Double check the new form, seems ok... But if I close and reopen it in the IDE, I can see the OnClick event handler of my button actually points to event handler acquired from the ancestor action, not from my new one.
The problem probably lies on the fact that the OnClick event handler, being acquired from the action, is not written to the DFM file, so when my inherited form is loaded, the OnClick event on my button isn't defined and is inherited from the ancestor form. Am I correct?
But then, how can I solve this problem?
I have a TEdit in a Delphi VCL form app (contained in a TFrame instance, if it matters). After a user indicates they are finished editing, by clicking elsewhere on the form, the caret and focus remain on this control until I click on another control, which then takes the focus. However, I want the TEdit to loose focus regardless of where the user clicks. I expect I can use ActiveControl := nil to end focus on the selected control, but I am uncertain where to invoke it.
What I want is for the focus to leave the selected control without necessarily having to transfer it to another control. I could end focus in the form's OnClick event, but that will not work if the user selects any of the other controls (also contained in frames) on my form, since the form's OnClick event is not triggered. It seems inelegant and tedious to provide separate OnClick events for each additional item on the form.
What is the global solution to achieve this behavior?
Try using the TApplication(Events).OnMessage event to look for WM_LBUTTONDOWN messages.
You can use the VCL's FindVCLWindow() or FindDragTarget() function (both in the Vcl.Controls unit) to see if there is a TWinControl located at the click coordinates. Or simpler, you can use the VCL's FindControl() function (also in the Vcl.Controls unit) to get an TWinControl directly from the message's target HWND.
If no control exists under the mouse, or if the control is not focusable (its CanFocus() method returns False), then set ActiveControl=nil. Otherwise, do nothing, and let the clicked control take focus on its own when the message is processed.
I've created a GtkComboBoxText using gtk_combo_box_text_new_with_entry. When I type into it, the "changed" callback is called for every letter.
How can I tell when the user has finished their entry?
I'd be happy to require the user to press 'Enter' at the end, but that doesn't call the callback.
(I'm using GTK+2.)
(Stackoverflow suggested another Q&A which put me on the path to enlightenment. I hadn't seen it while searching before I wrote my Q.)
It boils down to
g_signal_connect(gtk_bin_get_child(GTK_BIN(cb))/*entry*/, "activate", G_CALLBACK(entryActivated), NULL); where cb is the GtkComboBoxText (GtkWidget*). The callback is called when 'Enter' is pressed.
Pressing enter in a GtkComboBoxText that has an entry causes the child GtkEntry to emit the activate signal.
If the GtkComboBoxText contains an entry (via the 'has-entry' property), its contents can be retrieved using gtk_combo_box_text_get_active_text(). The entry itself can be accessed by calling gtk_bin_get_child() on the combo box.
https://developer.gnome.org/gtk2/stable/GtkEntry.html#GtkEntry-activate
The combo box might be considered as part of a form that has its own apply button.
You can also connect to GtkWidget signals. I can't say which event but there is one that is emitted when a widget loses keyboard focus to another widget in the same window. This would allow save on tab out. This is distinct from the window losing focus to another window which is a signal emitted on the GtkWindow. As the widget that has focus in the window does not change when a window loses focus.
In short: If any mouse button is Pressed when the mouse enters a WPF window, all mouse events are ignored regardless of whether the mouse is captured by any process.
The Challenge
Create two WPF 4.5 projects. In the first one, add a Border with a MouseDown handler. Inside that handler, do everything you can think of to release mouse capture:
this.ReleaseMouseCapture();
element.ReleaseMouseCapture(); // "sender"
Mouse.Capture(null);
while (Mouse.Captured != null)
Mouse.Captured.ReleaseMouseCapture();
ReleaseCapture(); //Win32.ReleaseCapture()
In the other project, add a MouseEnter handler to the default grid that will change its Background.
Start them both up, MouseDown on the border and "drag" to the other window. Until you release the mouse button, the second Window's background will not change.
What's really annoying is that if you stay within the first window, the attempts to "uncapture" the mouse appear to work. Add another element in the first window with a MouseEnter handler, and it will fire just fine. This implies that WPF doesn't know or care about cross-process capture. It just ignores events if any mouse button is in the Pressed state when the mouse first enters an application.
Anyone know if it's possible to have WPF elements respond to mouse events when the mouse was pressed before entering them?
Is there a standard way to separate MouseClick and MouseDown events in GWT?
If I click and hold button I still get MouseClick event together with MouseUp.
if I just click I still get MouseDown event together with MouseClick.
These events have some differences. Handle events which you need in a particular situation.
The thing is that in a general case ClickEvent includes MouseDownEvent and MouseUpEvent and cannot take place without of them. MouseDownEvent and MouseUpEvent precede ClickEvent. The same way as ClickEvent precedes DoubleClickEvent. But MouseDownEvent doesn't garantee that an ClickEvent will occur.
MouseDownEvent occurs every time when a user presses on one of the mouse buttons inside any element.
MouseUpEvent occurs when a user releases one of any mouse buttons.
and ClickEvent consists of both of these events. ClickEvent occurs when there're both these events on the same element. It's something like a combination of the mouse down and mouse up events. ClickEvent is generated only for the left mouse button unlike MouseDownEvent and MouseUpEvent.
That's ClickEvent is generated when a mouse is down then up while over an elem.
However, the mouse must stay within the same element, otherwise it won't occur.
For example, you pressed mouse down and moved outside of the element and release it. ClickEvent will not generated but MouseDownEvent will in this case.
And if you press mouse down and move outside the element, and move back in, then release it. ClickEvent will occur. And MouseDownEvent with MouseUpEvent will too.
If a user did click then this is the sequence of events:
MouseDownEvent
MouseUpEvent
ClickEvent
ClickEvent fires only after a user has released his mouse button.
Butt there's a way to create ClickEvent without generating of MouseDownEvent and MouseUpEvent:
click event will fire if a user used tab key to move the focus to a link and press Enter, but the MouseDown and MouseUp events will not.
Alternatively, you can open a link without generating ClickEvent:
click right button on a link and select on a item of dropdown list (in this case only MouseDownEvent and MouseUpEvent will fire)
also you can just pick up and drag a link to a new tab