1 ## Copyright (C) 2008-2012 Michael Goffioul
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {@var{name} =} graphics_toolkit ()
21 ## @deftypefnx {Function File} {@var{old_name} =} graphics_toolkit (@var{name})
22 ## @deftypefnx {Function File} {} graphics_toolkit (@var{hlist}, @var{name})
23 ## Query or set the default graphics toolkit to @var{name}. If the
24 ## toolkit is not already loaded, it is first initialized by calling the
25 ## function @code{__init_@var{name}__}.
27 ## When called with a list of figure handles, @var{hlist}, the graphics
28 ## toolkit is changed only for the listed figures.
29 ## @seealso{available_graphics_toolkits}
32 function retval = graphics_toolkit (name, hlist = [])
38 if (nargout > 0 || nargin == 0)
39 retval = get (0, "defaultfigure__graphics_toolkit__");
46 error ("graphics_toolkit: invalid graphics toolkit NAME");
49 ## Swap input arguments
50 [hlist, name] = deal (name, hlist);
51 if (! all (isfigure (hlist)))
52 error ("graphics_toolkit: invalid figure handle list HLIST");
53 elseif (! ischar (name))
54 error ("graphics_toolkit: invalid graphics toolkit NAME");
58 if (! any (strcmp (loaded_graphics_toolkits (), name)))
59 feval (["__init_", name, "__"]);
60 if (! any (strcmp (loaded_graphics_toolkits (), name)))
61 error ("graphics_toolkit: %s toolkit was not correctly loaded", name);
66 set (0, "defaultfigure__graphics_toolkit__", name);
68 set (hlist, "__graphics_toolkit__", name);
76 %! hf = figure ("visible", "off");
77 %! toolkit = graphics_toolkit ();
78 %! assert (get (0, "defaultfigure__graphics_toolkit__"), toolkit);
79 %! graphics_toolkit (hf, "fltk");
80 %! assert (get (hf, "__graphics_toolkit__"), "fltk");
81 %! unwind_protect_cleanup
86 %! old_toolkit = graphics_toolkit ();
89 %! new_toolkit = "fltk";
91 %! new_toolkit = "gnuplot";
93 %! assert (graphics_toolkit (new_toolkit), old_toolkit)
94 %! assert (graphics_toolkit (old_toolkit), new_toolkit)