Events sent programmatically

Francesco Montorsi f18m_cpp217828 at yahoo.it
Thu Sep 14 03:53:55 PDT 2006


Vadim Zeitlin ha scritto:
> On Sun, 10 Sep 2006 22:35:24 +0200 Francesco Montorsi <f18m_cpp217828 at yahoo.it> wrote:
> 
> FM> About this, there's one problem with the patch I've submitted: code 
> FM> redundancy. Very often it's difficult to make ChangeValue() without 
> FM> copying&pasting SetValue() code and then selectively removing some lines 
> FM> here and there.
> 
>  This is indeed quite bad. The last thing we need in wx code base is more
> redundancy.
> 
> FM> So, while I understand that compatibility is a very important thing, I 
> FM> propose to
> FM> 
> FM>   1) apply the patch as is, i.e. introducing some code redundancy
> FM> 
> FM>   2) provide SendUpdateEvent() functions next to ChangeSelection/Value 
> FM> so that the "migration path" for the users  is very easy: they can just 
> FM> replace every occurrence of "p->SetValue" with "p->ChangeValue(); 
> FM> p>SendUpdateEvent();"
> FM> 
> FM>   3) deprecate functions with events as soon as possible (I'd say that 
> FM> in 2.8.0 they should be deprecated) and then remove ASAP them so to 
> FM> remove code redundancy.
> 
>  Considering the amount of code using wxTextCtrl::SetValue() (I'd say just
> about any wx program more complicated than "Hello world", and this also
> includes tutorials, code snippers on the wiki and the forum, samples, ...)
> I still feel uncomfortable about it.
> 
>  I also feel bad about introducing redundancy, even if it's meant to be
> removed later. It would be really better to refactor the code to avoid it.
> I don't see why shouldn't it be possible by introducing some DoChangeXXX()
> function taking a parameter telling it whether it should or not generate
> the event (this function would be private, of course). Clearly, this would
> require more work but I think it's too dangerous to start duplicating the
> code with the hope of clearing it up later.
ok, I'll look at the patches and will try to remove as much redundancy 
as possible...


> FM> In fact, I also think that most of the user apps do not rely in a 
> FM> critical way to this aspect of wxTextCtrl and wxBookCtrl. I.e. I think 
> FM> that for most users a simple s/SetValue/ChangeValue will be enough..
> 
>  But you don't know for which occurrences it will, or not, be enough. I.e.
> in some places you would need SendUpdateEvent() but you wouldn't
> necessarily know where.
you have to re-think your design only if in your OnTextChanged() event 
handler you placed some code which needs to be executed also when the 
page is programmatically changed... in all other cases you can just do 
the s/SetValue/ChangeValue change.

Also, I think that you connect to the "text changed" event only for a 
small set of the wxTextCtrl you use in your app...


> This is potentially not a trivial change but it
> would be one which everybody be forced to do. I don't think we can justify
> forcing the user to do this if we can avoid it.
That's true...

Francesco





More information about the wx-dev mailing list