changeset 17485:edd15fceff14

guihandles.m: Overhaul function. * scripts/plot/guihandles.m: Add docstring which was missing. Match function variables to docstring. Put input validation first.
author Rik <rik@octave.org>
date Wed, 25 Sep 2013 10:46:18 -0700
parents 995decfed6cc
children b4343603f7ab
files scripts/plot/guihandles.m
diffstat 1 files changed, 30 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/guihandles.m	Wed Sep 25 10:23:30 2013 -0700
+++ b/scripts/plot/guihandles.m	Wed Sep 25 10:46:18 2013 -0700
@@ -17,37 +17,44 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {@var{hdata} =} guihandles (@var{handle})
+## @deftypefn  {Function File} {@var{hdata} =} guihandles (@var{h})
 ## @deftypefnx {Function File} {@var{hdata} =} guihandles
+## Return a structure of object handles for the figure associated with
+## handle @var{h}.
+## 
+## If no handle is specified the current figure returned by @code{gcf} is used.
 ##
-## @seealso{guidata, getappdata, setappdata}
+## The fieldname for each entry of @var{hdata} is taken from the @qcode{"tag"}
+## property of the graphic object.  If the tag is empty then the handle is not
+## returned.  If there are multiple graphic objects with the same tag then
+## the entry in @var{hdata} will be a vector of handles.  @code{guihandles}
+## includes all possible handles, including those for
+## which @qcode{"HandleVisibility"} is @qcode{"off"}.
+## @seealso{guidata, findobj, findall, allchild}
 ## @end deftypefn
 
 ## Author: goffioul
 
-function hdata = guihandles (varargin)
-
-  hdata = [];
+function hdata = guihandles (h)
 
-  if (nargin == 0 || nargin == 1)
-    if (nargin == 1)
-      h = varargin{1};
-      if (ishandle (h))
-        h = ancestor (h, "figure");
-        if (isempty (h))
-          error ("no ancestor figure found");
-        endif
-      else
-        error ("invalid object handle");
-      endif
-    else
-      h = gcf ();
-    endif
-    hdata = __make_guihandles_struct__ (h, hdata);
-  else
+  if (nargin > 2)
     print_usage ();
   endif
 
+  if (nargin == 1)
+    if (! ishandle (h))
+      error ("guidata: H must be a valid object handle");
+    endif
+    h = ancestor (h, "figure");
+    if (isempty (h))
+      error ("guidata: no ancestor figure of H found");
+    endif
+  else
+    h = gcf ();
+  endif
+
+  hdata = __make_guihandles_struct__ (h, []);
+
 endfunction
 
 function hdata = __make_guihandles_struct__ (h, hdata)
@@ -65,8 +72,8 @@
   endif
 
   kids = allchild (h);
-  for i = 1 : length (kids)
-    hdata = __make_guihandles_struct__ (kids(i), hdata);
+  for hkid = kids'
+    hdata = __make_guihandles_struct__ (hkid, hdata);
   endfor
 
 endfunction