GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
gtk-manager.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2007-2025 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 "interpreter.h"
32#include "graphics-toolkit.h"
33#include "gtk-manager.h"
34#include "ovl.h"
35
37
40{
41 graphics_toolkit retval;
42
43 if (m_dtk.empty ())
44 error ("no graphics toolkits are available!");
45
46 auto pl = m_loaded_toolkits.find (m_dtk);
47
48 if (pl == m_loaded_toolkits.end ())
49 {
50 auto pa = m_available_toolkits.find (m_dtk);
51
52 if (pa == m_available_toolkits.end ())
53 error ("default graphics toolkit '%s' is not available!",
54 m_dtk.c_str ());
55
57 args(0) = m_dtk;
58 m_interpreter.feval ("graphics_toolkit", args);
59
60 pl = m_loaded_toolkits.find (m_dtk);
61
62 if (pl == m_loaded_toolkits.end ())
63 error ("failed to load %s graphics toolkit", m_dtk.c_str ());
64
65 retval = pl->second;
66 }
67 else
68 retval = pl->second;
69
70 return retval;
71}
72
73void
74gtk_manager::register_toolkit (const std::string& name)
75{
76 if (m_dtk.empty () || name == "qt"
77 || (name == "fltk"
78 && m_available_toolkits.find ("qt") == m_available_toolkits.end ()))
79 m_dtk = name;
80
81 m_available_toolkits.insert (name);
82}
83
84void
85gtk_manager::unregister_toolkit (const std::string& name)
86{
87 m_available_toolkits.erase (name);
88
89 if (m_dtk == name)
90 {
91 if (m_available_toolkits.empty ())
92 m_dtk.clear ();
93 else
94 {
95 auto pa = m_available_toolkits.cbegin ();
96
97 m_dtk = *pa++;
98
99 while (pa != m_available_toolkits.cend ())
100 {
101 std::string tk_name = *pa++;
102
103 if (tk_name == "qt"
104 || (tk_name == "fltk"
105 && (m_available_toolkits.find ("qt")
106 == m_available_toolkits.cend ())))
107 m_dtk = tk_name;
108 }
109 }
110 }
111}
112
113OCTAVE_END_NAMESPACE(octave)
void register_toolkit(const std::string &name)
void unregister_toolkit(const std::string &name)
graphics_toolkit get_toolkit() const
octave_value_list feval(const char *name, const octave_value_list &args=octave_value_list(), int nargout=0)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition error.cc:1003