Opened 11 years ago

Closed 10 years ago

#11462 closed defect (fixed)

wxTextCtrl::ChangeValue() generates an event.

Reported by: talon_karrde Owned by: csomor
Priority: high Milestone: 2.9.1
Component: wxOSX Version: stable-latest
Keywords: wxTextCtrl ChangeValue generate event programatically Cc:
Blocked By: Blocking:
Patch: yes


The osx_cocoa version of wxTextCtrl::ChangeValue() generates a wxEVT_COMMAND_TEXT_UPDATED event, contrary to what the documentation states. The behaviour can be seen in the text sample, where selecting Text->"Change the first text zone value" generates an event, despite using ChangeValue() to modify the text.
I've attached a patch which fixes the issue, but I had to add an extra method to wxTextCtrl to do it. I know that this breaks binary compatibility, but I hope this is something you don't seek to preserve in the trunk right now.

Attachments (1)

ChangeValue.patch download (3.7 KB) - added by talon_karrde 10 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 11 years ago by vadz

  • Milestone set to 2.9.1

No, ABI is not preserved in the trunk and, besides, adding a new non-virtual function does preserve ABI anyhow.

Stefan, is there some better way to do this? If not I think the patch should be applied because ChangeValue() definitely shouldn't generate any events, people use it instead of SetValue() exactly to avoid them.

comment:2 Changed 10 years ago by vadz

  • Resolution set to fixed
  • Status changed from new to closed

This should have been fixed by r63881.

comment:3 Changed 10 years ago by talon_karrde

  • Resolution fixed deleted
  • Status changed from closed to reopened

ChangeValue() can still cause an event to be generated, although it doesn't happen every time. Steps to reproduce are:

  1. Open the text sample
  2. Click in the top left text ctrl (the one with the string "Prepended. Single" in it) and type a letter in it - the log window shows that the text has changed in some control
  3. From the Text menu, select "Change the first text zone value" - the log window will once again show that the text has changed in some control, which means that the call to ChangeValue() has generated an event.

N.B.: If you omit step 2, ChangeValue() behaves as expected.

Neno Ganchev

comment:4 Changed 10 years ago by talon_karrde

I've uploaded a new patch that is applicable and fixes the following issues:

  1. ChangeValue() generates an event if the user has entered text in the textctrl
  2. SetValue() generates two events if the user has entered text in the textctrl

The patch is far from clean, though, I had to make wxTextEntry::EventsAllowed() public. Perhaps there is a more general way to fix this issue but this is all I could do with my limited knowledge. If you can think of a better way to do it, please don't hesitate to enlighten me.

Neno Ganchev

comment:5 Changed 10 years ago by vadz

  • Priority changed from normal to high

I still don't understand what goes on here (what does the fact of entering text in the control changes exactly, Stefan?) but I'm pretty sure that this part of the patch can't be right as it will crash when textEntry == NULL:

if ( !textEntry || textEntry->EventsAllowed() ) { 

Stefan, any explanations would be very, very much appreciated.

Changed 10 years ago by talon_karrde

comment:6 Changed 10 years ago by talon_karrde

Yeah, that was a pretty dumb error on my part, sorry for that. I've fixed the patch FWIW.

Here's what the reference of -[NSControl currentEditor] says:

When the receiver is a control displaying editable text (for example, a text field) and it is the first responder, it has a field editor, which is returned by this method. The field editor is a single NSTextView object that is shared among all the controls in a window for light text-editing needs. It is automatically instantiated when needed.

I don't really understand the part about the field editor being shared among all controls, but the last sentence does answer the question what changes when text is entered in the control.


comment:7 Changed 10 years ago by csomor

  • Owner set to csomor
  • Status changed from reopened to accepted

comment:8 Changed 10 years ago by csomor

The text editor is the instance responsible for the GUI visible editing, there is only one editor instance for text fields and that one is shared, if a text field is in this editing mode the [m_textField currentEditor] returns the instance of its editor, otherwise nil

comment:9 Changed 10 years ago by SC

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [64662]) text updated events were not always sent out correctly, fixes #11462

Note: See TracTickets for help on using tickets.