GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
gtk-manager.h
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 (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
38namespace octave
39{
40 class OCTINTERP_API gtk_manager
41 {
42 public:
43
44 gtk_manager (void) { }
45
47 {
48 unload_all_toolkits ();
49 }
50
51 graphics_toolkit get_toolkit (void) const;
52
53 void register_toolkit (const std::string& name);
54
55 void unregister_toolkit (const std::string& name);
56
58 {
59 m_loaded_toolkits[tk.get_name ()] = tk;
60 }
61
62 void unload_toolkit (const std::string& name)
63 {
64 m_loaded_toolkits.erase (name);
65 }
66
67 graphics_toolkit find_toolkit (const std::string& name) const
68 {
69 auto p = m_loaded_toolkits.find (name);
70
71 if (p != m_loaded_toolkits.end ())
72 return p->second;
73 else
74 return graphics_toolkit ();
75 }
76
78 {
79 Cell m (1, m_available_toolkits.size ());
80
81 octave_idx_type i = 0;
82 for (const auto& tkit : m_available_toolkits)
83 m(i++) = tkit;
84
85 return m;
86 }
87
89 {
90 Cell m (1, m_loaded_toolkits.size ());
91
92 octave_idx_type i = 0;
93 for (const auto& nm_tkit_p : m_loaded_toolkits)
94 m(i++) = nm_tkit_p.first;
95
96 return m;
97 }
98
100 {
101 while (! m_loaded_toolkits.empty ())
102 {
103 auto p = m_loaded_toolkits.begin ();
104
105 std::string name = p->first;
106
107 p->second.close ();
108
109 // The toolkit may have unloaded itself. If not, we'll do it here.
110 if (m_loaded_toolkits.find (name) != m_loaded_toolkits.end ())
111 unload_toolkit (name);
112 }
113 }
114
115 std::string default_toolkit (void) const { return m_dtk; }
116
117 private:
118
119 // The name of the default toolkit.
120 std::string m_dtk;
121
122 // The list of toolkits that we know about.
123 std::set<std::string> m_available_toolkits;
124
125 // The list of toolkits we have actually loaded.
126 std::map<std::string, graphics_toolkit> m_loaded_toolkits;
127 };
128}
129
130#endif
Definition: Cell.h:43
std::string get_name(void) const
void load_toolkit(const graphics_toolkit &tk)
Definition: gtk-manager.h:57
void unload_all_toolkits(void)
Definition: gtk-manager.h:99
graphics_toolkit find_toolkit(const std::string &name) const
Definition: gtk-manager.h:67
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
Cell loaded_toolkits_list(void) const
Definition: gtk-manager.h:88
Cell available_toolkits_list(void) const
Definition: gtk-manager.h:77
void unload_toolkit(const std::string &name)
Definition: gtk-manager.h:62
std::string default_toolkit(void) const
Definition: gtk-manager.h:115
QString name