+
+#ifdef __WXMSW__
+ // 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();
+ if ( m_focus )
+ {
+ delete m_handlerFocus;
+ m_handlerFocus = new wxPopupFocusHandler(this);
+
+ m_focus->PushEventHandler(m_handlerFocus);
+ }
+#else
+ // GTK+ catches the activate events from the popup
+ // window, not the focus events from the child window
+ delete m_handlerFocus;
+ m_handlerFocus = new wxPopupFocusHandler(this);
+ PushEventHandler(m_handlerFocus);
+#endif // __WXMSW__
+
+ // catch destroy events, if you close a program with a popup shown in MSW
+ // you get a segfault if m_child or m_focus are deleted before this is
+ m_child->Connect(wxEVT_DESTROY,
+ wxWindowDestroyEventHandler(wxPopupTransientWindow::OnDestroy),
+ NULL, this);
+ m_focus->Connect(wxEVT_DESTROY,
+ wxWindowDestroyEventHandler(wxPopupTransientWindow::OnDestroy),
+ NULL, this);