annotate scripts/gui/msgbox.m @ 31191:bb9d776eafac stable

Fix wrong color in PDF printout of some latex strings (bug #62884) * octave-svgconvert (draw): For "rect" elements only set brush color if necessary and eventually restore to previous color.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Sun, 14 Aug 2022 18:24:07 +0200
parents a1476e3ea73d
children 597f3ee61a48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30195
diff changeset
3 ## Copyright (C) 2010-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 ##
15746
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
8 ## This file is part of Octave.
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
15746
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
15746
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
14 ##
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 ##
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
15746
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15709
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20181
diff changeset
27 ## @deftypefn {} {@var{h} =} msgbox (@var{msg})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20181
diff changeset
28 ## @deftypefnx {} {@var{h} =} msgbox (@var{msg}, @var{title})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20181
diff changeset
29 ## @deftypefnx {} {@var{h} =} msgbox (@var{msg}, @var{title}, @var{icon})
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
30 ## @deftypefnx {} {@var{h} =} msgbox (@var{msg}, @var{title}, "custom", @var{cdata})
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
31 ## @deftypefnx {} {@var{h} =} msgbox (@var{msg}, @var{title}, "custom", @var{cdata}, @var{colormap})
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
32 ## @deftypefnx {} {@var{h} =} msgbox (@dots{}, @var{opt})
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
33 ## Display @var{msg} using a message dialog box.
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 ##
20173
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20071
diff changeset
35 ## The message may have multiple lines separated by newline characters ("\n"),
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20071
diff changeset
36 ## or it may be a cellstr array with one element for each line.
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20071
diff changeset
37 ##
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20071
diff changeset
38 ## The optional input @var{title} (character string) can be used to decorate
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20071
diff changeset
39 ## the dialog caption.
15709
9fee0b741de6 Update Java dialog scrips to latest octave-forge status
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15625
diff changeset
40 ##
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
41 ## The optional argument @var{icon} selects a dialog icon.
20173
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20071
diff changeset
42 ## It can be one of @qcode{"none"} (default), @qcode{"error"}, @qcode{"help"},
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
43 ## @qcode{"warn"}, or @qcode{"custom"}. The latter must be followed by an
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
44 ## image array @var{cdata}, and for indexed images the associated colormap.
15748
54e8c2527a9e style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
45 ##
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
46 ## The final optional argument @var{opt} controls the behavior of the dialog.
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25921
diff changeset
47 ## If @var{opt} is a string, it may be one of
20071
98d10871018a Accept CREATEMODE argument for errordlg, warndlg, msgbox (bug #44775).
Rik <rik@octave.org>
parents: 19596
diff changeset
48 ##
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
49 ## @table @asis
26035
0a39db17170c doc: Clean up docstrings for XXXdlg.m functions
Rik <rik@octave.org>
parents: 26033
diff changeset
50 ## @item @qcode{"non-modal"} (default)
0a39db17170c doc: Clean up docstrings for XXXdlg.m functions
Rik <rik@octave.org>
parents: 26033
diff changeset
51 ## The dialog is normal.
0a39db17170c doc: Clean up docstrings for XXXdlg.m functions
Rik <rik@octave.org>
parents: 26033
diff changeset
52 ##
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
53 ## @item @qcode{"modal"}
27080
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
54 ## If any dialogs already exist with the same title, the most recent is reused
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
55 ## and all others are closed. The dialog is displayed @qcode{"modal"} which
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
56 ## means it prevents users from interacting with any other GUI element until
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
57 ## the dialog has been closed.
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
58 ##
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
59 ## @item @qcode{"replace"}
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
60 ## If any dialogs already exist with the same title, the most recent is reused
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
61 ## and all others are closed. The resulting dialog is set @qcode{"non-modal"}.
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
62 ## @end table
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
63 ##
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
64 ## If @var{opt} is a structure, it must contain fields @qcode{"WindowStyle"}
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
65 ## and @qcode{"Interpreter"}:
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
66 ##
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
67 ## @table @asis
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
68 ## @item @qcode{"WindowStyle"}
26035
0a39db17170c doc: Clean up docstrings for XXXdlg.m functions
Rik <rik@octave.org>
parents: 26033
diff changeset
69 ## The value must be @qcode{"non-modal"}, @qcode{"modal"}, or
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
70 ## @qcode{"replace"}. See above.
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
71 ##
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
72 ## @item @qcode{"Interpreter"}
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
73 ## Controls the @qcode{"interpreter"} property of the text object used for
26035
0a39db17170c doc: Clean up docstrings for XXXdlg.m functions
Rik <rik@octave.org>
parents: 26033
diff changeset
74 ## displaying the message. The value must be @qcode{"tex"} (default),
0a39db17170c doc: Clean up docstrings for XXXdlg.m functions
Rik <rik@octave.org>
parents: 26033
diff changeset
75 ## @qcode{"none"}, or @qcode{"latex"}.
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
76 ## @end table
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25921
diff changeset
77 ##
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
78 ## The return value @var{h} is a handle to the figure object used for building
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
79 ## the dialog.
21630
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
80 ##
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
81 ## Examples:
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
82 ##
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
83 ## @example
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
84 ## @group
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
85 ## msgbox ("Some message for the user.");
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
86 ## msgbox ("Some message\nwith two lines.");
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
87 ## msgbox (@{"Some message", "with two lines."@});
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
88 ## msgbox ("Some message for the user.", "Fancy caption");
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
89 ##
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
90 ## ## A message dialog box with error icon
21630
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
91 ## msgbox ("Some message for the user.", "Fancy caption", "error");
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
92 ## @end group
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
93 ## @end example
20181
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20173
diff changeset
94 ##
15772
0f1a143e5002 Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents: 15750
diff changeset
95 ## @seealso{errordlg, helpdlg, inputdlg, listdlg, questdlg, warndlg}
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 ## @end deftypefn
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97
27080
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
98 function retval = msgbox (msg, varargin)
15772
0f1a143e5002 Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents: 15750
diff changeset
99
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
100 if (nargin < 1)
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
101 print_usage ();
27080
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
102 endif
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
103
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
104 if (! ischar (msg) && ! iscellstr (msg))
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
105 error ("msgbox: MSG must be a string or cell array of strings");
27076
39b4341c3376 msgbox.m: Allow OPT argument in second position (bug #56260).
Rik <rik@octave.org>
parents: 26376
diff changeset
106 endif
27080
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
107
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
108 nargs = numel (varargin);
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
109 tit = "";
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
110 icon = "none";
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
111 windowstyle = "non-modal";
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
112 interpreter = "tex";
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
113
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
114 if (nargs > 0)
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
115 ## Check for option argument in last position
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
116 if (isstruct (varargin{nargs}))
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
117 opts = varargin{nargs};
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
118 if (isfield (opts, "WindowStyle"))
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
119 windowstyle = opts.WindowStyle;
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
120 endif
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
121 if (isfield (opts, "Interpreter"))
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
122 interpreter = opts.Interpreter;
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
123 endif
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
124
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
125 if (! any (strcmp (windowstyle, {"non-modal", "modal", "replace"})))
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
126 error ('msgbox: invalid value "%s" for WindowStyle', windowstyle);
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
127 endif
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
128 nargs -= 1;
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
129
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
130 elseif (any (strcmp (varargin{nargs}, {"non-modal", "modal", "replace"})))
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
131 windowstyle = varargin{nargs};
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
132 nargs -= 1;
27076
39b4341c3376 msgbox.m: Allow OPT argument in second position (bug #56260).
Rik <rik@octave.org>
parents: 26376
diff changeset
133 endif
39b4341c3376 msgbox.m: Allow OPT argument in second position (bug #56260).
Rik <rik@octave.org>
parents: 26376
diff changeset
134 endif
27080
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
135
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
136 if (nargs > 0)
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
137 tit = varargin{1};
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
138 if (! ischar (tit))
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
139 error ("msgbox: TITLE must be a string");
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
140 endif
27080
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
141 if (nargs > 1)
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
142 icon = varargin{2};
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
143 if (! any (strcmp (icon, {"help", "warn", "error", "none", "custom"})))
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
144 if (ischar (icon))
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
145 error ('msgbox: invalid value "%s" for ICON', icon);
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
146 else
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
147 error ("msgbox: ICON must be a string");
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
148 endif
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
149 elseif (strcmp (icon, "custom"))
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
150 if (nargs < 3)
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
151 error ('msgbox: missing data for "custom" icon');
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
152 endif
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
153 icon = struct ("cdata", varargin{3}, "colormap", []);
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
154 if (! isnumeric (icon.cdata))
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
155 error ('msgbox: invalid data for "custom" icon');
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
156 elseif (! ismatrix (icon.cdata)
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
157 && (ndims (icon.cdata) != 3 || size (icon.cdata, 3) != 3))
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
158 error ('msgbox: invalid data for "custom" icon');
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
159 elseif (ismatrix (icon.cdata) && nargs == 4)
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
160 icon.colormap = varargin{4};
31012
a1476e3ea73d msgbox.m: Allow "custom" cdata for icon (bug #62445).
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
161 elseif (nargs > 3)
27080
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
162 print_usage ();
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
163 endif
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
164 elseif (nargs > 2)
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
165 print_usage ();
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
166 endif
21630
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
167 endif
15772
0f1a143e5002 Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents: 15750
diff changeset
168 endif
15709
9fee0b741de6 Update Java dialog scrips to latest octave-forge status
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15625
diff changeset
169
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
170 ## Window behavior and text interpreter
27080
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
171 if (strcmp (windowstyle, "non-modal"))
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
172 windowstyle = "normal";
21630
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
173 endif
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25921
diff changeset
174
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
175 ## Make a GUI element or print to console
30195
a7981aa5822b event-manager: Add function to signal valid implementation of GUI dialogs (bug #60980).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29359
diff changeset
176 if (__event_manager_have_dialogs__ ())
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
177 retval = __msgbox__ (msg, tit, icon, windowstyle, interpreter);
21630
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
178 else
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
179 if (iscellstr (msg))
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
180 msg = strjoin (msg, "\n");
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
181 endif
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
182 if (isstruct (icon))
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
183 icon = "custom";
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
184 endif
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
185 disp (sprintf ("\n%s:\t%s\n\t%s\n",
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
186 upper (icon), tit, strrep (msg, "\n", "\n\t")));
21630
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
187 retval = 1;
b5d9b95d1e1a Removing Java dialog boxes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20852
diff changeset
188 endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190 endfunction
15772
0f1a143e5002 Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents: 15750
diff changeset
191
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
192 function hf = __msgbox__ (msg, tit, icon, windowstyle, interpreter)
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
193
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
194 ## Prepare graphics objects
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
195 hf = [];
27080
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
196 if (strcmp (windowstyle, "replace") || strcmp (windowstyle, "modal"))
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
197 hf = findall (groot, "tag", "__dialog__", "-and", "name", tit);
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
198 endif
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
199 if (strcmp (windowstyle, "replace"))
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
200 windowstyle = "normal";
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
201 endif
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
202
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
203 if (! isempty (hf))
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
204 if (numel (hf) > 1)
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
205 close (hf(2:end));
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
206 endif
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
207 hf = hf(1);
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
208 set (hf, "visible", "off", "windowstyle", "normal");
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
209 else
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
210 hf = dialog ("visible", "off", "name", tit, "tag", "__dialog__", ...
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
211 "windowstyle", "normal");
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
212 if (! strcmp (graphics_toolkit (), "qt"))
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
213 graphics_toolkit (hf, "qt");
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
214 endif
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
215 endif
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25921
diff changeset
216
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
217 hp = uipanel (hf);
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25921
diff changeset
218
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
219 hax = axes ("parent", hp, "visible", "off", "units", "pixels", ...
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
220 "ydir", "reverse");
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25921
diff changeset
221
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
222 ht = text ("parent", hax, "string", msg, "units", "pixels", ...
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
223 "fontsize", 14, "interpreter", interpreter);
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25921
diff changeset
224
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
225 ## Hold default icons data in a persistent variable
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
226 persistent cdata = struct ("help", [], "warn", [], "error", []);
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
227
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
228 icon_name = "custom";
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
229 if (ischar (icon))
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
230 icon_name = icon;
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
231 icon = struct ("cdata", [], "colormap", []);
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
232 if (isfield (cdata, icon_name))
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
233 if (! isempty (cdata.(icon_name)))
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
234 icon.cdata = cdata.(icon_name);
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
235 else
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
236 if (strcmp (icon_name, "help"))
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
237 icon_name = "information";
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
238 elseif (strcmp (icon_name, "warn"))
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
239 icon_name = "warning";
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
240 endif
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27080
diff changeset
241 tmp = __event_manager_named_icon__ (["dialog-" icon_name]);
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
242 ## Fake transparency until the opengl renderer handles it:
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
243 ## RGB data from Qt are premultiplied, we only need to add the
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
244 ## background part
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
245 alpha = tmp(:,:,4);
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
246 tmp(:,:,4) = [];
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
247 backgnd = get (hp, "backgroundcolor");
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
248 tmp(:,:,1) += backgnd(1) * (255-alpha);
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
249 tmp(:,:,2) += backgnd(2) * (255-alpha);
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
250 tmp(:,:,3) += backgnd(3) * (255-alpha);
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
251 icon.cdata = tmp;
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
252 cdata.(icon_name) = tmp;
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25921
diff changeset
253
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
254 endif
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
255 endif
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
256 endif
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
257
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
258 ## Compute bbox in pixels
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
259 ax_sz = [200 60];
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
260 ax_margin = 12;
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
261 txt_margin = 20;
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
262 button_margin = 40;
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
263
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
264 extent = get (ht, "extent");
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
265 extent(3) += txt_margin;
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
266
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
267 im_sz = size (icon.cdata);
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25921
diff changeset
268
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
269 if (! isempty (icon.cdata))
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
270 extent(3) += im_sz(2);
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
271 extent(4) = max (extent(4), im_sz(1));
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
272 endif
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
273
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
274 ax_sz = max ([ax_sz; extent(3:4)+2*ax_margin]);
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25921
diff changeset
275
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
276 ## Align text left when there is an icon
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
277 text_offset = txt_margin;
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
278 if (! isempty (icon.cdata))
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
279 if (! isempty (icon.colormap))
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
280 set (hax, "colormap", icon.colormap)
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
281 endif
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
282 image ("parent", hax, "cdata", icon.cdata, "cdatamapping", "direct", ...
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
283 "xdata", [1 im_sz(2)], "ydata", [-(im_sz(1))/2+1 im_sz(1)/2]);
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
284 text_offset = im_sz(2) + txt_margin;
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
285 endif
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
286
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
287 ## Set objects position
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
288 wd = ax_sz(1);
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
289 hg = ax_sz(2) + button_margin;
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
290 center = get (0, "screensize")(3:4) / 2;
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25921
diff changeset
291
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
292 set (hf, "position", [center(1)-wd/2 center(2)-hg/2 wd hg]);
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25921
diff changeset
293
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
294 set (hax, "position", [0 button_margin ax_sz], ...
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
295 "xlim", [1 ax_sz(1)]-ax_margin, "ylim", [-ax_sz(2)/2 ax_sz(2)/2], ...
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
296 "units", "normalized");
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
297
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
298 set (ht, "units", "data", "position", [text_offset 0 0]);
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
299
26033
f70729091570 msgbox.m: Install "keypress" callback that closes box when <RETURN> pressed (bug #54942).
Rik <rik@octave.org>
parents: 26007
diff changeset
300 hui = uicontrol ("string", "OK",
f70729091570 msgbox.m: Install "keypress" callback that closes box when <RETURN> pressed (bug #54942).
Rik <rik@octave.org>
parents: 26007
diff changeset
301 "callback", @cb_callback,
f70729091570 msgbox.m: Install "keypress" callback that closes box when <RETURN> pressed (bug #54942).
Rik <rik@octave.org>
parents: 26007
diff changeset
302 "keypressfcn", @cb_keypress,
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
303 "position", [ax_sz(1)/2-40 ax_margin 80 28], "parent", hp);
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25921
diff changeset
304
26037
864448a7f347 Don't set keyboard focus on newly created uicontrol objects (bug #54942)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26036
diff changeset
305 uicontrol (hui); # Set keyboard focus on the uicontrol
864448a7f347 Don't set keyboard focus on newly created uicontrol objects (bug #54942)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 26036
diff changeset
306
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
307 set (hf, "windowstyle", windowstyle, "visible", "on");
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
308
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
309 endfunction
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
310
26033
f70729091570 msgbox.m: Install "keypress" callback that closes box when <RETURN> pressed (bug #54942).
Rik <rik@octave.org>
parents: 26007
diff changeset
311 ## Callback when button clicked (close window)
f70729091570 msgbox.m: Install "keypress" callback that closes box when <RETURN> pressed (bug #54942).
Rik <rik@octave.org>
parents: 26007
diff changeset
312 function cb_callback (~, ~)
f70729091570 msgbox.m: Install "keypress" callback that closes box when <RETURN> pressed (bug #54942).
Rik <rik@octave.org>
parents: 26007
diff changeset
313 close (gcbf ());
f70729091570 msgbox.m: Install "keypress" callback that closes box when <RETURN> pressed (bug #54942).
Rik <rik@octave.org>
parents: 26007
diff changeset
314 endfunction
f70729091570 msgbox.m: Install "keypress" callback that closes box when <RETURN> pressed (bug #54942).
Rik <rik@octave.org>
parents: 26007
diff changeset
315
26036
fe29584dad35 msgbox.m: Close window when "enter", "return", "escape", "space" typed (bug #54942).
Rik <rik@octave.org>
parents: 26035
diff changeset
316 ## Callback when key typed (close window on activation of button)
26033
f70729091570 msgbox.m: Install "keypress" callback that closes box when <RETURN> pressed (bug #54942).
Rik <rik@octave.org>
parents: 26007
diff changeset
317 function cb_keypress (~, ev)
26036
fe29584dad35 msgbox.m: Close window when "enter", "return", "escape", "space" typed (bug #54942).
Rik <rik@octave.org>
parents: 26035
diff changeset
318 if (any (strcmp (ev.Key, {"enter", "return", "escape", "space"})))
26033
f70729091570 msgbox.m: Install "keypress" callback that closes box when <RETURN> pressed (bug #54942).
Rik <rik@octave.org>
parents: 26007
diff changeset
319 close (gcbf ());
f70729091570 msgbox.m: Install "keypress" callback that closes box when <RETURN> pressed (bug #54942).
Rik <rik@octave.org>
parents: 26007
diff changeset
320 endif
f70729091570 msgbox.m: Install "keypress" callback that closes box when <RETURN> pressed (bug #54942).
Rik <rik@octave.org>
parents: 26007
diff changeset
321 endfunction
f70729091570 msgbox.m: Install "keypress" callback that closes box when <RETURN> pressed (bug #54942).
Rik <rik@octave.org>
parents: 26007
diff changeset
322
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
323
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
324 %!demo
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
325 %! msgbox ("A bare dialog");
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
326
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
327 %!demo
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
328 %! msgbox ("An informative string", "Documentation", "help");
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
329
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
330 %!demo
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
331 %! msgbox ("Something the user should hear about before continuing", ...
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
332 %! "Take care!", "warn");
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
333
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
334 %!demo
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
335 %! msgbox ("A critical message for the user", "Error", "error");
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
336
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
337 %!demo
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
338 %! msgbox ({"The default interpreter is 'tex':", ...
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
339 %! '\Delta_{1-2} = r_2 - r_1'}, "Documentation", "help");
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
340
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
341 %!demo
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
342 %! msgbox ({"Help dialog with uninterpreted string:", ...
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
343 %! '\Delta_{1-2} = r_2 - r_1'}, "Documentation", "help", ...
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
344 %! struct ("Interpreter", "none", "WindowStyle", "non-modal"));
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
345
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
346 %!demo
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
347 %! msgbox ({"This dialog has replaced all the previously open dialogs", ...
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
348 %! "that had the same title ('Documentation')."}, "Documentation", ...
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
349 %! "warn", "replace");
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
350
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
351 %!demo
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
352 %! msgbox ("Custom dialog with a random 32-by-32-by-3 RGB icon.", ...
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
353 %! "Dialog Title", "custom", rand (32, 32, 3));
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
354
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
355 %!demo
25948
700b3f415ebe maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25921
diff changeset
356 %! cdata = get (0, "factoryimagecdata");
25921
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
357 %! msgbox ({"Custom dialog with the default Octave image.", ...
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
358 %! "The image is indexed into the 'copper' colormap"}, ...
9c47eedc44e2 msgbox.m: use graphics objects to build dialog (bug #42490)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25054
diff changeset
359 %! "Dialog Title", "custom", cdata, copper (64));
21759
b002b4331a12 maint: Use two newlines after endfunction and start of BIST tests.
Rik <rik@octave.org>
parents: 21630
diff changeset
360
b002b4331a12 maint: Use two newlines after endfunction and start of BIST tests.
Rik <rik@octave.org>
parents: 21630
diff changeset
361 ## Test input validation
28896
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 27923
diff changeset
362 %!error <Invalid call> msgbox ()
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
363 %!error <MSG must be a string or cell array of strings> msgbox (1)
27080
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
364 %!error <invalid value "foobar" for WindowStyle>
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
365 %! msgbox ("msg", struct ("WindowStyle", "foobar"))
26007
790595e6ebb9 msgbox.m: Clean up function.
Rik <rik@octave.org>
parents: 26006
diff changeset
366 %!error <TITLE must be a string> msgbox ("msg", 1)
27080
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
367 %!error <invalid value "foobar" for ICON> msgbox ("msg", "title", "foobar")
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
368 %!error <ICON must be a string> msgbox ("msg", "title", {1})
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
369 %!error <missing data for "custom" icon> msgbox ("msg", "title", "custom")
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
370 %!error <invalid data for "custom" icon>
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
371 %! msgbox ("msg", "title", "custom", {{1}})
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
372 %!error <Invalid call to msgbox> msgbox ("msg", "title", "custom", 1, 2, 3)
c4cb6f431773 msgbox.m: Overhaul input processing.
Rik <rik@octave.org>
parents: 27076
diff changeset
373 %!error <Invalid call to msgbox> msgbox ("msg", "title", "help", "1")