]> git.saurik.com Git - wxWidgets.git/commitdiff
Simplify checks for event vetoing in generic wxDataViewCtrl code.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 23 Aug 2011 15:11:25 +0000 (15:11 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 23 Aug 2011 15:11:25 +0000 (15:11 +0000)
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

src/generic/datavgen.cpp

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