1 ## Copyright (C) 2010 Martin Hepperle
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function file} {@var{[SEL,OK]} =} listdlg (@var{KEY} ,@var{VALUE} [, @var{KEY} ,@var{VALUE}, ...]])
19 ## Returns the user's inputs from a list dialog box in form of a vector of
20 ## selection indices SEL and a flag OK indicating how the user closed the dialog box.
21 ## The returned flag OK is 1 if the user closed the box with the OK button,
22 ## otherwise it is 0 and SEL is empty.
23 ## The indices in SEL are 1 based, i.e. the first list item carries the index 1.
25 ## The arguments are specified in form of @var{KEY}, @var{VALUE} pairs.
26 ## At least the 'ListString' argument pair must be specified.
28 ## @var{KEY}s and @var{VALUE}s pairs can be selected from the following list:
32 ## a cell array of strings comprising the content of the list.
33 ## @item SelectionMode
34 ## can be either @samp{Single} or @samp{Multiple}.
36 ## a vector with two elements [width, height] defining the size of the list field in pixels.
38 ## a vector containing 1-based indices of preselected elements.
40 ## a string to be used as the dialog caption.
42 ## a cell array of strings to be displayed above the list field.
44 ## a string used to label the OK button.
46 ## a string used to label the Cancel button.
52 ## [sel, ok] = listdlg ( 'ListString',@{'An item', 'another', 'yet another'@}, 'SelectionMode','Multiple' );
54 ## imax = length(sel);
62 ## @seealso{errordlg, helpdlg, inputdlg, questdlg, warndlg}
64 function varargout = listdlg(varargin)
73 listsize = [300,160]; % vector!
74 initialvalue = [1]; % vector!
78 cancelstring = 'Cancel';
80 % handle key, value pairs
82 if strcmp(varargin{i},'ListString')
83 listcell = varargin{i+1};
84 elseif strcmp(varargin{i},'SelectionMode')
85 selmode = varargin{i+1};
86 elseif strcmp(varargin{i},'ListSize')
87 listsize = varargin{i+1};
88 elseif strcmp(varargin{i},'InitialValue')
89 initialvalue = varargin{i+1};
90 elseif strcmp(varargin{i},'Name')
92 elseif strcmp(varargin{i},'PromptString')
93 prompt = varargin{i+1};
94 elseif strcmp(varargin{i},'OKString')
95 okstring = varargin{i+1};
96 elseif strcmp(varargin{i},'CancelString')
97 cancelstring = varargin{i+1};
101 % make sure prompt strings are a cell array
106 % make sure listcell strings are a cell array
107 if ! iscell(listcell)
108 listcell = {listcell};
112 % transform matrices to cell arrays of strings
113 listsize = arrayfun(@num2str,listsize,'UniformOutput',false);
114 initialvalue = arrayfun(@num2str,initialvalue,'UniformOutput',false);
116 ret = java_invoke ('org.octave.JDialogBox', 'listdlg', listcell, ...
117 selmode, listsize, initialvalue, name, prompt, ...
118 okstring, cancelstring );
120 varargout = {ret, 1};