Mercurial > hg > octave-lyh
changeset 7822:edbaa13397ee
Implement callbackobject property in root object.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Thu, 07 Feb 2008 23:00:51 +0100 |
parents | f79dcba526a8 |
children | feaaf725c54f |
files | src/ChangeLog src/graphics.cc src/graphics.h.in |
diffstat | 3 files changed, 67 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,13 @@ 2008-06-04 Michael Goffioul <michael.goffioul@gmail.com> + * graphics.h.in (root_figure::properties::callbackobject): + New root property. + (root_figure::properties::cbo_stack): New field. + * graphics.cc (xset_gcbo, xreset_gcbo): New utility functions. + (execute_callback): Set callbackobject property in root object + before executing a callback. + (root_figure::properties::set_callbackobject): Implement accessor. + * graphics.h.in (class root_figure::properties, class line::properties, class text::properties, class image::properties, class patch::properties,
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -172,6 +172,22 @@ return m; } +static void +xset_gcbo (const graphics_handle& h) +{ + graphics_object go = gh_manager::get_object (0); + root_figure::properties& props = + dynamic_cast<root_figure::properties&> (go.get_properties ()); + + props.set_callbackobject (h.as_octave_value ()); +} + +static void +xreset_gcbo (void *) +{ + xset_gcbo (graphics_handle ()); +} + // NOTE: "cb" is passed by value, because "function_value" method // is non-const; passing "cb" by const-reference is not // possible @@ -186,6 +202,11 @@ args(0) = h.as_octave_value (); args(1) = data; + unwind_protect::begin_frame ("execute_callback"); + unwind_protect::add (xreset_gcbo); + + xset_gcbo (h); + BEGIN_INTERRUPT_WITH_EXCEPTIONS; if (cb.is_function_handle ()) @@ -199,10 +220,7 @@ if (f.is_defined ()) fcn = f.function_value (); else - { - eval_string (s, false, status); - return; - } + eval_string (s, false, status); } else if (cb.is_cell () && cb.length () > 0 && (cb.rows () == 1 || cb.columns () == 1) @@ -224,10 +242,12 @@ nm.c_str ()); } - if (! error_state) + if (fcn && ! error_state) feval (fcn, args); END_INTERRUPT_WITH_EXCEPTIONS; + + unwind_protect::run_frame ("execute_callback"); } static Matrix @@ -1379,6 +1399,36 @@ gripe_set_invalid ("currentfigure"); } +void +root_figure::properties::set_callbackobject (const octave_value& v) +{ + graphics_handle val (v); + + if (error_state) + return; + + if (xisnan (val.value ())) + { + if (! cbo_stack.empty ()) + { + val = cbo_stack.front (); + + cbo_stack.pop_front (); + } + + callbackobject = val; + } + else if (is_handle (val)) + { + if (get_callbackobject ().ok ()) + cbo_stack.push_front (get_callbackobject ()); + + callbackobject = val; + } + else + gripe_set_invalid ("callbackobject"); +} + property_list root_figure::factory_properties = root_figure::init_factory_properties ();