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.h
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 (octave_gtk_manager_h)
27#define octave_gtk_manager_h 1
28
29#include "octave-config.h"
30
31#include <map>
32#include <set>
33#include <string>
34
35#include "Cell.h"
36#include "graphics-toolkit.h"
37
39
40class interpreter;
41
42class OCTINTERP_API gtk_manager
43{
44public:
45
46 gtk_manager (interpreter& interp) : m_interpreter (interp) { }
47
48 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (gtk_manager)
49
51 {
52 unload_all_toolkits ();
53 }
54
55 graphics_toolkit get_toolkit () const;
56
57 void register_toolkit (const std::string& name);
58
59 void unregister_toolkit (const std::string& name);
60
62 {
63 m_loaded_toolkits[tk.get_name ()] = tk;
64 }
65
66 void unload_toolkit (const std::string& name)
67 {
68 m_loaded_toolkits.erase (name);
69 }
70
71 graphics_toolkit find_toolkit (const std::string& name) const
72 {
73 auto p = m_loaded_toolkits.find (name);
74
75 if (p != m_loaded_toolkits.end ())
76 return p->second;
77 else
78 return graphics_toolkit ();
79 }
80
82 {
83 Cell m (1, m_available_toolkits.size ());
84
85 octave_idx_type i = 0;
86 for (const auto& tkit : m_available_toolkits)
87 m(i++) = tkit;
88
89 return m;
90 }
91
93 {
94 Cell m (1, m_loaded_toolkits.size ());
95
96 octave_idx_type i = 0;
97 for (const auto& nm_tkit_p : m_loaded_toolkits)
98 m(i++) = nm_tkit_p.first;
99
100 return m;
101 }
102
104 {
105 while (! m_loaded_toolkits.empty ())
106 {
107 auto p = m_loaded_toolkits.begin ();
108
109 std::string name = p->first;
110
111 p->second.close ();
112
113 // The toolkit may have unloaded itself. If not, we'll do it here.
114 if (m_loaded_toolkits.find (name) != m_loaded_toolkits.end ())
115 unload_toolkit (name);
116 }
117 }
118
119 std::string default_toolkit () const { return m_dtk; }
120
121private:
122
123 interpreter& m_interpreter;
124
125 // The name of the default toolkit.
126 std::string m_dtk;
127
128 // The list of toolkits that we know about.
129 std::set<std::string> m_available_toolkits;
130
131 // The list of toolkits we have actually loaded.
132 std::map<std::string, graphics_toolkit> m_loaded_toolkits;
133};
134
135OCTAVE_END_NAMESPACE(octave)
136
137#endif
Definition Cell.h:41
std::string get_name() const
void load_toolkit(const graphics_toolkit &tk)
Definition gtk-manager.h:61
gtk_manager(interpreter &interp)
Definition gtk-manager.h:46
void unload_all_toolkits()
std::string default_toolkit() const
void unload_toolkit(const std::string &name)
Definition gtk-manager.h:66
Cell loaded_toolkits_list() const
Definition gtk-manager.h:92
graphics_toolkit find_toolkit(const std::string &name) const
Definition gtk-manager.h:71
Cell available_toolkits_list() const
Definition gtk-manager.h:81
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn