www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/+mbcgui/+util/showDialog.m

    function showDialog(obj, DefActionControl)
%SHOWDIALOG Show figure as a dialog
%
%  SHOWDIALOG(FIG) turns the figure modal and displays it.  The method then
%  waits until the figure is either destroyed or turned invisible.

%  Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc.


% hHighlight = [];

if isempty(get(obj, 'WindowKeyReleaseFcn'))
    % Add a figure key action to implement Esc capturing
    set(obj, 'WindowKeyReleaseFcn', @i_catchEsc);
end

if nargin>1
    % Set the default button.  This will highlight it and execute it when
    % Enter is pressed.
    hFig = mbcgui.hgclassesutil.toHandle(obj);
    hFig.setDefaultButton(DefActionControl);
else
    DefActionControl = [];
end

% Save the current windowstyle for resetting later.  This will mean
% xregdialog's stay modal continuously, while other more unusual usages
% will get something closer to what they expect.
ws = get(obj, 'WindowStyle');
set(obj, ...
    'WindowStyle', 'modal', ...
    'CloseRequestFcn', @i_close, ...
    'Visible', 'on');

pk = findpackage('xregGui');
TESTMODE = pk.TestMode;
if ~TESTMODE
    uddObj = xregGui.uddDispatcher;
    uddObj.waitfor(obj, 'Visible');
elseif TESTMODE
    callback = pk.ShowDialogCallback;
    drawnow;
    if iscell( callback )
        feval( callback{1}, obj, DefActionControl, callback{2:end} );
    elseif ischar( callback ) || isa( callback, 'function_handle' )
        feval( callback, obj, DefActionControl );
    end
end

set(obj, 'WindowStyle', ws);



function i_close(src, evt)
set(src, 'Visible', 'off');

function i_catchEsc(src, evt)
if get(src, 'CurrentCharacter')==27    % Escape
    close(src);
end