7017
|
1 ## Copyright (C) 2002, 2005, 2006, 2007 John W. Eaton |
4225
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
4225
|
9 ## |
|
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. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
4225
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Command} {} close |
6257
|
21 ## @deftypefnx {Command} {} close (@var{n}) |
4225
|
22 ## @deftypefnx {Command} {} close all |
6257
|
23 ## @deftypefnx {Command} {} close all hidden |
6895
|
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. |
|
27 ## @seealso{closereq} |
4225
|
28 ## @end deftypefn |
|
29 |
|
30 ## Author: jwe |
|
31 |
4226
|
32 ## PKG_ADD: mark_as_command close |
4225
|
33 |
|
34 function retval = close (arg1, arg2) |
|
35 |
6405
|
36 figs = []; |
|
37 |
4225
|
38 if (nargin == 0) |
6278
|
39 ## Close current figure. Don't use gcf because that will open a new |
|
40 ## plot window if one doesn't exist. |
|
41 figs = get (0, "currentfigure"); |
|
42 if (! isempty (figs) && figs == 0) |
|
43 figs = []; |
|
44 endif |
4225
|
45 elseif (nargin == 1) |
6257
|
46 if (ischar (arg1) && strcmp (arg1, "all")) |
6405
|
47 close_all_figures (false); |
6257
|
48 elseif (isfigure (arg1)) |
|
49 figs = arg1; |
4225
|
50 else |
6257
|
51 error ("close: expecting argument to be \"all\" or a figure handle"); |
4225
|
52 endif |
|
53 elseif (nargin == 2 |
5443
|
54 && ischar (arg1) && strcmp (arg1, "all") |
|
55 && ischar (arg2) && strcmp (arg2, "hidden")) |
6405
|
56 close_all_figures (true); |
4225
|
57 else |
6046
|
58 print_usage (); |
4225
|
59 endif |
|
60 |
6257
|
61 for h = figs |
|
62 set (0, "currentfigure", h); |
|
63 feval (get (h, "closerequestfcn")); |
|
64 endfor |
|
65 |
4225
|
66 if (nargout > 0) |
|
67 retval = 1; |
|
68 endif |
|
69 |
|
70 endfunction |
6405
|
71 |
|
72 function close_all_figures (close_hidden_figs) |
|
73 |
|
74 while (! isempty (fig = get (0, "currentfigure"))) |
|
75 ## handlevisibility = get (fig, "handlevisibility") |
|
76 ## if (close_hidden_figs || ! strcmp (handlevisibility, "off")) |
|
77 close (fig); |
|
78 ## endif |
|
79 endwhile |
|
80 |
|
81 endfunction |