]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/listbox.cpp
Don't do the wx cleanup if wxPython didn't do the initialization.
[wxWidgets.git] / src / gtk1 / listbox.cpp
index 9cf8883c8e0e625ff8ee6957e27c50a16fae45a4..4eefc235d3fd5ca07e2ea6b9705f2cf625f1d943 100644 (file)
 extern void wxapp_install_idle_handler();
 extern bool g_isIdle;
 
-//-------------------------------------------------------------------------
-// conditional compilation
-//-------------------------------------------------------------------------
-
-#if (GTK_MINOR_VERSION > 0)
-    #define NEW_GTK_SCROLL_CODE
-#endif
-
 //-----------------------------------------------------------------------------
 // private functions
 //-----------------------------------------------------------------------------
@@ -67,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;
 
@@ -84,14 +77,20 @@ struct wxlistbox_idle_struct
     gint         m_tag;
 };
 
-static gint wxlistbox_idle_callback( gpointer gdata )
+extern "C" gint wxlistbox_idle_callback( gpointer gdata )
 {
     wxlistbox_idle_struct* data = (wxlistbox_idle_struct*) gdata;
     gdk_threads_enter();
 
     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;
 
@@ -379,11 +378,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
 
     gtk_list_set_selection_mode( GTK_LIST(m_list), mode );
 
-#ifdef NEW_GTK_SCROLL_CODE
     gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget), GTK_WIDGET(m_list) );
-#else
-    gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_list) );
-#endif
 
     /* make list scroll when moving the focus down using cursor keys */
     gtk_container_set_focus_vadjustment(
@@ -417,7 +412,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
 
     PostCreation();
 
-    SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) );
+    SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ) );
     SetForegroundColour( parent->GetForegroundColour() );
     SetFont( parent->GetFont() );
 
@@ -1029,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();
 }
 
@@ -1046,7 +1050,7 @@ wxSize wxListBox::DoGetBestSize() const
     }
 
     // Add room for the scrollbar
-    lbWidth += wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X);
+    lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
 
     // And just a bit more
     int cx, cy;