GNU Octave 7.1.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-2022 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
36namespace octave
37{
38 graphics_toolkit
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 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
73 void
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
82 }
83
84 void
86 {
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}
void unregister_toolkit(const std::string &name)
Definition: gtk-manager.cc:85
void register_toolkit(const std::string &name)
Definition: gtk-manager.cc:74
std::map< std::string, graphics_toolkit > m_loaded_toolkits
Definition: gtk-manager.h:126
std::string m_dtk
Definition: gtk-manager.h:120
std::set< std::string > m_available_toolkits
Definition: gtk-manager.h:123
graphics_toolkit get_toolkit(void) const
Definition: gtk-manager.cc:39
void error(const char *fmt,...)
Definition: error.cc:980
QString name
OCTINTERP_API octave_value_list feval(const char *name, const octave_value_list &args=octave_value_list(), int nargout=0)