0
|
1 ## Copyright (C) 1998, 1999, 2000 Joao Cardoso. |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify it |
|
4 ## under the terms of the GNU General Public License as published by the |
|
5 ## Free Software Foundation; either version 2 of the License, or (at your |
|
6 ## option) any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, but |
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
11 ## General Public License for more details. |
|
12 ## |
|
13 ## This file is part of tk_octave. |
|
14 |
|
15 ## value = tk_dialog(title, text, bitmap, default, ...) |
|
16 ## |
|
17 ## open a dialog window named 'title' with 'text' printed and N buttons |
|
18 ## named as the optional arguments, with button numbered 'default' being |
|
19 ## the default action. The return value is the number of the clicked button. |
|
20 ## First button is number 0. |
|
21 ## |
|
22 ## eg: ret = tk_dialog("Warning", "You are about to erase the whole disk. Are |
|
23 ## you sure?", "questhead", 0, "No","Yes", "Have I asked you something?") |
|
24 ## will return 0 if the first button (No) is clicked, etc. |
|
25 ## |
|
26 ## there are 6 meaningfull bitmap names: error, hourglass, info, questhead, |
|
27 ## question and warning. All arguments must be strings, except 'default'. |
|
28 |
|
29 ## 2001-09-14 Paul Kienzle <pkienzle@users.sf.net> |
|
30 ## * spelling corrections |
|
31 ## * modified to work with pthreads version of tk_interp |
|
32 |
|
33 |
|
34 function value = tk_dialog(title, text, bitmap, default, ...) |
|
35 |
|
36 eval("tk_interp",""); |
|
37 |
|
38 if (nargin < 5 ) |
|
39 help tk_dialog |
|
40 return |
|
41 endif |
|
42 |
|
43 if (! (isstr(title) & isstr(text) & isstr(bitmap) & is_scalar(default))) |
|
44 error("'title', 'text' and 'bitmap' must be strings, and 'default' must be scalar.\n"); |
|
45 return |
|
46 endif |
|
47 |
|
48 if (!(strcmp(bitmap, "error") || strcmp(bitmap, "hourglass") || \ |
|
49 strcmp(bitmap, "info") || strcmp(bitmap, "questhead") || \ |
|
50 strcmp(bitmap, "question") || strcmp(bitmap, "warning"))) |
|
51 error("'bitmap' must be one of 'error', 'hourglass', 'info', \ |
|
52 'questhead', 'question', 'warning'"); |
|
53 return |
|
54 endif |
|
55 |
|
56 if (default > nargin-5) |
|
57 error("'default' must be less then or equal to the number of buttons -1\n"); |
|
58 return |
|
59 endif |
|
60 |
|
61 cmd = sprintf("tk_dialog .top_tk_dialog \"%s\" \"%s\" \"%s\" %d", title, text, bitmap, default); |
|
62 |
|
63 while(--nargin != 3) |
|
64 arg = va_arg; |
|
65 if (! isstr(arg)) |
|
66 error("The arguments must be strings.\n"); |
|
67 return |
|
68 endif |
|
69 cmd = [cmd " " '"' arg '"']; |
|
70 endwhile |
|
71 |
|
72 value = str2num(tk_cmd( cmd )); |
|
73 |
|
74 endfunction |