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
This commit is contained in:
Robert Roebling
2001-11-17 22:32:15 +00:00
parent c6ac78a61e
commit bac957422a
4 changed files with 18 additions and 74 deletions

View File

@@ -76,8 +76,6 @@ public:
// implementation from now on // implementation from now on
void GtkDisableEvents();
void GtkEnableEvents();
void GtkAddItem( const wxString &item, int pos=-1 ); void GtkAddItem( const wxString &item, int pos=-1 );
int GtkGetIndex( GtkWidget *item ) const; int GtkGetIndex( GtkWidget *item ) const;
GtkWidget *GetConnectWidget(); GtkWidget *GetConnectWidget();
@@ -96,7 +94,9 @@ public:
bool m_hasCheckBoxes; bool m_hasCheckBoxes;
#endif // wxUSE_CHECKLISTBOX #endif // wxUSE_CHECKLISTBOX
int m_prevSelection; int m_prevSelection;
bool m_blockEvent;
protected: protected:
virtual wxSize DoGetBestSize() const; virtual wxSize DoGetBestSize() const;

View File

@@ -76,8 +76,6 @@ public:
// implementation from now on // implementation from now on
void GtkDisableEvents();
void GtkEnableEvents();
void GtkAddItem( const wxString &item, int pos=-1 ); void GtkAddItem( const wxString &item, int pos=-1 );
int GtkGetIndex( GtkWidget *item ) const; int GtkGetIndex( GtkWidget *item ) const;
GtkWidget *GetConnectWidget(); GtkWidget *GetConnectWidget();
@@ -96,7 +94,9 @@ public:
bool m_hasCheckBoxes; bool m_hasCheckBoxes;
#endif // wxUSE_CHECKLISTBOX #endif // wxUSE_CHECKLISTBOX
int m_prevSelection; int m_prevSelection;
bool m_blockEvent;
protected: protected:
virtual wxSize DoGetBestSize() const; virtual wxSize DoGetBestSize() const;

View File

@@ -267,9 +267,12 @@ static void gtk_listitem_select_cb( GtkWidget *widget, wxListBox *listbox, bool
if (!listbox->m_hasVMT) return; if (!listbox->m_hasVMT) return;
if (g_blockEventsOnDrag) return; if (g_blockEventsOnDrag) return;
if (listbox->m_blockEvent) return;
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() ); wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
event.SetEventObject( listbox ); event.SetEventObject( listbox );
// MSW doesn't do that either // MSW doesn't do that either
// event.SetExtraLong( (long) is_selection ); // event.SetExtraLong( (long) is_selection );
@@ -335,6 +338,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
m_acceptsFocus = TRUE; m_acceptsFocus = TRUE;
m_isListBox = TRUE; m_isListBox = TRUE;
m_prevSelection = 0; // or -1 ?? m_prevSelection = 0; // or -1 ??
m_blockEvent = FALSE;
if (!PreCreation( parent, pos, size ) || if (!PreCreation( parent, pos, size ) ||
!CreateBase( parent, id, pos, size, style, validator, name )) !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") ); wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
GtkDisableEvents(); m_blockEvent = TRUE;
if (select) if (select)
{ {
@@ -868,7 +872,7 @@ void wxListBox::SetSelection( int n, bool select )
else else
gtk_list_unselect_item( m_list, n ); gtk_list_unselect_item( m_list, n );
GtkEnableEvents(); m_blockEvent = FALSE;
} }
void wxListBox::DoSetFirstItem( int n ) void wxListBox::DoSetFirstItem( int n )
@@ -940,38 +944,6 @@ void wxListBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
} }
#endif // wxUSE_TOOLTIPS #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() GtkWidget *wxListBox::GetConnectWidget()
{ {
return GTK_WIDGET(m_list); return GTK_WIDGET(m_list);

View File

@@ -267,9 +267,12 @@ static void gtk_listitem_select_cb( GtkWidget *widget, wxListBox *listbox, bool
if (!listbox->m_hasVMT) return; if (!listbox->m_hasVMT) return;
if (g_blockEventsOnDrag) return; if (g_blockEventsOnDrag) return;
if (listbox->m_blockEvent) return;
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() ); wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
event.SetEventObject( listbox ); event.SetEventObject( listbox );
// MSW doesn't do that either // MSW doesn't do that either
// event.SetExtraLong( (long) is_selection ); // event.SetExtraLong( (long) is_selection );
@@ -335,6 +338,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
m_acceptsFocus = TRUE; m_acceptsFocus = TRUE;
m_isListBox = TRUE; m_isListBox = TRUE;
m_prevSelection = 0; // or -1 ?? m_prevSelection = 0; // or -1 ??
m_blockEvent = FALSE;
if (!PreCreation( parent, pos, size ) || if (!PreCreation( parent, pos, size ) ||
!CreateBase( parent, id, pos, size, style, validator, name )) !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") ); wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
GtkDisableEvents(); m_blockEvent = TRUE;
if (select) if (select)
{ {
@@ -868,7 +872,7 @@ void wxListBox::SetSelection( int n, bool select )
else else
gtk_list_unselect_item( m_list, n ); gtk_list_unselect_item( m_list, n );
GtkEnableEvents(); m_blockEvent = FALSE;
} }
void wxListBox::DoSetFirstItem( int n ) void wxListBox::DoSetFirstItem( int n )
@@ -940,38 +944,6 @@ void wxListBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
} }
#endif // wxUSE_TOOLTIPS #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() GtkWidget *wxListBox::GetConnectWidget()
{ {
return GTK_WIDGET(m_list); return GTK_WIDGET(m_list);