function dlgstruct = udtGetLeafWidgetBase(type, name, tag, sync, prop)
%udtGetLeafWidgetBase Dynamic Dialog block helper function.
%
%   udtGetLeafWidgetBase(type,name,tag,prop)
%   Returns a MATLAB structure for use with Dynamic Dialogs
%   The structure has several common fields filled out:
%
%    type : Type
%    name : Name
%    tag  : Tag
%    sync : whether or not to set MatlabMethod/MatlabArgs for syncing
%           input the controller source to set
%           input 0 to ignore
%    prop : ObjectProperty (optional)
%
%   Also, the struct has Mode set to 1, and Tunability set to 0
%

% Copyright 2003-2014 The MathWorks, Inc.

narginchk(4,5);

dlgstruct.Type = type;
dlgstruct.Tag = tag;
dlgstruct.Tunable = 0;

% Don't even create a Name field if the string is blank
if ~isempty(name)
    dlgstruct.Name = name;
end

% The mode should be true for all objects except those of type text.
if strcmp(type, 'text')
    dlgstruct.Mode  = false;
else
    dlgstruct.Mode  = true;
end

% The objectProperty (optional)
if nargin >= 5
    dlgstruct.ObjectProperty = prop;
end

% Fill in fields necessary to synchronize the widgets.
if sync ~= 0
    dlgstruct.MatlabMethod = 'udtDDGSync';
    dlgstruct.MatlabArgs = {sync, '%dialog', '%tag'};
    if isequal(type, 'edit') && nargin >= 5
        % ObjectProperty is being set to a more specific property
        % but it doesn't exist as a DialogParam so propertyActions won't
        % find it. Therefore set ActionProperty which propertyActions
        % checks before ObjectProperty
        dlgstruct.ActionProperty = dlgstruct.Tag;
    end
end

