changeset 31261:5f7d5934a1a9

gco.m: Extend function to accept a figure handle input (bug #63161) * gco.m: Rename allowable input to "hfig" in documentation. Change function prototype to accept single input "hfig". Add input validation code for optional input hfig. Add BIST test for input validation.
author Rik <rik@octave.org>
date Wed, 05 Oct 2022 11:53:05 -0700
parents c5c8bf50449c
children b8f4ec18e728
files scripts/plot/util/gco.m
diffstat 1 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/util/gco.m	Wed Oct 05 10:35:31 2022 -0400
+++ b/scripts/plot/util/gco.m	Wed Oct 05 11:53:05 2022 -0700
@@ -25,9 +25,9 @@
 
 ## -*- texinfo -*-
 ## @deftypefn  {} {@var{h} =} gco ()
-## @deftypefnx {} {@var{h} =} gco (@var{fig})
+## @deftypefnx {} {@var{h} =} gco (@var{hfig})
 ## Return a handle to the current object of the current figure, or a handle
-## to the current object of the figure with handle @var{fig}.
+## to the current object of the figure with handle @var{hfig}.
 ##
 ## The current object of a figure is the object that was last clicked on.  It
 ## is stored in the @qcode{"CurrentObject"} property of the target figure.
@@ -46,8 +46,20 @@
 ## @seealso{gcbo, gca, gcf, gcbf, get, set}
 ## @end deftypefn
 
-function h = gco ()
+function h = gco (hfig)
 
-  h = get (get (0, "currentfigure"), "currentobject");
+  if (nargin == 1)
+    if (! isfigure (hfig))
+      error ("gco: HFIG must be a graphics handle to a figure object");
+    endif
+  else
+    hfig = get (0, "currentfigure");
+  endif
+
+  h = get (hfig, "currentobject");
 
 endfunction
+
+
+## Test input invalidation
+%!error <HFIG must be a graphics handle> gco (-1)