1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gobject.TypeModule;
26 
27 private import glib.Str;
28 private import gobject.ObjectG;
29 private import gobject.TypePluginIF;
30 private import gobject.TypePluginT;
31 private import gobject.c.functions;
32 public  import gobject.c.types;
33 public  import gtkc.gobjecttypes;
34 
35 
36 /**
37  * #GTypeModule provides a simple implementation of the #GTypePlugin
38  * interface. The model of #GTypeModule is a dynamically loaded module
39  * which implements some number of types and interface implementations.
40  * When the module is loaded, it registers its types and interfaces
41  * using g_type_module_register_type() and g_type_module_add_interface().
42  * As long as any instances of these types and interface implementations
43  * are in use, the module is kept loaded. When the types and interfaces
44  * are gone, the module may be unloaded. If the types and interfaces
45  * become used again, the module will be reloaded. Note that the last
46  * unref cannot happen in module code, since that would lead to the
47  * caller's code being unloaded before g_object_unref() returns to it.
48  * 
49  * Keeping track of whether the module should be loaded or not is done by
50  * using a use count - it starts at zero, and whenever it is greater than
51  * zero, the module is loaded. The use count is maintained internally by
52  * the type system, but also can be explicitly controlled by
53  * g_type_module_use() and g_type_module_unuse(). Typically, when loading
54  * a module for the first type, g_type_module_use() will be used to load
55  * it so that it can initialize its types. At some later point, when the
56  * module no longer needs to be loaded except for the type
57  * implementations it contains, g_type_module_unuse() is called.
58  * 
59  * #GTypeModule does not actually provide any implementation of module
60  * loading and unloading. To create a particular module type you must
61  * derive from #GTypeModule and implement the load and unload functions
62  * in #GTypeModuleClass.
63  */
64 public class TypeModule : ObjectG, TypePluginIF
65 {
66 	/** the main Gtk struct */
67 	protected GTypeModule* gTypeModule;
68 
69 	/** Get the main Gtk struct */
70 	public GTypeModule* getTypeModuleStruct(bool transferOwnership = false)
71 	{
72 		if (transferOwnership)
73 			ownedRef = false;
74 		return gTypeModule;
75 	}
76 
77 	/** the main Gtk struct as a void* */
78 	protected override void* getStruct()
79 	{
80 		return cast(void*)gTypeModule;
81 	}
82 
83 	/**
84 	 * Sets our main struct and passes it to the parent class.
85 	 */
86 	public this (GTypeModule* gTypeModule, bool ownedRef = false)
87 	{
88 		this.gTypeModule = gTypeModule;
89 		super(cast(GObject*)gTypeModule, ownedRef);
90 	}
91 
92 	// add the TypePlugin capabilities
93 	mixin TypePluginT!(GTypeModule);
94 
95 
96 	/** */
97 	public static GType getType()
98 	{
99 		return g_type_module_get_type();
100 	}
101 
102 	/**
103 	 * Registers an additional interface for a type, whose interface lives
104 	 * in the given type plugin. If the interface was already registered
105 	 * for the type in this plugin, nothing will be done.
106 	 *
107 	 * As long as any instances of the type exist, the type plugin will
108 	 * not be unloaded.
109 	 *
110 	 * Since 2.56 if @module is %NULL this will call g_type_add_interface_static()
111 	 * instead. This can be used when making a static build of the module.
112 	 *
113 	 * Params:
114 	 *     instanceType = type to which to add the interface.
115 	 *     interfaceType = interface type to add
116 	 *     interfaceInfo = type information structure
117 	 */
118 	public void addInterface(GType instanceType, GType interfaceType, GInterfaceInfo* interfaceInfo)
119 	{
120 		g_type_module_add_interface(gTypeModule, instanceType, interfaceType, interfaceInfo);
121 	}
122 
123 	/**
124 	 * Looks up or registers an enumeration that is implemented with a particular
125 	 * type plugin. If a type with name @type_name was previously registered,
126 	 * the #GType identifier for the type is returned, otherwise the type
127 	 * is newly registered, and the resulting #GType identifier returned.
128 	 *
129 	 * As long as any instances of the type exist, the type plugin will
130 	 * not be unloaded.
131 	 *
132 	 * Since 2.56 if @module is %NULL this will call g_type_register_static()
133 	 * instead. This can be used when making a static build of the module.
134 	 *
135 	 * Params:
136 	 *     name = name for the type
137 	 *     constStaticValues = an array of #GEnumValue structs for the
138 	 *         possible enumeration values. The array is
139 	 *         terminated by a struct with all members being
140 	 *         0.
141 	 *
142 	 * Returns: the new or existing type ID
143 	 *
144 	 * Since: 2.6
145 	 */
146 	public GType registerEnum(string name, GEnumValue* constStaticValues)
147 	{
148 		return g_type_module_register_enum(gTypeModule, Str.toStringz(name), constStaticValues);
149 	}
150 
151 	/**
152 	 * Looks up or registers a flags type that is implemented with a particular
153 	 * type plugin. If a type with name @type_name was previously registered,
154 	 * the #GType identifier for the type is returned, otherwise the type
155 	 * is newly registered, and the resulting #GType identifier returned.
156 	 *
157 	 * As long as any instances of the type exist, the type plugin will
158 	 * not be unloaded.
159 	 *
160 	 * Since 2.56 if @module is %NULL this will call g_type_register_static()
161 	 * instead. This can be used when making a static build of the module.
162 	 *
163 	 * Params:
164 	 *     name = name for the type
165 	 *     constStaticValues = an array of #GFlagsValue structs for the
166 	 *         possible flags values. The array is
167 	 *         terminated by a struct with all members being
168 	 *         0.
169 	 *
170 	 * Returns: the new or existing type ID
171 	 *
172 	 * Since: 2.6
173 	 */
174 	public GType registerFlags(string name, GFlagsValue* constStaticValues)
175 	{
176 		return g_type_module_register_flags(gTypeModule, Str.toStringz(name), constStaticValues);
177 	}
178 
179 	/**
180 	 * Looks up or registers a type that is implemented with a particular
181 	 * type plugin. If a type with name @type_name was previously registered,
182 	 * the #GType identifier for the type is returned, otherwise the type
183 	 * is newly registered, and the resulting #GType identifier returned.
184 	 *
185 	 * When reregistering a type (typically because a module is unloaded
186 	 * then reloaded, and reinitialized), @module and @parent_type must
187 	 * be the same as they were previously.
188 	 *
189 	 * As long as any instances of the type exist, the type plugin will
190 	 * not be unloaded.
191 	 *
192 	 * Since 2.56 if @module is %NULL this will call g_type_register_static()
193 	 * instead. This can be used when making a static build of the module.
194 	 *
195 	 * Params:
196 	 *     parentType = the type for the parent class
197 	 *     typeName = name for the type
198 	 *     typeInfo = type information structure
199 	 *     flags = flags field providing details about the type
200 	 *
201 	 * Returns: the new or existing type ID
202 	 */
203 	public GType registerType(GType parentType, string typeName, GTypeInfo* typeInfo, GTypeFlags flags)
204 	{
205 		return g_type_module_register_type(gTypeModule, parentType, Str.toStringz(typeName), typeInfo, flags);
206 	}
207 
208 	/**
209 	 * Sets the name for a #GTypeModule
210 	 *
211 	 * Params:
212 	 *     name = a human-readable name to use in error messages.
213 	 */
214 	public void setName(string name)
215 	{
216 		g_type_module_set_name(gTypeModule, Str.toStringz(name));
217 	}
218 
219 	/**
220 	 * Decreases the use count of a #GTypeModule by one. If the
221 	 * result is zero, the module will be unloaded. (However, the
222 	 * #GTypeModule will not be freed, and types associated with the
223 	 * #GTypeModule are not unregistered. Once a #GTypeModule is
224 	 * initialized, it must exist forever.)
225 	 */
226 	public void unuse()
227 	{
228 		g_type_module_unuse(gTypeModule);
229 	}
230 
231 	/**
232 	 * Increases the use count of a #GTypeModule by one. If the
233 	 * use count was zero before, the plugin will be loaded.
234 	 * If loading the plugin fails, the use count is reset to
235 	 * its prior value.
236 	 *
237 	 * Returns: %FALSE if the plugin needed to be loaded and
238 	 *     loading the plugin failed.
239 	 */
240 	public bool use()
241 	{
242 		return g_type_module_use(gTypeModule) != 0;
243 	}
244 }