Use RAII SelectionEventsSuppressor in wxGTK wxDataViewCtrl code
This is simpler and safer than always remembering to call GtkDisableSelectionEvents() and GtkEnableSelectionEvents() in pairs. No real changes.
This commit is contained in:
@@ -188,6 +188,25 @@ public:
|
||||
|
||||
int GTKGetUniformRowHeight() const { return m_uniformRowHeight; }
|
||||
|
||||
// Simple RAII helper for disabling selection events during its lifetime.
|
||||
class SelectionEventsSuppressor
|
||||
{
|
||||
public:
|
||||
explicit SelectionEventsSuppressor(wxDataViewCtrl* ctrl)
|
||||
: m_ctrl(ctrl)
|
||||
{
|
||||
m_ctrl->GtkDisableSelectionEvents();
|
||||
}
|
||||
|
||||
~SelectionEventsSuppressor()
|
||||
{
|
||||
m_ctrl->GtkEnableSelectionEvents();
|
||||
}
|
||||
|
||||
private:
|
||||
wxDataViewCtrl* const m_ctrl;
|
||||
};
|
||||
|
||||
protected:
|
||||
virtual void DoSetExpanderColumn() wxOVERRIDE;
|
||||
virtual void DoSetIndent() wxOVERRIDE;
|
||||
|
@@ -5068,7 +5068,7 @@ void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel )
|
||||
{
|
||||
wxCHECK_RET( m_internal, "model must be associated before calling SetSelections" );
|
||||
|
||||
GtkDisableSelectionEvents();
|
||||
SelectionEventsSuppressor noSelection(this);
|
||||
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
|
||||
|
||||
@@ -5093,8 +5093,6 @@ void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel )
|
||||
iter.user_data = (gpointer) item.GetID();
|
||||
gtk_tree_selection_select_iter( selection, &iter );
|
||||
}
|
||||
|
||||
GtkEnableSelectionEvents();
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::Select( const wxDataViewItem & item )
|
||||
@@ -5103,7 +5101,7 @@ void wxDataViewCtrl::Select( const wxDataViewItem & item )
|
||||
|
||||
ExpandAncestors(item);
|
||||
|
||||
GtkDisableSelectionEvents();
|
||||
SelectionEventsSuppressor noSelection(this);
|
||||
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
|
||||
|
||||
@@ -5111,15 +5109,13 @@ void wxDataViewCtrl::Select( const wxDataViewItem & item )
|
||||
iter.stamp = m_internal->GetGtkModel()->stamp;
|
||||
iter.user_data = (gpointer) item.GetID();
|
||||
gtk_tree_selection_select_iter( selection, &iter );
|
||||
|
||||
GtkEnableSelectionEvents();
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::Unselect( const wxDataViewItem & item )
|
||||
{
|
||||
wxCHECK_RET( m_internal, "model must be associated before calling Unselect" );
|
||||
|
||||
GtkDisableSelectionEvents();
|
||||
SelectionEventsSuppressor noSelection(this);
|
||||
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
|
||||
|
||||
@@ -5127,8 +5123,6 @@ void wxDataViewCtrl::Unselect( const wxDataViewItem & item )
|
||||
iter.stamp = m_internal->GetGtkModel()->stamp;
|
||||
iter.user_data = (gpointer) item.GetID();
|
||||
gtk_tree_selection_unselect_iter( selection, &iter );
|
||||
|
||||
GtkEnableSelectionEvents();
|
||||
}
|
||||
|
||||
bool wxDataViewCtrl::IsSelected( const wxDataViewItem & item ) const
|
||||
@@ -5146,24 +5140,20 @@ bool wxDataViewCtrl::IsSelected( const wxDataViewItem & item ) const
|
||||
|
||||
void wxDataViewCtrl::SelectAll()
|
||||
{
|
||||
GtkDisableSelectionEvents();
|
||||
SelectionEventsSuppressor noSelection(this);
|
||||
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
|
||||
|
||||
gtk_tree_selection_select_all( selection );
|
||||
|
||||
GtkEnableSelectionEvents();
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::UnselectAll()
|
||||
{
|
||||
GtkDisableSelectionEvents();
|
||||
SelectionEventsSuppressor noSelection(this);
|
||||
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
|
||||
|
||||
gtk_tree_selection_unselect_all( selection );
|
||||
|
||||
GtkEnableSelectionEvents();
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::EnsureVisible(const wxDataViewItem& item,
|
||||
|
Reference in New Issue
Block a user