X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bac957422a5fb858173f7c0643dd1c0f5ae2d506..44ba8f0ea92f65d9893ce0780971745a5d8e80ea:/src/gtk/listbox.cpp?ds=sidebyside diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 20c77eec98..b81275e629 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -21,6 +21,7 @@ #include "wx/intl.h" #include "wx/checklst.h" #include "wx/settings.h" +#include "wx/gtk/private.h" #if wxUSE_TOOLTIPS #include "wx/tooltip.h" @@ -37,14 +38,6 @@ 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 +60,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 +78,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; @@ -336,7 +336,6 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, { m_needParent = TRUE; m_acceptsFocus = TRUE; - m_isListBox = TRUE; m_prevSelection = 0; // or -1 ?? m_blockEvent = FALSE; @@ -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( @@ -393,8 +388,6 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, gtk_widget_show( GTK_WIDGET(m_list) ); - SetBestSize( size ); - if ( style & wxLB_SORT ) { // this will change DoAppend() behaviour @@ -411,11 +404,15 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, DoAppend(choices[i]); } + // call it after appending the strings to the listbox, otherwise it doesn't + // work correctly + SetBestSize( size ); + m_parent->DoAddChild( this ); PostCreation(); - SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) ); + SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ) ); SetForegroundColour( parent->GetForegroundColour() ); SetFont( parent->GetFont() ); @@ -541,7 +538,7 @@ void wxListBox::GtkAddItem( const wxString &item, int pos ) } #endif // wxUSE_CHECKLISTBOX - list_item = gtk_list_item_new_with_label( label.mbc_str() ); + list_item = gtk_list_item_new_with_label( wxGTK_CONV( label ) ); GList *gitem_list = g_list_alloc (); gitem_list->data = list_item; @@ -667,6 +664,12 @@ void wxListBox::Clear() wxCHECK_RET( m_list != NULL, wxT("invalid listbox") ); gtk_list_clear_items( m_list, 0, GetCount() ); + + if ( GTK_LIST(m_list)->last_focus_child != NULL ) + { + // This should be NULL, I think. + GTK_LIST(m_list)->last_focus_child = NULL; + } if ( HasClientObjectData() ) { @@ -735,7 +738,7 @@ void wxListBox::SetString( int n, const wxString &string ) #endif // wxUSE_CHECKLISTBOX str += string; - gtk_label_set( label, str.mbc_str() ); + gtk_label_set( label, wxGTK_CONV( str ) ); } else { @@ -753,7 +756,11 @@ wxString wxListBox::GetString( int n ) const GtkBin *bin = GTK_BIN( child->data ); GtkLabel *label = GTK_LABEL( bin->child ); - wxString str = wxString(GET_REAL_LABEL(label->label),*wxConvCurrent); +#ifdef __WXGTK20__ + wxString str = wxGTK_CONV_BACK( gtk_label_get_text( label ) ); +#else + wxString str = wxString( label->label ); +#endif return str; } @@ -782,7 +789,11 @@ int wxListBox::FindString( const wxString &item ) const GtkBin *bin = GTK_BIN( child->data ); GtkLabel *label = GTK_LABEL( bin->child ); - wxString str = wxString(GET_REAL_LABEL(label->label),*wxConvCurrent); +#ifdef __WXGTK20__ + wxString str = wxGTK_CONV_BACK( gtk_label_get_text( label ) ); +#else + wxString str = wxString( label->label ); +#endif if (str == item) return count; @@ -1021,6 +1032,15 @@ void wxListBox::OnInternalIdle() } } + if (g_delayedFocus == this) + { + if (GTK_WIDGET_REALIZED(m_widget)) + { + gtk_widget_grab_focus( m_widget ); + g_delayedFocus = NULL; + } + } + UpdateWindowUI(); } @@ -1038,7 +1058,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; @@ -1052,4 +1072,13 @@ wxSize wxListBox::DoGetBestSize() const return wxSize(lbWidth, lbHeight); } -#endif +void wxListBox::FixUpMouseEvent(GtkWidget *widget, wxCoord& x, wxCoord& y) +{ + // the mouse event coords are relative to the listbox items, we need to + // translate them to the normal client coords + x += widget->allocation.x; + y += widget->allocation.y; +} + +#endif // wxUSE_LISTBOX +