changeset 31662:a36035adefeb

prep for moving gh_manager class to separate file * graphics-utils.h, graphics-utils.cc: New file. (delete_executing, xset, xget, isfigure, reparent, delete_graphics_object, delete_graphics_objects, close_figure, force_close_figure): Move here from graphics.cc. Declare extern but don't set visibility flags to export functions. * graphics.cc: Include graphics-utils.h. * libinterp/corefcn/module.mk: Update.
author John W. Eaton <jwe@octave.org>
date Sat, 10 Dec 2022 00:11:20 -0500
parents 5fb15fb04e09
children a74935a6cc75
files libinterp/corefcn/graphics-utils.cc libinterp/corefcn/graphics-utils.h libinterp/corefcn/graphics.cc libinterp/corefcn/module.mk
diffstat 4 files changed, 258 insertions(+), 144 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libinterp/corefcn/graphics-utils.cc	Sat Dec 10 00:11:20 2022 -0500
@@ -0,0 +1,180 @@
+////////////////////////////////////////////////////////////////////////
+//
+// Copyright (C) 2007-2022 The Octave Project Developers
+//
+// See the file COPYRIGHT.md in the top-level directory of this
+// distribution or <https://octave.org/copyright/>.
+//
+// This file is part of Octave.
+//
+// Octave is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Octave is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Octave; see the file COPYING.  If not, see
+// <https://www.gnu.org/licenses/>.
+//
+////////////////////////////////////////////////////////////////////////
+
+#if defined (HAVE_CONFIG_H)
+#  include "config.h"
+#endif
+
+#include "caseless-str.h"
+
+#include "graphics-utils.h"
+#include "graphics.h"
+#include "input.h"
+#include "interpreter-private.h"
+#include "ov.h"
+
+OCTAVE_BEGIN_NAMESPACE(octave)
+
+// Flag to stop redraws due to callbacks while deletion is in progress.
+bool delete_executing = false;
+
+void
+xset (const graphics_handle& h, const caseless_str& pname,
+      const octave_value& val)
+{
+  gh_manager& gh_mgr = octave::__get_gh_manager__ ();
+
+  graphics_object go = gh_mgr.get_object (h);
+
+  go.set (pname, val);
+}
+
+void
+xset (const graphics_handle& h, const octave_value_list& args)
+{
+  if (args.length () > 0)
+    {
+      gh_manager& gh_mgr = octave::__get_gh_manager__ ();
+
+      graphics_object go = gh_mgr.get_object (h);
+
+      go.set (args);
+    }
+}
+
+octave_value
+xget (const graphics_handle& h, const caseless_str& pname)
+{
+  gh_manager& gh_mgr = octave::__get_gh_manager__ ();
+
+  graphics_object go = gh_mgr.get_object (h);
+
+  return go.get (pname);
+}
+
+bool isfigure (double val)
+{
+  gh_manager& gh_mgr = octave::__get_gh_manager__ ();
+
+  graphics_object go = gh_mgr.get_object (val);
+
+  return go && go.isa ("figure");
+}
+
+graphics_handle
+reparent (const octave_value& ov, const std::string& who,
+          const std::string& pname, const graphics_handle& new_parent,
+          bool adopt)
+{
+  double hv = ov.xdouble_value ("%s: %s must be a graphics handle",
+                                who.c_str (), pname.c_str ());
+
+  gh_manager& gh_mgr = octave::__get_gh_manager__ ();
+
+  graphics_handle h = gh_mgr.lookup (hv);
+
+  if (! h.ok ())
+    error ("%s: invalid graphics handle (= %g) for %s",
+           who.c_str (), hv, pname.c_str ());
+
+  graphics_object go = gh_mgr.get_object (h);
+
+  graphics_handle parent_h = go.get_parent ();
+
+  graphics_object parent_go = gh_mgr.get_object (parent_h);
+
+  parent_go.remove_child (h);
+
+  if (adopt)
+    go.set ("parent", new_parent.value ());
+  else
+    go.reparent (new_parent);
+
+  return h;
+}
+
+void
+delete_graphics_object (const graphics_handle& h, bool from_root)
+{
+  if (h.ok ())
+    {
+      gh_manager& gh_mgr = octave::__get_gh_manager__ ();
+
+      graphics_object go = gh_mgr.get_object (h);
+
+      // Don't do recursive deleting, due to callbacks
+      if (! go.get_properties ().is_beingdeleted ())
+        {
+          // NOTE: Freeing the handle also calls any deletefcn.  It also calls
+          //       the parent's delete_child function.
+
+          gh_mgr.free (h, from_root || go.isa ("figure"));
+
+          Vdrawnow_requested = true;
+        }
+    }
+}
+
+void
+delete_graphics_object (double val, bool from_root)
+{
+  gh_manager& gh_mgr = octave::__get_gh_manager__ ();
+
+  delete_graphics_object (gh_mgr.lookup (val), from_root || isfigure (val));
+}
+
+void
+delete_graphics_objects (const NDArray vals, bool from_root)
+{
+  // Prevent redraw of partially deleted objects.
+  octave::unwind_protect_var<bool> restore_var (delete_executing, true);
+
+  for (octave_idx_type i = 0; i < vals.numel (); i++)
+    delete_graphics_object (vals.elem (i), from_root);
+}
+
+void
+close_figure (const graphics_handle& h)
+{
+  octave_value closerequestfcn = xget (h, "closerequestfcn");
+
+  gh_manager& gh_mgr = octave::__get_gh_manager__ ();
+
+  gh_mgr.execute_callback (h, closerequestfcn);
+}
+
+void
+force_close_figure (const graphics_handle& h)
+{
+  // Remove the deletefcn and closerequestfcn callbacks
+  // and delete the object directly.
+
+  xset (h, "deletefcn", Matrix ());
+  xset (h, "closerequestfcn", Matrix ());
+
+  delete_graphics_object (h, true);
+}
+
+OCTAVE_END_NAMESPACE(octave)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libinterp/corefcn/graphics-utils.h	Sat Dec 10 00:11:20 2022 -0500
@@ -0,0 +1,75 @@
+////////////////////////////////////////////////////////////////////////
+//
+// Copyright (C) 2007-2022 The Octave Project Developers
+//
+// See the file COPYRIGHT.md in the top-level directory of this
+// distribution or <https://octave.org/copyright/>.
+//
+// This file is part of Octave.
+//
+// Octave is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Octave is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Octave; see the file COPYING.  If not, see
+// <https://www.gnu.org/licenses/>.
+//
+////////////////////////////////////////////////////////////////////////
+
+#if ! defined (octave_graphics_utils_h)
+#define octave_graphics_utils_h 1
+
+// The functions defined here are private and should not be exported.
+// This header file should not be installed.
+
+#include "octave-config.h"
+
+#include <string>
+
+#include "graphics-handle.h"
+
+class caseless_str;
+class octave_value;
+class NDArray;
+
+OCTAVE_BEGIN_NAMESPACE(octave)
+
+// Flag to stop redraws due to callbacks while deletion is in progress.
+extern bool delete_executing;
+
+extern void xset (const graphics_handle& h, const caseless_str& pname,
+                  const octave_value& val);
+
+extern void xset (const graphics_handle& h, const octave_value_list& args);
+
+extern octave_value xget (const graphics_handle& h, const caseless_str& pname);
+
+extern bool isfigure (double val);
+
+extern graphics_handle
+reparent (const octave_value& ov, const std::string& who,
+          const std::string& pname, const graphics_handle& new_parent,
+          bool adopt = true);
+
+extern void
+delete_graphics_object (const graphics_handle& h, bool from_root = false);
+
+extern void delete_graphics_object (double val, bool from_root = false);
+
+extern void
+delete_graphics_objects (const NDArray vals, bool from_root = false);
+
+extern void close_figure (const graphics_handle& h);
+
+extern void force_close_figure (const graphics_handle& h);
+
+OCTAVE_END_NAMESPACE(octave)
+
+#endif
--- a/libinterp/corefcn/graphics.cc	Sat Dec 10 09:14:55 2022 -0500
+++ b/libinterp/corefcn/graphics.cc	Sat Dec 10 00:11:20 2022 -0500
@@ -51,6 +51,7 @@
 #include "defun.h"
 #include "display.h"
 #include "error.h"
+#include "graphics-utils.h"
 #include "graphics.h"
 #include "input.h"
 #include "interpreter-private.h"
@@ -69,9 +70,6 @@
 
 OCTAVE_BEGIN_NAMESPACE(octave)
 
-// forward declarations
-static octave_value xget (const graphics_handle& h, const caseless_str& name);
-
 OCTAVE_NORETURN static
 void
 err_set_invalid (const std::string& pname)
@@ -2867,16 +2865,6 @@
   return retval;
 }
 
-static bool
-isfigure (double val)
-{
-  gh_manager& gh_mgr = octave::__get_gh_manager__ ();
-
-  graphics_object go = gh_mgr.get_object (val);
-
-  return go && go.isa ("figure");
-}
-
 void
 gh_manager::free (const graphics_handle& h, bool from_root)
 {
@@ -2969,72 +2957,6 @@
     }
 }
 
-static void
-xset (const graphics_handle& h, const caseless_str& pname,
-      const octave_value& val)
-{
-  gh_manager& gh_mgr = octave::__get_gh_manager__ ();
-
-  graphics_object go = gh_mgr.get_object (h);
-
-  go.set (pname, val);
-}
-
-static void
-xset (const graphics_handle& h, const octave_value_list& args)
-{
-  if (args.length () > 0)
-    {
-      gh_manager& gh_mgr = octave::__get_gh_manager__ ();
-
-      graphics_object go = gh_mgr.get_object (h);
-
-      go.set (args);
-    }
-}
-
-static octave_value
-xget (const graphics_handle& h, const caseless_str& pname)
-{
-  gh_manager& gh_mgr = octave::__get_gh_manager__ ();
-
-  graphics_object go = gh_mgr.get_object (h);
-
-  return go.get (pname);
-}
-
-static graphics_handle
-reparent (const octave_value& ov, const std::string& who,
-          const std::string& pname, const graphics_handle& new_parent,
-          bool adopt = true)
-{
-  double hv = ov.xdouble_value ("%s: %s must be a graphics handle",
-                                who.c_str (), pname.c_str ());
-
-  gh_manager& gh_mgr = octave::__get_gh_manager__ ();
-
-  graphics_handle h = gh_mgr.lookup (hv);
-
-  if (! h.ok ())
-    error ("%s: invalid graphics handle (= %g) for %s",
-           who.c_str (), hv, pname.c_str ());
-
-  graphics_object go = gh_mgr.get_object (h);
-
-  graphics_handle parent_h = go.get_parent ();
-
-  graphics_object parent_go = gh_mgr.get_object (parent_h);
-
-  parent_go.remove_child (h);
-
-  if (adopt)
-    go.set ("parent", new_parent.value ());
-  else
-    go.reparent (new_parent);
-
-  return h;
-}
-
 // This function is NOT equivalent to the scripting language function gcf.
 graphics_handle
 gcf (void)
@@ -3055,71 +2977,6 @@
          : val.double_value ();
 }
 
-static void
-delete_graphics_object (const graphics_handle& h, bool from_root = false)
-{
-  if (h.ok ())
-    {
-      gh_manager& gh_mgr = octave::__get_gh_manager__ ();
-
-      graphics_object go = gh_mgr.get_object (h);
-
-      // Don't do recursive deleting, due to callbacks
-      if (! go.get_properties ().is_beingdeleted ())
-        {
-          // NOTE: Freeing the handle also calls any deletefcn.  It also calls
-          //       the parent's delete_child function.
-
-          gh_mgr.free (h, from_root || go.isa ("figure"));
-
-          Vdrawnow_requested = true;
-        }
-    }
-}
-
-static void
-delete_graphics_object (double val, bool from_root = false)
-{
-  gh_manager& gh_mgr = octave::__get_gh_manager__ ();
-
-  delete_graphics_object (gh_mgr.lookup (val), from_root || isfigure (val));
-}
-
-// Flag to stop redraws due to callbacks while deletion is in progress.
-static bool delete_executing = false;
-
-static void
-delete_graphics_objects (const NDArray vals, bool from_root = false)
-{
-  // Prevent redraw of partially deleted objects.
-  octave::unwind_protect_var<bool> restore_var (delete_executing, true);
-
-  for (octave_idx_type i = 0; i < vals.numel (); i++)
-    delete_graphics_object (vals.elem (i), from_root);
-}
-
-static void
-close_figure (const graphics_handle& h)
-{
-  octave_value closerequestfcn = xget (h, "closerequestfcn");
-
-  gh_manager& gh_mgr = octave::__get_gh_manager__ ();
-
-  gh_mgr.execute_callback (h, closerequestfcn);
-}
-
-static void
-force_close_figure (const graphics_handle& h)
-{
-  // Remove the deletefcn and closerequestfcn callbacks
-  // and delete the object directly.
-
-  xset (h, "deletefcn", Matrix ());
-  xset (h, "closerequestfcn", Matrix ());
-
-  delete_graphics_object (h, true);
-}
-
 void
 gh_manager::close_all_figures (void)
 {
--- a/libinterp/corefcn/module.mk	Sat Dec 10 09:14:55 2022 -0500
+++ b/libinterp/corefcn/module.mk	Sat Dec 10 00:11:20 2022 -0500
@@ -102,6 +102,7 @@
   %reldir%/gzfstream.h
 
 NOINSTALL_COREFCN_INC = \
+  %reldir%/graphics-utils.h \
   %reldir%/interpreter-private.h \
   %reldir%/mex-private.h \
   %reldir%/oct-hdf5.h \
@@ -180,6 +181,7 @@
   %reldir%/gl-render.cc \
   %reldir%/gl2ps-print.cc \
   %reldir%/graphics-toolkit.cc \
+  %reldir%/graphics-utils.cc \
   %reldir%/graphics.cc \
   %reldir%/gsvd.cc \
   %reldir%/gtk-manager.cc \