changeset 19078:4c59f69fa52c

figure: define adopted axes "currentaxes" if none is defined (bug #41573) * graphics.in.h (figure::properties::adopt): declare new custom method * graphics.cc (figure::properties::adopt): when adopting an axes, define it as currentaxes if none is already defined * graphics.cc: add %! test for currentaxes update
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Sat, 23 Aug 2014 16:12:03 +0200
parents 0976f9fccbbd
children 920a400929ca
files libinterp/corefcn/graphics.cc libinterp/corefcn/graphics.in.h
diffstat 2 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc	Thu Aug 21 16:05:09 2014 -0700
+++ b/libinterp/corefcn/graphics.cc	Sat Aug 23 16:12:03 2014 +0200
@@ -3672,6 +3672,37 @@
     }
 }
 
+void 
+figure::properties::adopt (const graphics_handle& h)
+{
+  base_properties::adopt (h);
+
+  if (! get_currentaxes ().ok ())
+    {
+      graphics_object go = gh_manager::get_object (h);
+
+      if (go.type () == "axes")
+        set_currentaxes (h.as_octave_value ());
+    }
+}
+
+/*
+%!test
+%! hf1 = figure ("visible", "off");
+%! ax1 = subplot (1,2,1);
+%! ax2 = subplot (1,2,2);
+%! hf2 = figure ("visible", "off");
+%! unwind_protect
+%!   set (ax2, "parent", hf2);
+%!   assert (get (hf2, "currentaxes"), ax2);
+%!   assert (get (hf1, "currentaxes"), ax1);
+%!   set (ax1, "parent", hf2);
+%!   assert (get (hf2, "currentaxes"), ax2);
+%! unwind_protect_cleanup
+%!   close (hf);
+%! end_unwind_protect
+*/
+
 void
 figure::properties::set_visible (const octave_value& val)
 {
--- a/libinterp/corefcn/graphics.in.h	Thu Aug 21 16:05:09 2014 -0700
+++ b/libinterp/corefcn/graphics.in.h	Sat Aug 23 16:12:03 2014 +0200
@@ -3306,6 +3306,8 @@
         }
     }
 
+    void adopt (const graphics_handle& h);
+
     void set_position (const octave_value& val,
                        bool do_notify_toolkit = true);