File Exchange

image thumbnail

enable_editclick_no​tification

version 1.2.0.0 (1.56 KB) by David
Causes the currentobject property of a figure to be properly updated when an edit field is clicked.

0 Downloads

Updated 14 Feb 2012

View Version History

View License

format:
enable_editclick_notification(figure_handle)

When a user clicks an edit field in a matlab figure, the currentobject property of the figure is not updated immediately. Only after the user has pressed a key is the currentobject property of the figure updated to the edit field handle.

Therefore, when processing a key press, it is often unclear whether the key press should activate a hotkey or whether it is meant as input to an edit field. For example, when the user presses the right arrow key in a movie player, is the intention to advance a frame or has an edit field with a numerical value been clicked? It is not clear.

However, after calling this function with a figure handle as an input, any future clicks on an edit field will cause the currentobject property of the figure to be updated, even before the user has pressed a key. Any existing callbacks of the figure or edit fields will work as normal.

To accomplish this, the function modifies several callbacks: the buttondownfcn of the edit fields in the figure, and the figure's windowbuttondownfcn. By setting the edit fields' enable property to inactive, we can intercept clicks, which we then respond to in the appropriate way in addition to temporarily enabling the edit field. The original callbacks will be executed as normal, so long as they were of standard form (e.g. fcn(hObject, eventdata)). When the user clicks the figure background or executes an edit field callback, the edit fields are set back to inactive before the normal callback is executed.

Note that after calling this function, edit fields with the enable property set to inactive will now essentialy be on, while the off functionality will be unchanged. Edit fields' enable property should never be set programmatically to on after his function has been called. An invisible text style uicontrol will be created for the purpose of removing focus from edit fields when need be.

I tested this on windows, not sure about mac and linux. Feedback is welcome!

Cite As

David (2021). enable_editclick_notification (https://www.mathworks.com/matlabcentral/fileexchange/34060-enable_editclick_notification), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (1)

Alexander

Thanks! It is what I was looking for. It works okay, but not perfect yet, at least under linux. I haven't yet been able to find when and why it sometimes fails.

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!