changeset 8058:ca39c21fa4b8

[mq]: generic_octave_to_backend_nofitication
author John W. Eaton <jwe@octave.org>
date Tue, 26 Aug 2008 13:23:27 -0400
parents 7670cd296687
children 75c99d3f97d7
files src/ChangeLog src/graphics.cc src/graphics.h.in
diffstat 3 files changed, 84 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Aug 26 18:05:35 2008 +0200
+++ b/src/ChangeLog	Tue Aug 26 13:23:27 2008 -0400
@@ -1,3 +1,16 @@
+2008-08-26  Maciek Gajewski <maciej.gajewski0@gmail.com>
+
+	* graphics.h.in (base_property::set): Remove inline implementation.
+	(base_graphics_backend::property_changed,
+	base_graphics_backend::object_created,
+	base_graphics_backend::object_destroyed): New method.
+	(graphics_backend::property_changed, graphics_backend::object_created,
+	graphics_backend::object_destroyed): Likewise.
+	* graphics.cc (base_property::set): Moved from header file.
+	(gh_manager::do_free): Add backend notification.
+	(gh_manager::do_make_graphics_handle): Likewise.
+	(gh_manager::do_make_figure_handle): Likewise.
+
 2008-08-25  Thomas L. Scofield  <scofield@calvin.edu>
 
 	* DLD-FUNCTIONS/__magick_read__.cc: Untabify.
--- a/src/graphics.cc	Tue Aug 26 18:05:35 2008 +0200
+++ b/src/graphics.cc	Tue Aug 26 13:23:27 2008 -0400
@@ -459,6 +459,26 @@
 // ---------------------------------------------------------------------
 
 void
+base_property::set (const octave_value& v, bool do_run )
+{
+  do_set (v);
+
+  // notify backend
+  graphics_object go = gh_manager::get_object (parent);
+  if (go)
+    {
+      graphics_backend backend = go.get_backend();
+      if (backend)
+        backend.property_changed (parent, name);
+    }
+  
+  // run listeners
+  if (do_run && ! error_state)
+    run_listeners (POSTSET);
+}
+
+
+void
 base_property::run_listeners (listener_mode mode)
 {
   const octave_value_list& l = listeners[mode];
@@ -1172,6 +1192,13 @@
 	      p->second.get_properties ().set_beingdeleted (true);
 	      p->second.get_properties ().execute_deletefcn ();
 
+	      // notify backend
+	      graphics_backend backend = p->second.get_backend ();
+	      if (backend)
+                backend.object_destroyed (h);
+                 // note - this will be valid only for first explicitly deleted object.
+                 // All his children will have unknown backend then.
+                 
 	      handle_map.erase (p);
 
 	      if (h.value () < 0)
@@ -3524,6 +3551,11 @@
       handle_map[h] = graphics_object (go);
       if (do_createfcn)
         go->get_properties ().execute_createfcn ();
+
+      // notify backend
+      graphics_backend backend = go->get_backend ();
+      if (backend)
+        backend.object_created (h);
     }
   else
     error ("gh_manager::do_make_graphics_handle: invalid object type `%s'",
@@ -3537,8 +3569,14 @@
 {
   graphics_handle h = val;
 
-  handle_map[h] = graphics_object (new figure (h, 0));
-
+  base_graphics_object* go = new figure (h, 0);
+  handle_map[h] = graphics_object (go);
+
+  // notify backend
+  graphics_backend backend = go->get_backend ();
+  if (backend)
+    backend.object_created (h);
+  
   return h;
 }
 
--- a/src/graphics.h.in	Tue Aug 26 18:05:35 2008 +0200
+++ b/src/graphics.h.in	Tue Aug 26 13:23:27 2008 -0400
@@ -372,14 +372,10 @@
 
   void set_hidden (bool flag) { hidden = flag; }
 
-  void set (const octave_value& v, bool do_run = true)
-    {
-      do_set (v);
-
-      if (do_run && ! error_state)
-	run_listeners (POSTSET);
-    }
-
+  // Sets property value, notifies backend.
+  // If do_run is true, runs associated listeners.
+  void set (const octave_value& v, bool do_run = true);
+  
   virtual octave_value get (void) const
     {
       error ("get: invalid property \"%s\"", name.c_str ());
@@ -1351,6 +1347,18 @@
   virtual void set_figure_position (const graphics_handle&, const Matrix&) const
     { gripe_invalid ("set_figure_position"); }
 
+  // Called when graphics object using this backend changes it's property.
+  virtual void property_changed (const graphics_handle&, const std::string&)
+    { gripe_invalid ("property_changed"); }
+  
+  // Called when new object using this backend is created.
+  virtual void object_created (const graphics_handle&)
+    { gripe_invalid ("object_created"); }
+
+  // Called when object using this backend is destroyed.
+  virtual void object_destroyed (const graphics_handle&)
+    { gripe_invalid ("object_destroyed"); }
+
 private:
   std::string name;
   int count;
@@ -1430,7 +1438,21 @@
 
   void set_figure_position (const graphics_handle& h, const Matrix& pos) const
     { rep->set_figure_position (h, pos); }
-
+  
+  // Notifies backend that object't property has changed.
+  void property_changed (const graphics_handle& h, const std::string& prop)
+    { rep->property_changed (h, prop); }
+
+  // Notifies backend that new object was created.
+  void object_created (const graphics_handle& h)
+    { rep->object_created (h); }
+  
+  // Notifies backend that object was destroyed.
+  // This is called only for explicitly deleted object. Children are
+  // deleted implicitly and backend isn't notified.
+  void object_destroyed (const graphics_handle& h)
+    { rep->object_destroyed (h); }
+  
   OCTINTERP_API static graphics_backend default_backend (void);
 
   static void register_backend (const graphics_backend& b)