Mercurial > hg > octave-lojdl
changeset 12506:0dda50ae4997
add a persistent mode for listeners
author | Konstantinos Poulios <logari81@gmail.com> |
---|---|
date | Thu, 10 Mar 2011 20:27:15 +0100 |
parents | 6a1fe83fe129 |
children | 41d183070c04 |
files | src/ChangeLog src/graphics.cc src/graphics.h.in |
diffstat | 3 files changed, 48 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2011-03-10 Konstantinos Poulios <logari81@googlemail.com> + + * graphics.h.in: Add PERSISTENT mode to listener_mode. + (base_property::delete_listener): Take into account persistent + mode of a listener. + * graphics.cc (addlistener, dellistener): Accept a new optional + argument for persistent listeners. + 2011-03-07 Konstantinos Poulios <logari81@googlemail.com> Bug #32482.
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -7768,7 +7768,7 @@ octave_value retval; - if (args.length () == 3) + if (args.length () >= 3 && args.length () <= 4) { double h = args(0).double_value (); @@ -7785,6 +7785,13 @@ graphics_object go = gh_manager::get_object (gh); go.add_property_listener (pname, args(2), POSTSET); + + if (args.length () == 4) + { + caseless_str persistent = args(3).string_value (); + if (persistent.compare ("persistent")) + go.add_property_listener (pname, args(2), PERSISTENT); + } } else error ("addlistener: invalid graphics object (= %g)", @@ -7852,7 +7859,16 @@ if (args.length () == 2) go.delete_property_listener (pname, octave_value (), POSTSET); else - go.delete_property_listener (pname, args(2), POSTSET); + { + caseless_str persistent = args(2).string_value (); + if (persistent.compare ("persistent")) + { + go.delete_property_listener (pname, octave_value (), PERSISTENT); + go.delete_property_listener (pname, octave_value (), POSTSET); + } + else + go.delete_property_listener (pname, args(2), POSTSET); + } } else error ("dellistener: invalid graphics object (= %g)",
--- a/src/graphics.h.in +++ b/src/graphics.h.in @@ -318,7 +318,7 @@ class property; -enum listener_mode { POSTSET }; +enum listener_mode { POSTSET, PERSISTENT }; class base_property { @@ -423,7 +423,27 @@ } } else - l.resize (0); + { + if (mode == PERSISTENT) + l.resize (0); + else + { + octave_value_list lnew (0); + octave_value_list& lp = listeners[PERSISTENT]; + for (int i = l.length () - 1; i >= 0 ; i--) + { + for (int j = 0; j < lp.length (); j++) + { + if (l(i).internal_rep () == lp(j).internal_rep ()) + { + lnew.resize (lnew.length () + 1, l(i)); + break; + } + } + } + l = lnew; + } + } }