diff libgui/graphics/Canvas.cc @ 24636:9d01ce02d5cb

Make selection and "HitTest" compatible with Matlab (bug #52795). * GLCanvas.cc (GLCanvas::selectFromAxes): Don't take "HitTest" into account during selection. * Canvas.cc (Canvas::canvasMousePressEvent): If the selected object has "HitTest"->"off" then replace it with the first ancestor with "HitTest"->"on" or fallback to empty matrix. * NEWS: Announce that HitTest property is now fully implemented.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Mon, 22 Jan 2018 16:46:59 +0100
parents ab2321d4ba03
children 13c207835e79
line wrap: on
line diff
--- a/libgui/graphics/Canvas.cc	Tue Jan 23 10:45:23 2018 +0100
+++ b/libgui/graphics/Canvas.cc	Mon Jan 22 16:46:59 2018 +0100
@@ -636,6 +636,20 @@
         // clicks.
         if (! currentObj.valid_object ())
           currentObj = figObj;
+        else if (! currentObj.get_properties ().is_hittest ())
+          {
+            // Objects with "hittest"->"off" pass the mouse event to their 
+            // parent and so on.
+            graphics_object tmpgo;
+            tmpgo = gh_manager::get_object (currentObj.get_parent ());
+            while (tmpgo && ! tmpgo.get_properties ().is_hittest ())
+              tmpgo = gh_manager::get_object (tmpgo.get_parent ());
+
+            if (tmpgo && tmpgo.get_handle () != 0.0)
+              currentObj = tmpgo;
+            else
+              currentObj = graphics_object ();
+          }
 
         if (axesObj)
           {
@@ -660,7 +674,8 @@
               // Update the figure "currentobject"
               auto& fprop = Utils::properties<figure> (figObj);
 
-              if (currentObj.get_properties ().handlevisibility_is ("on"))
+              if (currentObj 
+                  && currentObj.get_properties ().handlevisibility_is ("on"))
                 fprop.set_currentobject (currentObj.get_handle ()
                                          .as_octave_value ());
               else
@@ -678,13 +693,13 @@
                                          button_number (event));
 
               // Execute the "buttondownfcn" of the selected object
-              if (! currentObj.get ("buttondownfcn").isempty ())
+              if (currentObj && ! currentObj.get ("buttondownfcn").isempty ())
                 gh_manager::post_callback (currentObj.get_handle (),
                                            "buttondownfcn",
                                            button_number (event));
 
               // Show context menu of the selected object
-              if (event->button () == Qt::RightButton)
+              if (currentObj && event->button () == Qt::RightButton)
                 ContextMenu::executeAt (currentObj.get_properties (),
                                         event->globalPos ());
             }