1 ## Copyright (C) 2002-2012 John W. Eaton
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Command} {} close
21 ## @deftypefnx {Command} {} close (@var{n})
22 ## @deftypefnx {Command} {} close all
23 ## @deftypefnx {Command} {} close all hidden
24 ## Close figure window(s) by calling the function specified by the
25 ## @code{"closerequestfcn"} property for each figure. By default, the
26 ## function @code{closereq} is used.
31 ## 2010-05-02 PBig allow empty argument
33 function retval = close (arg1, arg2)
38 ## Close current figure. Don't use gcf because that will open a new
39 ## plot window if one doesn't exist.
40 figs = get (0, "currentfigure");
41 if (! isempty (figs) && figs == 0)
45 if (ischar (arg1) && strcmpi (arg1, "all"))
46 close_all_figures (false);
47 elseif (isfigure (arg1))
49 elseif (isempty(arg1))
52 error ("close: expecting argument to be \"all\" or a figure handle");
55 && ischar (arg1) && strcmpi (arg1, "all")
56 && ischar (arg2) && strcmpi (arg2, "hidden"))
57 close_all_figures (true);
63 __go_execute_callback__ (h, "closerequestfcn");
72 function close_all_figures (close_hidden_figs)
74 while (! isempty (fig = get (0, "currentfigure")))
75 ## handlevisibility = get (fig, "handlevisibility")
76 ## if (close_hidden_figs || ! strcmpi (handlevisibility, "off"))
84 %! hf = figure ("visible", "off");
87 %! objs = findobj ("type", "figure");
88 %! assert (isempty (intersect (objs, hf)));
89 %! unwind_protect_cleanup