1 ## Copyright (C) 2012 Michael Goffioul
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 {Function File} {} uiwait
21 ## @deftypefnx {Function File} {} uiwait (@var{h})
22 ## @deftypefnx {Function File} {} uiwait (@var{h}, @var{timeout})
23 ## Suspend program execution until the figure with handle @var{h} is
24 ## deleted or @code{uiresume} is called. When no figure handle is specified,
25 ## this function uses the current figure.
27 ## If the figure handle is invalid or there is no current figure, this
28 ## functions returns immediately.
30 ## When specified, @var{timeout} defines the number of seconds to wait
31 ## for the figure deletion or the @code{uiresume} call. The timeout value
32 ## must be at least 1. If a smaller value is specified, a warning is issued
33 ## and a timeout value of 1 is used instead. If a non-integer value is
34 ## specified, it is truncated towards 0. If @var{timeout} is not specified,
35 ## the program execution is suspended indefinitely.
36 ## @seealso{uiresume, waitfor}
41 function uiwait (varargin)
47 h = get (0, "currentfigure");
50 if (! ishandle (h) || ! strcmp (get (h, "type"), "figure"))
51 error ("uiwait: invalid figure handle");
54 timeout = varargin{2};
61 addproperty ("__uiwait_state__", h, "radio", "none|{active}|triggered");
63 if (! strcmp (get (h, "__uiwait_state__"), "none"))
64 error ("uiwait: an active uiwait call for this figure already exists");
66 set (h, "__uiwait_state__", "active");
68 waitfor_args = {h, "__uiwait_state__", "triggered"};
69 if (! isempty (timeout))
70 waitfor_args(end+1:end+2) = {"timeout", timeout};
72 waitfor (waitfor_args{:});
73 unwind_protect_cleanup
74 if (ishandle (h) && isprop (h, "__uiwait_state__"))
75 set (h, "__uiwait_state__", "none");