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