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