function theResult = doevent(self, theEvent, theMessage, varargin)

% pst/doevent -- Call "pst" event handler.
%  doevent(self, theEvent, theMessage) calls the appropriate
%   event handler on behalf of self, a "pst" object.
 
% svn $Id$
%=======================================================================
% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO.
%  All Rights Reserved.
%   Disclosure without explicit written consent from the
%    copyright owner does not constitute publication.
%=======================================================================
 
% Version of 05-Nov-1999 19:28:46.
% Updated    05-Nov-1999 19:34:37.

if nargout > 0, theResult = []; end
if nargin < 1, help(mfilename), return, end
if nargin < 2, theEvent = '(none)'; end
if nargin < 3, theMessage = []; end

result = [];

switch get(gcbo, 'Type')
case 'uimenu*'
	result = domenu(self, theEvent, theMessage);
case 'uicontrol*'
	result = docontrol(self, theEvent, theMessage);
otherwise
	theHandler = handler(self, theEvent);
	if ~isempty(theHandler)
		result = builtin('feval', theHandler, self, theEvent, theMessage);
	else
		if isempty(theEvent), theEvent = '(none)'; end
		theType = get(gcbo, 'Type');
		disp([' ## ' datestr(now, 13) ' ' theEvent ' ' theType ' ' num2str(gcbo)])
	end
end

if isa(result, 'pst')
	self = result;
end

if nargout > 0
	theResult = self;
end
