# HG changeset patch # User Michael Goffioul # Date 1202485594 -3600 # Node ID adb520646d7e75704edfa5dc974c929c5c260705 # Parent feaaf725c54f26da380e168ef7bfd9f89ff65f52 Fix execution of callback strings and allow execution of callback by name. diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -8,6 +8,14 @@ before executing a callback. (root_figure::properties::set_callbackobject): Implement accessor. + * 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, @@ -1858,6 +1866,14 @@ (get_user_input): Don't process input_buf if there is an error. Call reset_error_handler instead of setting error_state to 0. +2008-02-08 Michael Goffioul + + * graphics.h.in (callback_property::execute): New static + helper method (useful to execute callbacks by name). + * graphics.cc (callback_property::execute): Likewise. + (execute_callback): Avoid undefined argument when executing + callback. Do not use arguments when the callback is a string. + 2008-02-07 John W. Eaton * ov-range.h (octave_range::sort): New functions. diff --git a/src/graphics.cc b/src/graphics.cc --- a/src/graphics.cc +++ b/src/graphics.cc @@ -200,7 +200,10 @@ octave_function *fcn = 0; args(0) = h.as_octave_value (); - args(1) = data; + if (data.is_defined ()) + args(1) = data; + else + args(1) = Matrix (); unwind_protect::begin_frame ("execute_callback"); unwind_protect::add (xreset_gcbo); @@ -213,14 +216,10 @@ fcn = cb.function_value (); else if (cb.is_string ()) { + int status; std::string s = cb.string_value (); - octave_value f = symbol_table::find_function (s); - int status; - - if (f.is_defined ()) - fcn = f.function_value (); - else - eval_string (s, false, status); + + eval_string (s, false, status); } else if (cb.is_cell () && cb.length () > 0 && (cb.rows () == 1 || cb.columns () == 1) @@ -562,6 +561,14 @@ execute_callback (callback, get_parent (), data); } +void +callback_property::execute (const octave_value& cb, const graphics_handle& h, + const octave_value& data) +{ + if (cb.is_defined () && ! cb.is_empty ()) + execute_callback (cb, h, data); +} + // --------------------------------------------------------------------- void diff --git a/src/graphics.h.in b/src/graphics.h.in --- a/src/graphics.h.in +++ b/src/graphics.h.in @@ -985,6 +985,11 @@ OCTINTERP_API void execute (const octave_value& data = octave_value ()) const; + OCTINTERP_API static + void execute (const octave_value& cb, const graphics_handle& h, + const octave_value& data = octave_value ()); + + callback_property& operator = (const octave_value& val) { set (val);