function out1 = dguiwait(option,in2,in3,in4,in5)
%DGUIWAIT Waiting function for demos.

%   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
%   Last Revision: 27-Jun-1999.
%   Copyright 1995-2000 The MathWorks, Inc.
% $Revision: 1.8 $

if strcmp(option,'pause')
    % in2 = figNumber
    % in3 = wait_mode
    % in4 = win_msg (optional)
    % in5 = msg     (optional)
    %--------------------------
    out1 = 0;
    if nargin==5
        dynvtool('hide',in4);
        msg =in5;
        hdlTxt = wwaiting('handle',in4);
        oldBkCol = get(hdlTxt,'Backgroundcolor');
        set(hdlTxt,'Backgroundcolor','w');
        nblin = size(msg,1);
        for k = 1:nblin
            hdlTxt = wwaiting('msg',in4,deblank(msg(k,:)));
            if in3>0
               out1 = wshowdrv('pause',in2,in3); 
            else
                mousefrm(0,'watch');            
                out1 = 0; pause(3.5);
                mousefrm(0,'arrow');            
            end
            if out1 , break; end
        end
        hdlTxt = wwaiting('off',in4);
        set(hdlTxt,'Backgroundcolor',oldBkCol);
        dynvtool('show',in4);
    else
        if in3>0
            out1 = wshowdrv('pause',in2,in3); 
        else
            mousefrm(0,'watch');            
            out1 = 0; pause(3.5);
            mousefrm(0,'arrow');            
        end
    end
end
