diff src/graphics.h.in @ 8299:be9b14945774

Add code to remove listeners from properties and use it with newplot
author David Bateman <dbateman@free.fr>
date Fri, 31 Oct 2008 12:30:20 +0100
parents 53f35799b235
children 4b9bce36109b
line wrap: on
line diff
--- a/src/graphics.h.in	Fri Oct 31 12:09:16 2008 +0100
+++ b/src/graphics.h.in	Fri Oct 31 12:30:20 2008 +0100
@@ -398,6 +398,37 @@
       l.resize (l.length () + 1, v);
     }
 
+  void delete_listener (const octave_value& v = octave_value (), 
+			listener_mode mode = POSTSET)
+    {
+      octave_value_list& l = listeners[mode];
+
+      if (v.is_defined ())
+	{
+	  bool found = false;
+	  int i;
+
+	  for (i = 0; i < l.length (); i++)
+	    {
+	      if (v.internal_rep () == l(i).internal_rep ())
+		{
+		  found = true;
+		  break;
+		}
+	    }
+	  if (found)
+	    {
+	      for (int j = i; j < l.length() - 1; j++)
+		l(j) = l (j + 1);
+
+	      l.resize (l.length () - 1);
+	    }
+	}
+      else
+	l.resize (0);
+
+    }
+
   OCTINTERP_API void run_listeners (listener_mode mode = POSTSET);
 
   virtual base_property* clone (void) const
@@ -1287,6 +1318,10 @@
   void add_listener (const octave_value& v, listener_mode mode = POSTSET)
     { rep->add_listener (v, mode); }
 
+  void delete_listener (const octave_value& v = octave_value (), 
+			listener_mode mode = POSTSET)
+  { rep->delete_listener (v, mode); }
+
   void run_listeners (listener_mode mode = POSTSET)
     { rep->run_listeners (mode); }
 
@@ -1632,6 +1667,9 @@
   virtual void add_listener (const caseless_str&, const octave_value&,
 			     listener_mode = POSTSET);
 
+  virtual void delete_listener (const caseless_str&, const octave_value&,
+				listener_mode = POSTSET);
+
   void set_tag (const octave_value& val) { tag = val; }
 
   void set_parent (const octave_value& val);
@@ -1927,6 +1965,16 @@
 	get_properties ().add_listener (nm, v, mode);
     }
 
+  virtual void delete_property_listener (const std::string& nm,
+					 const octave_value& v,
+					 listener_mode mode = POSTSET)
+    {
+      if (valid_object ())
+	get_properties ().delete_listener (nm, v, mode);
+    }
+
+  virtual void remove_all_listeners (void);
+
 protected:
   // A reference count.
   int count;
@@ -2087,6 +2135,10 @@
 			      listener_mode mode = POSTSET)
     { rep->add_property_listener (nm, v, mode); }
 
+  void delete_property_listener (const std::string& nm, const octave_value& v,
+				 listener_mode mode = POSTSET)
+    { rep->delete_property_listener (nm, v, mode); }
+
 private:
   base_graphics_object *rep;
 };
@@ -2773,6 +2825,7 @@
 
   void set_defaults (const std::string& mode)
   {
+    remove_all_listeners ();
     xproperties.set_defaults (*this, mode);
   }