-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathptrDlgQuestion.m
95 lines (81 loc) · 3.23 KB
/
ptrDlgQuestion.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
% Show a question in a modal window and wait for answer.
%
% PARAMS:
% - msg -> Message string
% - title -> Window title (optional, default = '')
% - options -> Possible answers (cell)
%
% RETURN:
% - res -> The position of the selected answer or -1 if dialog is canceled
%
function res = ptrDlgQuestion(msg, title, options)
winWidth = 500; % Windows width
textCtlHeight = 35; % Height reserved for question text
res = -1;
if nargin<3, return, end
nOptions = numel(options);
if ~isempty(msg) && strcmp(msg(1),'$'), msg = ptrLgGetString(msg(2:end)); end
if ~isempty(title) && strcmp(title(1),'$'), title = ptrLgGetString(title(2:end)); end
for i=1:nOptions,
option = options{i};
if ~isempty(option) && strcmp(option(1),'$')
options{i} = ptrLgGetString(option(2:end));
end
end
btnTex = ptrLgGetString('all_SelecBtn');
f = figure('Name', title, 'NumberTitle', 'off','visible','off', ...
'WindowStyle','modal');
pos = get(f, 'Position');
pos (3) = winWidth;
pos (4) = 80 + textCtlHeight + nOptions * 25;
set (f, 'Position', pos);
set (f, 'MenuBar', 'none');
set (f, 'Resize', 'off');
set (f, 'WindowStyle', 'modal');
ptrCenterWindow(f);
pan = uipanel('Parent',f, 'BorderType', 'none',...
'Units','pixels','Position',[1 1 pos(3) pos(4)]);
textCtl = uicontrol('Parent',pan, ...
'String',msg, ...
'Style','text', ...
'Units','pixels', ...
'Position',[20 pos(4)-textCtlHeight-10 pos(3)-40 textCtlHeight], ...
'FontUnits','pixels', ...
'FontName', 'Helvetica', ...
'FontSize',12, ...
'HorizontalAlignment','left');
btnGroup = uibuttongroup ('Parent', pan, ...
'Title','', ...
'BorderType','none',...
'Units','pixels', ...
'Position',[20 50 pos(3)-40 pos(4)-30-textCtlHeight-10*2], ...
'FontUnits','pixels', ...
'FontName', 'Helvetica', ...
'FontSize',12);
for i=1:nOptions
radio(i) = uicontrol('Parent',btnGroup, ...
'String', options{i}, ...
'Style', 'radiobutton', ...
'Units','pixels', ...
'Position', [10 10+25*(nOptions-i) pos(3)-60 25], ...
'FontUnits', 'pixels', ...
'FontName', 'Helvetica', ...
'FontSize', 12);
end
btnOk = uicontrol('Parent',pan, ...
'String', btnTex,...
'Units','pixels', ...
'Position', [(pos(3)-90)/2 10 90 30], ...
'FontUnits', 'pixels', ...
'FontName', 'Helvetica', ...
'FontSize', 11, ...
'FontWeight', 'bold',...
'Callback', 'uiresume(gcbf)');
set(f,'Visible','on');
uiwait(f);
if ishandle(f)
sel = get(btnGroup,'SelectedObject');
res = find(radio == sel);
close(f);
end
end