4225
|
1 ## Copyright (C) 2002 John W. Eaton |
|
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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
4225
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Command} {} close |
6257
|
22 ## @deftypefnx {Command} {} close (@var{n}) |
4225
|
23 ## @deftypefnx {Command} {} close all |
6257
|
24 ## @deftypefnx {Command} {} close all hidden |
6895
|
25 ## Close figure window(s) by calling the function specified by the |
|
26 ## @code{"closerequestfcn"} property for each figure. By default, the |
|
27 ## function @code{closereq} is used. |
|
28 ## @seealso{closereq} |
4225
|
29 ## @end deftypefn |
|
30 |
|
31 ## Author: jwe |
|
32 |
4226
|
33 ## PKG_ADD: mark_as_command close |
4225
|
34 |
|
35 function retval = close (arg1, arg2) |
|
36 |
6405
|
37 figs = []; |
|
38 |
4225
|
39 if (nargin == 0) |
6278
|
40 ## Close current figure. Don't use gcf because that will open a new |
|
41 ## plot window if one doesn't exist. |
|
42 figs = get (0, "currentfigure"); |
|
43 if (! isempty (figs) && figs == 0) |
|
44 figs = []; |
|
45 endif |
4225
|
46 elseif (nargin == 1) |
6257
|
47 if (ischar (arg1) && strcmp (arg1, "all")) |
6405
|
48 close_all_figures (false); |
6257
|
49 elseif (isfigure (arg1)) |
|
50 figs = arg1; |
4225
|
51 else |
6257
|
52 error ("close: expecting argument to be \"all\" or a figure handle"); |
4225
|
53 endif |
|
54 elseif (nargin == 2 |
5443
|
55 && ischar (arg1) && strcmp (arg1, "all") |
|
56 && ischar (arg2) && strcmp (arg2, "hidden")) |
6405
|
57 close_all_figures (true); |
4225
|
58 else |
6046
|
59 print_usage (); |
4225
|
60 endif |
|
61 |
6257
|
62 for h = figs |
|
63 set (0, "currentfigure", h); |
|
64 feval (get (h, "closerequestfcn")); |
|
65 endfor |
|
66 |
4225
|
67 if (nargout > 0) |
|
68 retval = 1; |
|
69 endif |
|
70 |
|
71 endfunction |
6405
|
72 |
|
73 function close_all_figures (close_hidden_figs) |
|
74 |
|
75 while (! isempty (fig = get (0, "currentfigure"))) |
|
76 ## handlevisibility = get (fig, "handlevisibility") |
|
77 ## if (close_hidden_figs || ! strcmp (handlevisibility, "off")) |
|
78 close (fig); |
|
79 ## endif |
|
80 endwhile |
|
81 |
|
82 endfunction |