Simplify checks for event vetoing in generic wxDataViewCtrl code.

Don't return the whole event object from SendExpanderEvent() just to check if
it wasn't vetoed, simply return a boolean value indicating if this was the
case from this function itself.

This makes it both more efficient and easier to use.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68867 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-08-23 15:11:25 +00:00
parent d1a92cf322
commit fd48fe892c

View File

@@ -580,7 +580,8 @@ private:
int RecalculateCount(); int RecalculateCount();
wxDataViewEvent SendExpanderEvent( wxEventType type, const wxDataViewItem & item ); // Return false only if the event was vetoed by its handler.
bool SendExpanderEvent(wxEventType type, const wxDataViewItem& item);
wxDataViewTreeNode * FindNode( const wxDataViewItem & item ); wxDataViewTreeNode * FindNode( const wxDataViewItem & item );
@@ -2888,7 +2889,8 @@ wxDataViewTreeNode * wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row) co
return job.GetResult(); return job.GetResult();
} }
wxDataViewEvent wxDataViewMainWindow::SendExpanderEvent( wxEventType type, bool
wxDataViewMainWindow::SendExpanderEvent(wxEventType type,
const wxDataViewItem& item) const wxDataViewItem& item)
{ {
wxWindow *parent = GetParent(); wxWindow *parent = GetParent();
@@ -2898,8 +2900,7 @@ wxDataViewEvent wxDataViewMainWindow::SendExpanderEvent( wxEventType type,
le.SetModel(GetOwner()->GetModel()); le.SetModel(GetOwner()->GetModel());
le.SetItem( item ); le.SetItem( item );
parent->GetEventHandler()->ProcessEvent(le); return !parent->ProcessWindowEvent(le) || le.IsAllowed();
return le;
} }
bool wxDataViewMainWindow::IsExpanded( unsigned int row ) const bool wxDataViewMainWindow::IsExpanded( unsigned int row ) const
@@ -2955,12 +2956,11 @@ void wxDataViewMainWindow::Expand( unsigned int row )
if (!node->IsOpen()) if (!node->IsOpen())
{ {
wxDataViewEvent e = if ( !SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, node->GetItem()) )
SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, node->GetItem()); {
// Vetoed by the event handler.
// Check if the user prevent expanding
if( !e.IsAllowed() )
return; return;
}
node->ToggleOpen(); node->ToggleOpen();
@@ -3011,10 +3011,11 @@ void wxDataViewMainWindow::Collapse(unsigned int row)
if (node->IsOpen()) if (node->IsOpen())
{ {
wxDataViewEvent e = if ( !SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING,node->GetItem()) )
SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING,node->GetItem()); {
if( !e.IsAllowed() ) // Vetoed by the event handler.
return; return;
}
// Find out if there are selected items below the current node. // Find out if there are selected items below the current node.
bool selectCollapsingRow = false; bool selectCollapsingRow = false;