]> git.saurik.com Git - wxWidgets.git/commitdiff
Changed/Fixed way in which wxListBox blocks events
authorRobert Roebling <robert@roebling.de>
Sat, 17 Nov 2001 22:32:15 +0000 (22:32 +0000)
committerRobert Roebling <robert@roebling.de>
Sat, 17 Nov 2001 22:32:15 +0000 (22:32 +0000)
     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
include/wx/gtk1/listbox.h
src/gtk/listbox.cpp
src/gtk1/listbox.cpp

index da536fe9c2726a9a266e3200f33ad2299fbd9f5e..5ffaa706c4e9cc6136f742fb4d58beb97f87897c 100644 (file)
@@ -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;
 
index da536fe9c2726a9a266e3200f33ad2299fbd9f5e..5ffaa706c4e9cc6136f742fb4d58beb97f87897c 100644 (file)
@@ -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;
 
index 449d4fbe014ad67378076a66ed5b26a0b3a1be90..20c77eec98523983fb94b8b59dd7b27b30dddefc 100644 (file)
@@ -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);
index 449d4fbe014ad67378076a66ed5b26a0b3a1be90..20c77eec98523983fb94b8b59dd7b27b30dddefc 100644 (file)
@@ -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);