Remove m_blockEvents and use Disable/Enable instead, some more rearraging
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53706 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -93,11 +93,13 @@ public:
|
||||
bool m_hasCheckBoxes;
|
||||
#endif // wxUSE_CHECKLISTBOX
|
||||
|
||||
bool m_blockEvent;
|
||||
|
||||
struct _GtkTreeEntry* GtkGetEntry(unsigned pos) const;
|
||||
void GtkDeselectAll();
|
||||
void GtkSetSelection(int n, const bool select, const bool blockEvent);
|
||||
|
||||
void GtkDisableEvents();
|
||||
void GtkEnableEvents();
|
||||
|
||||
wxArrayInt m_oldSelection;
|
||||
void GtkUpdateOldSelection();
|
||||
|
||||
protected:
|
||||
virtual void DoClear();
|
||||
|
@@ -119,8 +119,6 @@ gtk_listitem_changed_callback(GtkTreeSelection * WXUNUSED(selection),
|
||||
{
|
||||
if (g_blockEventsOnDrag) return;
|
||||
|
||||
if (listbox->m_blockEvent) return;
|
||||
|
||||
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
|
||||
event.SetEventObject( listbox );
|
||||
|
||||
@@ -367,8 +365,6 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
|
||||
long style, const wxValidator& validator,
|
||||
const wxString &name )
|
||||
{
|
||||
m_blockEvent = false;
|
||||
|
||||
if (!PreCreation( parent, pos, size ) ||
|
||||
!CreateBase( parent, id, pos, size, style, validator, name ))
|
||||
{
|
||||
@@ -435,12 +431,6 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
|
||||
|
||||
gtk_tree_view_set_enable_search(m_treeview, FALSE);
|
||||
|
||||
|
||||
GtkTreeSelection* selection = gtk_tree_view_get_selection( m_treeview );
|
||||
|
||||
g_signal_connect_after (selection, "changed",
|
||||
G_CALLBACK (gtk_listitem_changed_callback), this);
|
||||
|
||||
GtkSelectionMode mode;
|
||||
if (style & wxLB_MULTIPLE)
|
||||
{
|
||||
@@ -457,6 +447,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
|
||||
mode = GTK_SELECTION_SINGLE;
|
||||
}
|
||||
|
||||
GtkTreeSelection* selection = gtk_tree_view_get_selection( m_treeview );
|
||||
gtk_tree_selection_set_mode( selection, mode );
|
||||
|
||||
// Handle sortable stuff
|
||||
@@ -497,6 +488,9 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
|
||||
PostCreation(size);
|
||||
SetInitialSize(size); // need this too because this is a wxControlWithItems
|
||||
|
||||
g_signal_connect_after (selection, "changed",
|
||||
G_CALLBACK (gtk_listitem_changed_callback), this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -507,6 +501,24 @@ wxListBox::~wxListBox()
|
||||
Clear();
|
||||
}
|
||||
|
||||
void wxListBox::GtkDisableEvents()
|
||||
{
|
||||
GtkTreeSelection* selection = gtk_tree_view_get_selection( m_treeview );
|
||||
|
||||
g_signal_handlers_block_by_func(selection,
|
||||
(gpointer) gtk_listitem_changed_callback, this);
|
||||
}
|
||||
|
||||
void wxListBox::GtkEnableEvents()
|
||||
{
|
||||
GtkTreeSelection* selection = gtk_tree_view_get_selection( m_treeview );
|
||||
|
||||
g_signal_handlers_unblock_by_func(selection,
|
||||
(gpointer) gtk_listitem_changed_callback, this);
|
||||
|
||||
GtkUpdateOldSelection();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// adding items
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -793,44 +805,26 @@ bool wxListBox::IsSelected( int n ) const
|
||||
|
||||
void wxListBox::DoSetSelection( int n, bool select )
|
||||
{
|
||||
wxCHECK_RET( m_treeview != NULL, wxT("invalid listbox") );
|
||||
|
||||
GtkDisableEvents();
|
||||
|
||||
GtkTreeSelection* selection = gtk_tree_view_get_selection(m_treeview);
|
||||
|
||||
// passing -1 to SetSelection() is documented to deselect all items
|
||||
if ( n == wxNOT_FOUND )
|
||||
{
|
||||
// ... and not generate any events in the process
|
||||
GtkDeselectAll();
|
||||
gtk_tree_selection_unselect_all(selection);
|
||||
GtkEnableEvents();
|
||||
return;
|
||||
}
|
||||
|
||||
wxCHECK_RET( IsValid(n), wxT("invalid index in wxListBox::SetSelection") );
|
||||
|
||||
// don't generate the selection event
|
||||
GtkSetSelection(n, select, true);
|
||||
}
|
||||
|
||||
void wxListBox::GtkDeselectAll()
|
||||
{
|
||||
wxCHECK_RET( m_treeview != NULL, wxT("invalid listbox") );
|
||||
|
||||
GtkTreeSelection* selection = gtk_tree_view_get_selection(m_treeview);
|
||||
|
||||
m_blockEvent = true;
|
||||
|
||||
gtk_tree_selection_unselect_all(selection);
|
||||
|
||||
m_blockEvent = false;
|
||||
}
|
||||
|
||||
void wxListBox::GtkSetSelection(int n, const bool select, const bool blockEvent)
|
||||
{
|
||||
wxCHECK_RET( m_treeview != NULL, wxT("invalid listbox") );
|
||||
|
||||
GtkTreeSelection* selection = gtk_tree_view_get_selection(m_treeview);
|
||||
|
||||
|
||||
GtkTreeIter iter;
|
||||
wxCHECK_RET( GtkGetIteratorFor(n, &iter), wxT("Invalid index") );
|
||||
|
||||
m_blockEvent = blockEvent;
|
||||
|
||||
if (select)
|
||||
gtk_tree_selection_select_iter(selection, &iter);
|
||||
else
|
||||
@@ -843,7 +837,13 @@ void wxListBox::GtkSetSelection(int n, const bool select, const bool blockEvent)
|
||||
|
||||
gtk_tree_path_free(path);
|
||||
|
||||
m_blockEvent = false;
|
||||
GtkEnableEvents();
|
||||
}
|
||||
|
||||
void wxListBox::GtkUpdateOldSelection()
|
||||
{
|
||||
if (HasFlag(wxLB_MULTIPLE))
|
||||
GetSelections( m_oldSelection );
|
||||
}
|
||||
|
||||
void wxListBox::DoScrollToCell(int n, float alignY, float alignX)
|
||||
|
Reference in New Issue
Block a user