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