feature request: optionally deleting the whole chain of event
handlers, when window is deleted
Vadim Zeitlin
vadim at wxwidgets.org
Mon Feb 4 00:22:14 PST 2008
On Sun, 3 Feb 2008 23:46:27 -0800 (PST) chris <cb at delta-h.de> wrote:
c> On 1 Feb., 18:15, va... at wxwidgets.org (Vadim Zeitlin) wrote:
c> > On Fri, 1 Feb 2008 03:12:07 -0800 (PST) chris <c... at delta-h.de> wrote:
c> >
c> > c> this feature would need an additional flag when adding a handler to a
c> > c> window:
c> > c>
c> > c> void wxWindowBase::PushEventHandler(wxEvtHandler *handler, const bool&
c> > c> shouldBeDeletedWithWindow = false);
c> >
c> > Unless I'm missing something, this would require adding a field to each
c> > wxEvtHandler (and hence each wxWindow) indicating whether it should be
c> > deleted with the window it is associated with. I don't think it's a good
c> > trade-off.
c>
c> Or a field in every wxWindowBase, indicating that 'all' handlers in
c> the chain should be deleted.
This is too unsafe to consider. There can be some unrelated code somewhere
which pushes its own event handler on your window and then deletes it
itself which is a perfectly valid thing to do, but with this approach it
would be deleted twice. Besides, it doesn't make sense API-wise: what if
you call PushEventHandler(handler1, true) and then PushEventHandler(handler2,
false)?
c> > The solution I use when I need to push-and-forget an event handler is to
c> > catch window destruction event in this handler and do "delete this" from
c> > it.
c>
c> I do it quite similiar: I have one instance of an manager object,
c> derived from wxEvtHandler. Here i register all my dialogs etc. which
c> get extra event handling.
c> When this dialog is closed i delete all corresponding event handlers.
c> That's because I dont want to 'call delete' this anywhere.
Is there any reason for this?
c> But using the flag mentioned above would be a quite cleaner and more
c> flexible solution. We wouldn't be restricted to the windows wich are
c> sending an event, when they are closed and we wouldn't have to watch
c> for wxEVT_CLOSE_WINDOW all the time.
I don't see any problem with catching wxEVT_CLOSE_WINDOW nor do I really
see why would the other approach be more flexible. IMO having each handler
decide itself whether it wants to be deleted automatically or not is still
the best thing to do.
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
More information about the wx-users
mailing list