git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13745 
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
 class wxPopupFocusHandler : public wxEvtHandler
 {
 public:
 class wxPopupFocusHandler : public wxEvtHandler
 {
 public:
-    wxPopupFocusHandler(wxPopupTransientWindow *popup) { m_popup = popup; }
+    wxPopupFocusHandler(wxPopupTransientWindow *popup)
+    {
+        m_popup = popup;
+
+#ifdef __WXGTK__
+        // ignore the next few OnKillFocus() calls
+        m_creationTime = time(NULL);
+#endif // __WXGTK__
+    }
 
 protected:
     // event handlers
 
 protected:
     // event handlers
 private:
     wxPopupTransientWindow *m_popup;
 
 private:
     wxPopupTransientWindow *m_popup;
 
+    // hack around wxGTK bug: we always get several kill focus events
+    // immediately after creation!
+#ifdef __WXGTK__
+    time_t m_creationTime;
+#endif // __WXGTK__
+
-    // we can't capture mouse before the window is shown in wxGTK
-#ifdef __WXGTK__
+    // we can't capture mouse before the window is shown in wxGTK, so do it
+    // first
 
     m_child->CaptureMouse();
     m_child->PushEventHandler(new wxPopupWindowHandler(this));
 
 
     m_child->CaptureMouse();
     m_child->PushEventHandler(new wxPopupWindowHandler(this));
 
-#ifndef __WXGTK__
-    Show();
-#endif
-
     m_focus = winFocus ? winFocus : this;
     m_focus->SetFocus();
 
     m_focus = winFocus ? winFocus : this;
     m_focus->SetFocus();
 
     // FIXME: I don't know why does this happen but sometimes SetFocus() simply
     //        refuses to work under MSW - no error happens but the focus is not
     //        given to the window, i.e. the assert below is triggered
     //
     //        Try work around this as we can...
     // FIXME: I don't know why does this happen but sometimes SetFocus() simply
     //        refuses to work under MSW - no error happens but the focus is not
     //        given to the window, i.e. the assert below is triggered
     //
     //        Try work around this as we can...
-#if 0
-    wxASSERT_MSG( FindFocus() == m_focus, _T("setting focus failed") );
-#else
-    m_focus = FindFocus();
-#endif
+    //wxASSERT_MSG( FindFocus() == m_focus, _T("setting focus failed") );
+    m_focus = FindFocus();
     {
         m_focus->PushEventHandler(new wxPopupFocusHandler(this));
     }
     {
         m_focus->PushEventHandler(new wxPopupFocusHandler(this));
     }
 
 void wxPopupFocusHandler::OnKillFocus(wxFocusEvent& event)
 {
 
 void wxPopupFocusHandler::OnKillFocus(wxFocusEvent& event)
 {
+#ifdef __WXGTK__
+    // ignore the next OnKillFocus() call
+    if ( time(NULL) < m_creationTime + 1 )
+    {
+        event.Skip();
+
+        return;
+    }
+#endif // __WXGTK__
+
     // when we lose focus we always disappear - unless it goes to the popup (in
     // which case we don't really lose it)
     if ( event.GetWindow() != m_popup )
     // when we lose focus we always disappear - unless it goes to the popup (in
     // which case we don't really lose it)
     if ( event.GetWindow() != m_popup )