diff --git a/include/wx/compositewin.h b/include/wx/compositewin.h index 8483414686..23ee6f738b 100644 --- a/include/wx/compositewin.h +++ b/include/wx/compositewin.h @@ -186,8 +186,21 @@ private: // support) to hook into its event processing. wxWindow *child = event.GetWindow(); - if ( child == this ) - return; // not a child, we don't want to bind to ourselves + + // Check that it's one of our children: it could also be this window + // itself (for which we don't need to handle focus at all) or one of + // its grandchildren and we don't want to bind to those as child + // controls are supposed to be well-behaved and get their own focus + // event if any of their children get focus anyhow, so binding to them + // would only result in duplicate events. + // + // Notice that we can't use GetCompositeWindowParts() here because the + // member variables that are typically used in its implementation in + // the derived classes would typically not be initialized yet, as this + // event is generated by "m_child = new wxChildControl(this, ...)" code + // before "m_child" is assigned. + if ( child->GetParent() != this ) + return; child->Bind(wxEVT_SET_FOCUS, &wxCompositeWindow::OnSetFocus, this);