function privatesldialogbox(dialog, message, title, varargin)
%PRIVATESLDIALOGBOX Generates dialog box message for SL dialog masks.
%
%    PRIVATESLDIALOGBOX(DIALOG, MESSAGE, TITLE) Generates
%    the error dialog box with the required message, MESSAGE, 
%    and title, TITLE. 
% 
%    PRIVATESLDIALOGBOX(DIALOG, MESSAGE, TITLE, TAG) Generates
%    the error dialog box with the required message, MESSAGE, 
%    and title, TITLE. It also reverts the previous value to the block
%    widget, TAG, before enabling the dialog mask.
%    
%    SS 03-03-07
%    Copyright 2007 The MathWorks, Inc.
%    $Revision: 1.1.6.1 $  $Date: 2010/03/04 16:32:29 $


% Disable the mask dialog.
dialog.setEnabled('ParameterPane', false);

% Create the error dlg. 
h = errordlg(message, title, 'modal');
% Check if handle is valid and call uiwait. 
if ishandle(h)
    % Call uiwait if figure handle is valid.
    uiwait(h);
end

% Check if widget tag is passed as well. 
if (nargin==4)
    % Dialog source object. 
    obj = dialog.getDialogSource;
    
    % Revert the block value to the source value. 
    obj.Block.(varargin{1}) = obj.(varargin{1});
end

% Disable and enable of mask dialogs is required as since 7a, MATLAB error
% dialogs are not modal within Simulink. This being the case, a user can
% enter into weird states with the block dialogs.

% Enable the mask dialog. 
dialog.setEnabled('ParameterPane', true);
