1 function Answer=My_inputdlg(Prompt, Title, NumLines, DefAns)
\r
2 %INPUTDLG Input dialog box.
\r
3 % Answer = inputdlg(Prompt) creates a modal dialog box that returns
\r
4 % user input for multiple prompts in the cell array Answer. Prompt
\r
5 % is a cell array containing the Prompt strings.
\r
7 % Answer = inputdlg(Prompt,Title) specifies the Title for the dialog.
\r
9 % Answer = inputdlg(Prompt,Title,LineNo) specifies the number of lines
\r
10 % for each answer in LineNo. LineNo may be a constant value or a
\r
11 % vector having one element per Prompt.
\r
13 % Answer = inputdlg(Prompt,Title,LineNo,DefAns) specifies the default
\r
14 % answer to display for each Prompt. DefAns must contain the same
\r
15 % number of elements as Prompt and must be a cell array.
\r
17 % prompt={'Enter the matrix size:','Enter the colormap name:'};
\r
19 % title='Input for Peaks function';
\r
21 % answer=inputdlg(prompt,title,lineNo,def);
\r
23 % See also TEXTWRAP.
\r
25 % Loren Dean May 24, 1995.
\r
26 % Copyright (c) 1984-97 by The MathWorks, Inc.
\r
29 %%%%%%%%%%%%%%%%%%%%%
\r
30 %%% General Info. %%%
\r
31 %%%%%%%%%%%%%%%%%%%%%
\r
32 Black =[0 0 0 ]/255;
\r
33 LightGray =[192 192 192 ]/255;
\r
34 LightGray2 =[160 160 164 ]/255;
\r
35 MediumGray =[128 128 128 ]/255;
\r
36 White =[255 255 255 ]/255;
\r
38 %%%%%%%%%%%%%%%%%%%%
\r
39 %%% Nargin Check %%%
\r
40 %%%%%%%%%%%%%%%%%%%%
\r
41 if nargout~=1,error('Wrong number of output arguents for INPUTDLG');end
\r
42 if nargin<1,error('Too few arguments for INPUTDLG');end
\r
44 if nargin==1,Title=' ';end
\r
45 if nargin<=2, NumLines=1;end
\r
51 NumQuest=prod(size(Prompt));
\r
54 DefAns=cell(NumQuest,1);
\r
55 for lp=1:NumQuest, DefAns{lp}=''; end
\r
57 if nargin>4,error('Too many input arguments');end
\r
59 % Backwards Compatibility
\r
61 warning(['Please see the INPUTDLG help for correct input syntax.' 10 ...
\r
62 ' OKCallback no longer supported.' ]);
\r
66 if length(NumLines)~=NumQuest,NumLines=ones(NumQuest,1)*NumLines(1);end
\r
69 error('Default Answer must be a cell array in INPUTDLG.');
\r
72 %%%%%%%%%%%%%%%%%%%%%%%
\r
73 %%% Create InputFig %%%
\r
74 %%%%%%%%%%%%%%%%%%%%%%%
\r
75 FigWidth=300;FigHeight=100;
\r
76 FigPos(3:4)=[FigWidth FigHeight];
\r
77 FigColor=get(0,'Defaultuicontrolbackgroundcolor');
\r
78 InputFig=dialog( ...
\r
79 'Visible' ,'off' , ...
\r
81 'Pointer' ,'arrow' , ...
\r
82 'Units' ,'points', ...
\r
83 'UserData' ,'' , ...
\r
85 'HandleVisibility','on' , ...
\r
86 'Color' ,FigColor, ...
\r
87 'NextPlot' ,'add' ...
\r
91 %%%%%%%%%%%%%%%%%%%%%
\r
92 %%% Set Positions %%%
\r
93 %%%%%%%%%%%%%%%%%%%%%
\r
99 BtnYOffset=DefOffset;
\r
100 BtnFontSize=get(0,'FactoryUIControlFontSize');
\r
101 BtnWidth=DefBtnWidth;
\r
102 TxtBackClr=FigColor;
\r
105 StInfo.Style ='text' ;
\r
106 StInfo.Units ='points' ;
\r
107 StInfo.FontSize =BtnFontSize;
\r
108 StInfo.HorizontalAlignment='left' ;
\r
109 StInfo.BackgroundColor =TxtBackClr ;
\r
110 StInfo.ForegroundColor =TxtForeClr ;
\r
111 StInfo.HandleVisibility ='callback' ;
\r
115 EdInfo.Style='edit';
\r
116 EdInfo.BackgroundColor=White;
\r
119 BtnInfo.Style='pushbutton';
\r
120 BtnInfo.HorizontalAlignment='center';
\r
122 % Determine # of lines for all Prompts
\r
123 ExtControl=uicontrol(StInfo, ...
\r
124 'String' ,'' , ...
\r
125 'Position' ,[DefOffset DefOffset ...
\r
126 0.95*(FigWidth-2*DefOffset) BtnHeight ...
\r
128 'Visible' ,'off' ...
\r
131 WrapQuest=cell(NumQuest,1);
\r
132 QuestPos=zeros(NumQuest,4);
\r
134 for ExtLp=1:NumQuest,
\r
135 [WrapQuest{ExtLp},QuestPos(ExtLp,1:4)]= ...
\r
136 textwrap(ExtControl,Prompt(ExtLp),75);
\r
138 delete(ExtControl);
\r
140 QuestHeight=QuestPos(:,4);
\r
142 TxtHeight=QuestHeight(1)/size(WrapQuest{1,1},1);
\r
143 EditHeight=TxtHeight*NumLines;
\r
144 EditHeight(NumLines==1)=EditHeight(NumLines==1)+4;
\r
146 FigHeight=(NumQuest+2)*DefOffset + ...
\r
147 BtnHeight+sum(EditHeight) + ...
\r
148 sum(QuestHeight);% + ...
\r
149 %NumQuest*SmallOffset;
\r
151 FigWidth=max(175,max(QuestPos(:,3)))+2*DefOffset;
\r
152 FigPos=get(InputFig,'Position');
\r
154 Temp=get(0,'Units');
\r
155 set(0,'Units','points');
\r
156 ScreenSize=get(0,'ScreenSize');
\r
157 set(0,'Units',Temp);
\r
159 FigPos(1)=(ScreenSize(3)-FigWidth)/2;
\r
160 FigPos(2)=(ScreenSize(4)-FigHeight)/2;
\r
161 FigPos(3)=FigWidth;
\r
162 FigPos(4)=FigHeight;
\r
163 set(InputFig,'Position',FigPos);
\r
165 TxtXOffset=DefOffset;
\r
166 TxtWidth=FigWidth-2*DefOffset;
\r
168 TxtBackClr=get(InputFig,'Color');
\r
170 QuestYOffset=zeros(NumQuest,1);
\r
171 EditYOffset=zeros(NumQuest,1);
\r
172 QuestYOffset(1)=FigHeight-DefOffset-QuestHeight(1);
\r
173 EditYOffset(1)=QuestYOffset(1)-EditHeight(1);% -SmallOffset;
\r
175 for YOffLp=2:NumQuest,
\r
176 QuestYOffset(YOffLp)=EditYOffset(YOffLp-1)-QuestHeight(YOffLp)-DefOffset;
\r
177 EditYOffset(YOffLp)=QuestYOffset(YOffLp)-EditHeight(YOffLp); %-SmallOffset;
\r
183 QuestTag=['Prompt' num2str(lp)];
\r
184 EditTag=['Edit' num2str(lp)];
\r
185 QuestHandle(lp)=uicontrol(InputFig , ...
\r
187 'Max' ,size(Prompt{lp},1), ...
\r
188 'Position' ,[ TxtXOffset QuestYOffset(lp) ...
\r
189 TxtWidth QuestHeight(lp) ...
\r
191 'String' ,WrapQuest{lp} , ...
\r
192 'Tag' ,QuestTag ...
\r
195 EditHandle(lp)=uicontrol(InputFig , ...
\r
197 'Max' ,NumLines(lp) , ...
\r
198 'Position' ,[ TxtXOffset EditYOffset(lp) ...
\r
199 TxtWidth EditHeight(lp) ...
\r
201 'String' ,DefAns{lp} , ...
\r
202 'Tag' ,QuestTag ...
\r
207 CBString='set(gcf,''UserData'',''Cancel'');uiresume';
\r
209 CancelHandle=uicontrol(InputFig , ...
\r
211 'Position' ,[ DefOffset DefOffset ...
\r
212 BtnWidth BtnHeight ...
\r
214 'String' ,'Cancel' , ...
\r
215 'Callback' ,CBString , ...
\r
216 'Tag' ,'Cancel' ...
\r
220 CBString='set(gcf,''UserData'',''OK'');uiresume';
\r
222 OKHandle=uicontrol(InputFig , ...
\r
224 'Position' ,[ FigWidth-BtnWidth-DefOffset DefOffset ...
\r
225 BtnWidth BtnHeight ...
\r
227 'Callback' ,CBString , ...
\r
228 'String' ,'OK' , ...
\r
232 set(InputFig, 'KeyPressFcn', CBString);
\r
233 set(InputFig ,'Visible','on');
\r
234 set(findobj(InputFig),'Units','normalized','HandleVisibility','callback');
\r
235 set(InputFig,'Units','points');
\r
239 TempHide=get(0,'ShowHiddenHandles');
\r
240 set(0,'ShowHiddenHandles','on');
\r
242 if any(get(0,'Children')==InputFig),
\r
244 if strcmp(get(InputFig,'UserData'),'OK'),
\r
245 Answer=cell(NumQuest,1);
\r
247 Answer(lp)=get(EditHandle(lp),{'String'});
\r
255 set(0,'ShowHiddenHandles',TempHide);
\r