From bac957422a5fb858173f7c0643dd1c0f5ae2d506 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sat, 17 Nov 2001 22:32:15 +0000 Subject: [PATCH] Changed/Fixed way in which wxListBox blocks events after changing its state programatically. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12463 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/listbox.h | 6 +++--- include/wx/gtk1/listbox.h | 6 +++--- src/gtk/listbox.cpp | 40 ++++++--------------------------------- src/gtk1/listbox.cpp | 40 ++++++--------------------------------- 4 files changed, 18 insertions(+), 74 deletions(-) diff --git a/include/wx/gtk/listbox.h b/include/wx/gtk/listbox.h index da536fe9c2..5ffaa706c4 100644 --- a/include/wx/gtk/listbox.h +++ b/include/wx/gtk/listbox.h @@ -76,8 +76,6 @@ public: // implementation from now on - void GtkDisableEvents(); - void GtkEnableEvents(); void GtkAddItem( const wxString &item, int pos=-1 ); int GtkGetIndex( GtkWidget *item ) const; GtkWidget *GetConnectWidget(); @@ -96,7 +94,9 @@ public: bool m_hasCheckBoxes; #endif // wxUSE_CHECKLISTBOX - int m_prevSelection; + int m_prevSelection; + bool m_blockEvent; + protected: virtual wxSize DoGetBestSize() const; diff --git a/include/wx/gtk1/listbox.h b/include/wx/gtk1/listbox.h index da536fe9c2..5ffaa706c4 100644 --- a/include/wx/gtk1/listbox.h +++ b/include/wx/gtk1/listbox.h @@ -76,8 +76,6 @@ public: // implementation from now on - void GtkDisableEvents(); - void GtkEnableEvents(); void GtkAddItem( const wxString &item, int pos=-1 ); int GtkGetIndex( GtkWidget *item ) const; GtkWidget *GetConnectWidget(); @@ -96,7 +94,9 @@ public: bool m_hasCheckBoxes; #endif // wxUSE_CHECKLISTBOX - int m_prevSelection; + int m_prevSelection; + bool m_blockEvent; + protected: virtual wxSize DoGetBestSize() const; diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 449d4fbe01..20c77eec98 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -267,9 +267,12 @@ static void gtk_listitem_select_cb( GtkWidget *widget, wxListBox *listbox, bool if (!listbox->m_hasVMT) return; if (g_blockEventsOnDrag) return; + + if (listbox->m_blockEvent) return; wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() ); event.SetEventObject( listbox ); + // MSW doesn't do that either // event.SetExtraLong( (long) is_selection ); @@ -335,6 +338,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, m_acceptsFocus = TRUE; m_isListBox = TRUE; m_prevSelection = 0; // or -1 ?? + m_blockEvent = FALSE; if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) @@ -856,7 +860,7 @@ void wxListBox::SetSelection( int n, bool select ) { wxCHECK_RET( m_list != NULL, wxT("invalid listbox") ); - GtkDisableEvents(); + m_blockEvent = TRUE; if (select) { @@ -868,7 +872,7 @@ void wxListBox::SetSelection( int n, bool select ) else gtk_list_unselect_item( m_list, n ); - GtkEnableEvents(); + m_blockEvent = FALSE; } void wxListBox::DoSetFirstItem( int n ) @@ -940,38 +944,6 @@ void wxListBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip ) } #endif // wxUSE_TOOLTIPS -void wxListBox::GtkDisableEvents() -{ - GList *child = m_list->children; - while (child) - { - gtk_signal_disconnect_by_func( GTK_OBJECT(child->data), - GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); - - if (HasFlag(wxLB_MULTIPLE) || HasFlag(wxLB_EXTENDED)) - gtk_signal_disconnect_by_func( GTK_OBJECT(child->data), - GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback), (gpointer)this ); - - child = child->next; - } -} - -void wxListBox::GtkEnableEvents() -{ - GList *child = m_list->children; - while (child) - { - gtk_signal_connect( GTK_OBJECT(child->data), "select", - GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); - - if (HasFlag(wxLB_MULTIPLE) || HasFlag(wxLB_EXTENDED)) - gtk_signal_connect( GTK_OBJECT(child->data), "deselect", - GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback), (gpointer)this ); - - child = child->next; - } -} - GtkWidget *wxListBox::GetConnectWidget() { return GTK_WIDGET(m_list); diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index 449d4fbe01..20c77eec98 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -267,9 +267,12 @@ static void gtk_listitem_select_cb( GtkWidget *widget, wxListBox *listbox, bool if (!listbox->m_hasVMT) return; if (g_blockEventsOnDrag) return; + + if (listbox->m_blockEvent) return; wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() ); event.SetEventObject( listbox ); + // MSW doesn't do that either // event.SetExtraLong( (long) is_selection ); @@ -335,6 +338,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, m_acceptsFocus = TRUE; m_isListBox = TRUE; m_prevSelection = 0; // or -1 ?? + m_blockEvent = FALSE; if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) @@ -856,7 +860,7 @@ void wxListBox::SetSelection( int n, bool select ) { wxCHECK_RET( m_list != NULL, wxT("invalid listbox") ); - GtkDisableEvents(); + m_blockEvent = TRUE; if (select) { @@ -868,7 +872,7 @@ void wxListBox::SetSelection( int n, bool select ) else gtk_list_unselect_item( m_list, n ); - GtkEnableEvents(); + m_blockEvent = FALSE; } void wxListBox::DoSetFirstItem( int n ) @@ -940,38 +944,6 @@ void wxListBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip ) } #endif // wxUSE_TOOLTIPS -void wxListBox::GtkDisableEvents() -{ - GList *child = m_list->children; - while (child) - { - gtk_signal_disconnect_by_func( GTK_OBJECT(child->data), - GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); - - if (HasFlag(wxLB_MULTIPLE) || HasFlag(wxLB_EXTENDED)) - gtk_signal_disconnect_by_func( GTK_OBJECT(child->data), - GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback), (gpointer)this ); - - child = child->next; - } -} - -void wxListBox::GtkEnableEvents() -{ - GList *child = m_list->children; - while (child) - { - gtk_signal_connect( GTK_OBJECT(child->data), "select", - GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); - - if (HasFlag(wxLB_MULTIPLE) || HasFlag(wxLB_EXTENDED)) - gtk_signal_connect( GTK_OBJECT(child->data), "deselect", - GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback), (gpointer)this ); - - child = child->next; - } -} - GtkWidget *wxListBox::GetConnectWidget() { return GTK_WIDGET(m_list); -- 2.45.2