+
+ // There is a problem if these are still in use
+ wxASSERT(!m_handlerFocus || !m_handlerFocus->GetNextHandler());
+ wxASSERT(!m_handlerPopup || !m_handlerPopup->GetNextHandler());
+
+ if (!m_handlerPopup)
+ m_handlerPopup = new wxPopupWindowHandler(this);
+
+ m_child->PushEventHandler(m_handlerPopup);
+
+#if defined(__WXMSW__)
+ // Focusing on child of popup window does not work on MSW unless WS_POPUP
+ // style is set. We do not even want to try to set the focus, as it may
+ // provoke errors on some Windows versions (Vista and later).
+ if ( ::GetWindowLong(GetHwnd(), GWL_STYLE) & WS_POPUP )
+#endif
+ {
+ m_focus = winFocus ? winFocus : this;
+ m_focus->SetFocus();
+ }
+
+#if defined( __WXMSW__ ) || (defined( __WXMAC__) && wxOSX_USE_CARBON)
+ // MSW doesn't allow to set focus to the popup window, but we need to
+ // subclass the window which has the focus, and not winFocus passed in or
+ // otherwise everything else breaks down
+ m_focus = FindFocus();
+#elif defined(__WXGTK__)
+ // GTK+ catches the activate events from the popup
+ // window, not the focus events from the child window
+ m_focus = this;