RichEdit control: Determine when text is changed? - richedit

I'm trying to count the number of times that text is changed in a given RichEdit control. I considered using events like key down, but that gets messy when you consider keys that don't change the text (like arrows, page up, etc). And how do you make sure you get all of those keys?
It seems it would be simpler to register a callback for a onTextChanged event, if one exists. Is there any way to do something like that?

Well you need to listen to the EN_CHANGE message if your using C++. Note that you also have to call SetEventMask with ENM_CHANGE to receive these notifications unlike a normal edit control will sends these messages by default.

Related

GUI: configure the racket:text% to read-only

I want to use an editor to display a log from a program, I just need a very basic text field:
With a vertical scrollbar
With a contextual menu for copy/paste
Prevent the user from changing the text
In order to activate the copy/paste menu, I use the class racket:text% from framework rather than the basic one.
How to prevent the user from changing the text?
I read the documentation, as far as I understand the closest thing I found is lock method:
https://docs.racket-lang.org/gui/editor___.html?q=lock#%28meth._%28%28%28lib._mred%2Fmain..rkt%29._editor~3c~25~3e%29._lock%29%29
But it is not convenient, as it also prevent my program to write the data.
I also find get-read-write? but cannot find set-read-write.
Use the lock method, and just unlock the editor around any modifications that you want to do. You may find it useful to write a call-with-unlock helper function or with-unlock macro.
If you do your updates from the eventspace's handler thread (and you probably should; use queue-callback if they originate from another thread), then as long as you re-lock the editor at the end of an update, the user will never be able to interact with the unlocked editor.

Handling key events in OS X with Swift and Cocoa

I have a very basic OS X that has a few different elements.
A text field, a table view and a file contents view.
I have a single ViewController.
I'd like to be able to intercept specific key events for each of these elements in the storyboard in my ViewController and change the focus between the different elements.
For example, if the cursor is currently in the file contents view, and I hit ESCAPE, I'd like for the focus to be transferred to the text field.
Or, if the focus is currently on the table view and I hit ENTER, that the cursor/focus is moved to the file contents view.
What's the best way to handle this?
I have tried overriding the keyDown method in the ViewController but with things such as autocomplete getting in the way, I'm not having much luck. I have added a print statement to keyDown to check if the function is receiving events, but it's not always fired.
Update
Except for the specific keys that I want to intercept, I want all other key events to behave as normal. For example, typing in the file contents view, or the text field.
I would highly recommend watching the WWDC talk #145 from 2010, Key Event Handling in Cocoa Applications. It gives an overview of the event delivery mechanism, and several ways of handling events:
Make a menu item or button whose keyEquivalent is the escape key.
Override cancelOperation(_:) or complete(_:), which are the two NSResponder methods which can get invoked by default when the escape key is pressed. (There are other methods for the enter/return key.)
Override sendEvent(_:) in NSApplication or NSWindow to intercept all events and bypass the default behavior.

Prevent focus loss while validating Input in JavaFX8 (as in Swing)

I'm trying to do the following. I have a TextField (or any other control) and I want to determine focus loss according to user’s input validation.
I’ve read this article https://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html#inputVerification but it seems that JavaFX does not handle focus as Swing does.
What I’m trying to achieve is: “A component's input verifier is consulted whenever the component is about to lose the focus. If the component's value is not acceptable, the input verifier can take appropriate action, such as refusing to yield the focus on the component or replacing the user's input with the last valid value and then allowing the focus to transfer to the next component.”
When a user is focused on a textfield (or any other control) I want to validate user’s input in 3 scenarios:
1) Enter key was pressed (I would listen to the KeyEvent, validate input and, if appropriate, ask to focus on the next control, but I don’t know how to do the latter).
2) TAB key was pressed (I need to intercept the focus change event).
3)Focus is lost (for example by clicking on another control or outside the Stage or even by pressing TAB key)
I need to validate user’s input and decide whether I let focus loss or no. In a way, I need to intercept the focus change event.
I can’t simply listen to de textField.focusedProperty because that only tells me that I’m loosing focus, but I can’t (or at least I don´t know how) stop it from happening.
I tried to get information about focus subsystem in JavaFX but couldn’t find any.
I’d like to know when the engine handles focus events and act according to:
a) The control that is loosing focus (and its content)
b) The possible next control in the focus sequence.
c) If the focus remains in the same Stage o if its send to another Stage or application.
I hope I’ve been clear enough with my explanation and please forgive my English if there are any mistakes.
Thank you very much in advance.

Gtk suppres focus-out

It seems for me that best place for validation of user input is in focus-out-event handler of entry type widgets (but this is only my thinking). I try to return TRUE from focus-out-event with idea that this will avoid to transfer focus to next control and keep focus on current widget, but this is not OK (not work as needed).
Which is proper way to suppress of transfering focus to next control in case when validation don't pass and where to put validation code on such widgets (gtkEntry, gtkSpinButton, etc) to be usable with signals invoked with both - mouse and keyboard actions?
That is hardly a good idea... Focus is (should be) always owned by the user. That is, the users should be able to move the focus wherever they see fit. If you try to direct the focus, or prevent moving it, based on any logic you can imagine, you will likely frustrate them.
It will surely frustrate me! Say for example that I wrote a wrong data in a box, and then I say, "hey, that's wrong! I want to select that data over there, copy it and paste it here". But I cannot do that because the program will not let me leave the box where I am now without writing an acceptable data. I have to delete the wrong data and enter something... just not good.
The best way to validate the user entry is when you actually do something with it. Either when you save it or when you make it effective. Then you can even make a pop-up saying that there is an error, and when it is close, move the focus to the first error.
If you feel that the user can benefit from an early warning that he is doing wrong, you can use colors (paint the box yellow/red if there is an error), or add a small error icon next to the box. That is waaaay less disruptive than moving the focus around.

GWT: creating a text widget for highly customized data entry

I'm trying to implement a kind of "guided typing" widget for data entry, in which the user's text entry is highly controlled and filtered. When the user types a particular character I need to intercept and filter it before displaying it in the widget. Imagine if
you will, a Unix shell embedded as a webapp; that's the kind of thing I'm trying to implement. I've tried two approaches.
In the first, I extend a TextArea, and add a KeyPressHandler to filter the characters. This works, but the browser-provided spelling correction is totally inappropriate, and I don't see how to turn it off. I've tried:
DOM.setElementProperty(textArea.getElement(),
"spellcheck", "false");
But that seems to have no effect- I still get the red underlines over
"typos".
In the second approach I use a FocusWidget to get KeyPress events, and a separate Label or HTML widget to present the filtered characters back to the user. This avoids the spelling correction issue, but since the FocusWidget is not a TextArea, the browser tends to intercept certain typed characters for internal use; e.g. FireFox will use the "/" character to begin a "Quick Find" on the page, and hitting Backspace will load the previous web page.
Is there a better way to accomplish what I'm trying to do?
You might just be able to use event.preventDefault() on your keypress events to avoid these browser behaviors. Otherwise, maybe a hybrid of the two approaches? Have a hidden TextArea with focus, accepting key events, and then post the typed characters to a separate Label.
There is no specific GWT method on TextBox for this, but this simple line of
GWT code fixes the problem for Chrome (for other browsers, YMMV - it may depend upon how completely they implement HTML5) by setting an attribute on the underlying input element:
myTextBox.getElement().setAttribute("spellCheck", "false");
Perhaps this attribute is a relatively new feature.