changeset 11250:830b940e7ff4

Turn xget_ancestor into regular API
author Michael Goffioul <michael.goffioul@gmail.com>
date Sun, 14 Nov 2010 21:51:45 +0000
parents 6cd1e62b6616
children 77989197a3c7
files src/ChangeLog src/DLD-FUNCTIONS/fltk_backend.cc src/graphics.cc src/graphics.h.in
diffstat 4 files changed, 31 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sun Nov 14 22:01:20 2010 +0100
+++ b/src/ChangeLog	Sun Nov 14 21:51:45 2010 +0000
@@ -1,3 +1,13 @@
+2010-11-14  Michael Goffioul  <michael.goffioul@gmail.com>
+
+	* graphics.h.in (graphics_object::get_ancestor): New method.
+	* graphics.cc (graphics_object::get_ancestor): Likewise.
+	(convert_text_position, convert_cdata): Use it.
+	(xget_ancestor): Remove obsolete function.
+	* DLD_FUNCTIONS/fltk_backend.cc (plot_window::uimenu_update,
+	fltk_backend::update): Replace xget_ancestor with
+	graphics_objects::get_ancestor.
+
 2010-11-13  John W. Eaton  <jwe@octave.org>
 
 	* graphics.h.in (figure::properties::filename): Make writable.
--- a/src/DLD-FUNCTIONS/fltk_backend.cc	Sun Nov 14 22:01:20 2010 +0100
+++ b/src/DLD-FUNCTIONS/fltk_backend.cc	Sun Nov 14 21:51:45 2010 +0000
@@ -85,9 +85,6 @@
 left double click - autoscale\n\
 ";
 
-graphics_object xget_ancestor (const graphics_object& go_arg,
-                                      const std::string& type);
-
 class OpenGL_fltk : public Fl_Gl_Window
 {
 public:
@@ -790,7 +787,7 @@
         uimenu::properties& uimenup =
           dynamic_cast<uimenu::properties&> (uimenu_obj.get_properties ());
         std::string fltk_label = uimenup.get_fltk_label();
-        graphics_object fig = xget_ancestor(uimenu_obj,"figure");
+        graphics_object fig = uimenu_obj.get_ancestor("figure");
         figure::properties& figp =
           dynamic_cast<figure::properties&> (fig.get_properties ());
         
@@ -1825,7 +1822,7 @@
         if (id == uimenu::properties::ID_LABEL)
           uimenu_set_fltk_label (go);
         
-        graphics_object fig = xget_ancestor(go,"figure");
+        graphics_object fig = go.get_ancestor("figure");
         figure_manager::uimenu_update(fig.get_handle (), go.get_handle (), id);
       }
   }
--- a/src/graphics.cc	Sun Nov 14 22:01:20 2010 +0100
+++ b/src/graphics.cc	Sun Nov 14 21:51:45 2010 +0000
@@ -55,8 +55,6 @@
 
 // forward declarations
 static octave_value xget (const graphics_handle& h, const caseless_str& name);
-graphics_object xget_ancestor (const graphics_object& go_arg,
-                                      const std::string& type);
 
 static void
 gripe_set_invalid (const std::string& pname)
@@ -460,7 +458,7 @@
                        const caseless_str& to_units)
 {
   graphics_object go = gh_manager::get_object (props.get___myhandle__ ());
-  graphics_object ax = xget_ancestor (go, "axes");
+  graphics_object ax = go.get_ancestor ("axes");
 
   Matrix retval (1, pos.numel (), 0);
 
@@ -541,26 +539,6 @@
   return convert_position (sz, obj.get ("units").string_value (), "pixels", sz.extract_n (0, 2, 1, 2)).extract_n (0, 2, 1, 2);
 }
 
-graphics_object
-xget_ancestor (const graphics_object& go_arg, const std::string& type)
-{
-  graphics_object go = go_arg;
-
-  do
-    {
-      if (go.valid_object ())
-        {
-          if (go.isa (type))
-            return go;
-          else
-            go = gh_manager::get_object (go.get_parent ());
-        }
-      else
-        return graphics_object ();
-    }
- while (true);
-}
-
 static void
 convert_cdata_2 (bool is_scaled, double clim_0, double clim_1,
                  const double *cmapv, double x, octave_idx_type lda,
@@ -615,7 +593,7 @@
   Matrix clim (1, 2, 0.0);
 
   graphics_object go = gh_manager::get_object (props.get___myhandle__ ());
-  graphics_object fig = xget_ancestor (go, "figure");
+  graphics_object fig = go.get_ancestor ("figure");
 
   if (fig.valid_object ())
     {
@@ -627,7 +605,7 @@
 
   if (is_scaled)
     {
-      graphics_object ax = xget_ancestor (go, "axes");
+      graphics_object ax = go.get_ancestor ("axes");
 
       if (ax.valid_object ())
         {
@@ -2555,6 +2533,20 @@
   return retval;
 }
 
+graphics_object
+graphics_object::get_ancestor (const std::string& type) const
+{
+  if (valid_object ())
+    {
+      if (isa (type))
+        return *this;
+      else
+        return gh_manager::get_object (get_parent ()).get_ancestor (type);
+    }
+  else
+    return graphics_object ();
+}
+
 // ---------------------------------------------------------------------
 
 #include "graphics-props.cc"
--- a/src/graphics.h.in	Sun Nov 14 22:01:20 2010 +0100
+++ b/src/graphics.h.in	Sun Nov 14 21:51:45 2010 +0000
@@ -2496,6 +2496,8 @@
 
   graphics_handle get_handle (void) const { return rep->get_handle (); }
 
+  graphics_object get_ancestor (const std::string& type) const;
+
   void remove_child (const graphics_handle& h) { rep->remove_child (h); }
 
   void adopt (const graphics_handle& h) { rep->adopt (h); }