X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b33c8d22ccc7f7d059c2d0daaa2a86f6e30e7315..f2a10cdc48bd349914b382352c18d8cfcd69f3b8:/src/gtk/listbox.cpp

diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp
index d54e30e324..4eefc235d3 100644
--- a/src/gtk/listbox.cpp
+++ b/src/gtk/listbox.cpp
@@ -59,9 +59,10 @@ extern bool g_isIdle;
 // data
 //-----------------------------------------------------------------------------
 
-extern bool       g_blockEventsOnDrag;
-extern bool       g_blockEventsOnScroll;
-extern wxCursor   g_globalCursor;
+extern bool           g_blockEventsOnDrag;
+extern bool           g_blockEventsOnScroll;
+extern wxCursor       g_globalCursor;
+extern wxWindowGTK   *g_delayedFocus;
 
 static bool       g_hasDoubleClicked = FALSE;
 
@@ -83,7 +84,13 @@ extern "C" gint wxlistbox_idle_callback( gpointer gdata )
 
     gtk_idle_remove( data->m_tag );
 
-    data->m_listbox->SetFirstItem( data->m_item );
+    // check that the items haven't been deleted from the listbox since we had
+    // installed this callback
+    wxListBox *lbox = data->m_listbox;
+    if ( data->m_item < lbox->GetCount() )
+    {
+        lbox->SetFirstItem( data->m_item );
+    }
 
     delete data;
 
@@ -1017,6 +1024,15 @@ void wxListBox::OnInternalIdle()
         }
     }
 
+    if (g_delayedFocus == this)
+    {
+        if (GTK_WIDGET_REALIZED(m_widget))
+        {
+            gtk_widget_grab_focus( m_widget );
+            g_delayedFocus = NULL;
+        }
+    }
+
     UpdateWindowUI();
 }