GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
gtk-manager.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2007-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include "error.h"
31 #include "graphics-toolkit.h"
32 #include "gtk-manager.h"
33 #include "ovl.h"
34 #include "parse.h"
35 
36 namespace octave
37 {
40  {
42 
43  if (dtk.empty ())
44  error ("no graphics toolkits are available!");
45 
46  auto pl = loaded_toolkits.find (dtk);
47 
48  if (pl == loaded_toolkits.end ())
49  {
50  auto pa = available_toolkits.find (dtk);
51 
52  if (pa == available_toolkits.end ())
53  error ("default graphics toolkit '%s' is not available!",
54  dtk.c_str ());
55 
56  octave_value_list args;
57  args(0) = dtk;
58  feval ("graphics_toolkit", args);
59 
60  pl = loaded_toolkits.find (dtk);
61 
62  if (pl == loaded_toolkits.end ())
63  error ("failed to load %s graphics toolkit", dtk.c_str ());
64 
65  retval = pl->second;
66  }
67  else
68  retval = pl->second;
69 
70  return retval;
71  }
72 
73  void
74  gtk_manager::register_toolkit (const std::string& name)
75  {
76  if (dtk.empty () || name == "qt"
77  || (name == "fltk"
78  && available_toolkits.find ("qt") == available_toolkits.end ()))
79  dtk = name;
80 
81  available_toolkits.insert (name);
82  }
83 
84  void
86  {
87  available_toolkits.erase (name);
88 
89  if (dtk == name)
90  {
91  if (available_toolkits.empty ())
92  dtk.clear ();
93  else
94  {
95  auto pa = available_toolkits.cbegin ();
96 
97  dtk = *pa++;
98 
99  while (pa != available_toolkits.cend ())
100  {
101  std::string tk_name = *pa++;
102 
103  if (tk_name == "qt"
104  || (tk_name == "fltk"
105  && (available_toolkits.find ("qt")
106  == available_toolkits.cend ())))
107  dtk = tk_name;
108  }
109  }
110  }
111  }
112 }
void unregister_toolkit(const std::string &name)
Definition: gtk-manager.cc:85
void register_toolkit(const std::string &name)
Definition: gtk-manager.cc:74
graphics_toolkit get_toolkit(void) const
Definition: gtk-manager.cc:39
std::map< std::string, graphics_toolkit > loaded_toolkits
Definition: gtk-manager.h:126
std::set< std::string > available_toolkits
Definition: gtk-manager.h:123
void error(const char *fmt,...)
Definition: error.cc:968
QString name
octave_value_list feval(const char *name, const octave_value_list &args, int nargout)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
Definition: oct-parse.cc:9580
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811