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 gtkc.gobject;
32 public  import gtkc.gobjecttypes;
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()
70 	{
71 		return gTypeModule;
72 	}
73 
74 	/** the main Gtk struct as a void* */
75 	protected override void* getStruct()
76 	{
77 		return cast(void*)gTypeModule;
78 	}
79 
80 	protected override void setStruct(GObject* obj)
81 	{
82 		gTypeModule = cast(GTypeModule*)obj;
83 		super.setStruct(obj);
84 	}
85 
86 	/**
87 	 * Sets our main struct and passes it to the parent class.
88 	 */
89 	public this (GTypeModule* gTypeModule, bool ownedRef = false)
90 	{
91 		this.gTypeModule = gTypeModule;
92 		super(cast(GObject*)gTypeModule, ownedRef);
93 	}
94 
95 	// add the TypePlugin capabilities
96 	mixin TypePluginT!(GTypeModule);
97 
98 	/**
99 	 */
100 
101 	public static GType getType()
102 	{
103 		return g_type_module_get_type();
104 	}
105 
106 	/**
107 	 * Registers an additional interface for a type, whose interface lives
108 	 * in the given type plugin. If the interface was already registered
109 	 * for the type in this plugin, nothing will be done.
110 	 *
111 	 * As long as any instances of the type exist, the type plugin will
112 	 * not be unloaded.
113 	 *
114 	 * Params:
115 	 *     instanceType = type to which to add the interface.
116 	 *     interfaceType = interface type to add
117 	 *     interfaceInfo = type information structure
118 	 */
119 	public void addInterface(GType instanceType, GType interfaceType, GInterfaceInfo* interfaceInfo)
120 	{
121 		g_type_module_add_interface(gTypeModule, instanceType, interfaceType, interfaceInfo);
122 	}
123 
124 	/**
125 	 * Looks up or registers an enumeration that is implemented with a particular
126 	 * type plugin. If a type with name @type_name was previously registered,
127 	 * the #GType identifier for the type is returned, otherwise the type
128 	 * is newly registered, and the resulting #GType identifier returned.
129 	 *
130 	 * As long as any instances of the type exist, the type plugin will
131 	 * not be unloaded.
132 	 *
133 	 * Params:
134 	 *     name = name for the type
135 	 *     constStaticValues = an array of #GEnumValue structs for the
136 	 *         possible enumeration values. The array is
137 	 *         terminated by a struct with all members being
138 	 *         0.
139 	 *
140 	 * Return: the new or existing type ID
141 	 *
142 	 * Since: 2.6
143 	 */
144 	public GType registerEnum(string name, GEnumValue* constStaticValues)
145 	{
146 		return g_type_module_register_enum(gTypeModule, Str.toStringz(name), constStaticValues);
147 	}
148 
149 	/**
150 	 * Looks up or registers a flags type that is implemented with a particular
151 	 * type plugin. If a type with name @type_name was previously registered,
152 	 * the #GType identifier for the type is returned, otherwise the type
153 	 * is newly registered, and the resulting #GType identifier returned.
154 	 *
155 	 * As long as any instances of the type exist, the type plugin will
156 	 * not be unloaded.
157 	 *
158 	 * Params:
159 	 *     name = name for the type
160 	 *     constStaticValues = an array of #GFlagsValue structs for the
161 	 *         possible flags values. The array is
162 	 *         terminated by a struct with all members being
163 	 *         0.
164 	 *
165 	 * Return: the new or existing type ID
166 	 *
167 	 * Since: 2.6
168 	 */
169 	public GType registerFlags(string name, GFlagsValue* constStaticValues)
170 	{
171 		return g_type_module_register_flags(gTypeModule, Str.toStringz(name), constStaticValues);
172 	}
173 
174 	/**
175 	 * Looks up or registers a type that is implemented with a particular
176 	 * type plugin. If a type with name @type_name was previously registered,
177 	 * the #GType identifier for the type is returned, otherwise the type
178 	 * is newly registered, and the resulting #GType identifier returned.
179 	 *
180 	 * When reregistering a type (typically because a module is unloaded
181 	 * then reloaded, and reinitialized), @module and @parent_type must
182 	 * be the same as they were previously.
183 	 *
184 	 * As long as any instances of the type exist, the type plugin will
185 	 * not be unloaded.
186 	 *
187 	 * Params:
188 	 *     parentType = the type for the parent class
189 	 *     typeName = name for the type
190 	 *     typeInfo = type information structure
191 	 *     flags = flags field providing details about the type
192 	 *
193 	 * Return: the new or existing type ID
194 	 */
195 	public GType registerType(GType parentType, string typeName, GTypeInfo* typeInfo, GTypeFlags flags)
196 	{
197 		return g_type_module_register_type(gTypeModule, parentType, Str.toStringz(typeName), typeInfo, flags);
198 	}
199 
200 	/**
201 	 * Sets the name for a #GTypeModule
202 	 *
203 	 * Params:
204 	 *     name = a human-readable name to use in error messages.
205 	 */
206 	public void setName(string name)
207 	{
208 		g_type_module_set_name(gTypeModule, Str.toStringz(name));
209 	}
210 
211 	/**
212 	 * Decreases the use count of a #GTypeModule by one. If the
213 	 * result is zero, the module will be unloaded. (However, the
214 	 * #GTypeModule will not be freed, and types associated with the
215 	 * #GTypeModule are not unregistered. Once a #GTypeModule is
216 	 * initialized, it must exist forever.)
217 	 */
218 	public void unuse()
219 	{
220 		g_type_module_unuse(gTypeModule);
221 	}
222 
223 	/**
224 	 * Increases the use count of a #GTypeModule by one. If the
225 	 * use count was zero before, the plugin will be loaded.
226 	 * If loading the plugin fails, the use count is reset to
227 	 * its prior value.
228 	 *
229 	 * Return: %FALSE if the plugin needed to be loaded and
230 	 *     loading the plugin failed.
231 	 */
232 	public bool use()
233 	{
234 		return g_type_module_use(gTypeModule) != 0;
235 	}
236 }