function varargout=setwatch(varargin)
%SETWATCH Set the figure pointer correctly
%   setwatch sets the figure pointer appropriately on all Guide tools 
%   and Guide controlled figures.

%   Loren Dean 
%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 1.21 $ $Date: 1997/11/21 23:49:27 $

switch varargin{1},
  %%%%%%%%%%%%%%%%%%%
  %%%%% WatchOn %%%%%
  %%%%%%%%%%%%%%%%%%%
  case 'on',
    Data=varargin{2};  
    WatchFlag=0;
    if ~isempty(Data),      
      if ~Data.All.WatchFlag,  
        Data.All.WatchFlag=1;WatchFlag=1;
        if nargin~=3, % A check for ctlpanel object type selection
          Data.All.Figs.Handles(~ishandle(Data.All.Figs.Handles))=[];
          set(Data.All.Figs.Handles,'Pointer','watch');
        end          

        if Data.All.GuideFlag,
          if ~isempty(Data.All.ControlInfo.Figures.Handle),  
            Loc=ishandle(Data.All.ControlInfo.Figures.Handle);      
           
            if strcmp(Data.ToolFig.NewObjectType,'pointer'),
              set(Data.All.ControlInfo.Figures.Handle(Loc), ...
                  'Pointer','watch');
            else,            
              setptr(Data.All.ControlInfo.Figures.Handle(Loc),'add');
            end % if strcmp
          end            
          
        end % if Data.All

      else,        
        Stack=dbstack;NumCalls=size(Stack,1);
        if NumCalls==2|NumCalls==4,WatchFlag=1;end        
        
      end  % if Data.All...  
          
    end % if ~isempty
    
    varargout{1}=Data;  
    varargout{2}=WatchFlag;
    
  %%%%%%%%%%%%%%%%%%%%
  %%%%% WatchOff %%%%%
  %%%%%%%%%%%%%%%%%%%%
  case 'off',
    WatchFlag=varargin{2};
    Data=varargin{3};
     
    if WatchFlag,    
      if ~isempty(Data),
        Data.All.WatchFlag=0;      
        Data.All.Figs.Handles= ...
          Data.All.Figs.Handles(ishandle(Data.All.Figs.Handles));
        set(Data.All.Figs.Handles,'Pointer','arrow'); 

        if Data.All.GuideFlag,        
          if ~isempty(Data.All.ControlInfo.Figures.Handle),          
            Loc=ishandle(Data.All.ControlInfo.Figures.Handle); 
           
            if strcmp(Data.ToolFig.NewObjectType,'pointer'),
              set(Data.All.ControlInfo.Figures.Handle(Loc), ...
                  'Pointer','arrow');

            else,            
              setptr(Data.All.ControlInfo.Figures.Handle(Loc),'add');
            end % if strcmp
          end % if ~isempty
        end % if Data
      
      end % if ~isempty
    
    end % if WatchFlag      
    varargout{1}=Data;    

end % switch




