diff libinterp/corefcn/graphics.cc @ 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 da7d9e4bda8c
children 1288a2f27769
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)
 {